| 1 |
/*! |
| 2 |
* jsoneditor.js |
| 3 |
* |
| 4 |
* @brief |
| 5 |
* JSONEditor is a web-based tool to view, edit, format, and validate JSON. |
| 6 |
* It has various modes such as a tree editor, a code editor, and a plain text |
| 7 |
* editor. |
| 8 |
* |
| 9 |
* Supported browsers: Chrome, Firefox, Safari, Opera, Internet Explorer 8+ |
| 10 |
* |
| 11 |
* @license |
| 12 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 13 |
* use this file except in compliance with the License. You may obtain a copy |
| 14 |
* of the License at |
| 15 |
* |
| 16 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 17 |
* |
| 18 |
* Unless required by applicable law or agreed to in writing, software |
| 19 |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 20 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 21 |
* License for the specific language governing permissions and limitations under |
| 22 |
* the License. |
| 23 |
* |
| 24 |
* Copyright (c) 2011-2017 Jos de Jong, http://jsoneditoronline.org |
| 25 |
* |
| 26 |
* @author Jos de Jong, <[email protected]> |
| 27 |
* @version 5.5.11 |
| 28 |
* @date 2017-01-06 |
| 29 |
*/ |
| 30 |
(function webpackUniversalModuleDefinition(root, factory) { |
| 31 |
if(typeof exports === 'object' && typeof module === 'object') |
| 32 |
module.exports = factory(); |
| 33 |
else if(typeof define === 'function' && define.amd) |
| 34 |
define([], factory); |
| 35 |
else if(typeof exports === 'object') |
| 36 |
exports["JSONEditor"] = factory(); |
| 37 |
else |
| 38 |
root["JSONEditor"] = factory(); |
| 39 |
})(this, function() { |
| 40 |
return /******/ (function(modules) { // webpackBootstrap |
| 41 |
/******/ // The module cache |
| 42 |
/******/ var installedModules = {}; |
| 43 |
|
| 44 |
/******/ // The require function |
| 45 |
/******/ function __webpack_require__(moduleId) { |
| 46 |
|
| 47 |
/******/ // Check if module is in cache |
| 48 |
/******/ if(installedModules[moduleId]) |
| 49 |
/******/ return installedModules[moduleId].exports; |
| 50 |
|
| 51 |
/******/ // Create a new module (and put it into the cache) |
| 52 |
/******/ var module = installedModules[moduleId] = { |
| 53 |
/******/ exports: {}, |
| 54 |
/******/ id: moduleId, |
| 55 |
/******/ loaded: false |
| 56 |
/******/ }; |
| 57 |
|
| 58 |
/******/ // Execute the module function |
| 59 |
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 60 |
|
| 61 |
/******/ // Flag the module as loaded |
| 62 |
/******/ module.loaded = true; |
| 63 |
|
| 64 |
/******/ // Return the exports of the module |
| 65 |
/******/ return module.exports; |
| 66 |
/******/ } |
| 67 |
|
| 68 |
|
| 69 |
/******/ // expose the modules object (__webpack_modules__) |
| 70 |
/******/ __webpack_require__.m = modules; |
| 71 |
|
| 72 |
/******/ // expose the module cache |
| 73 |
/******/ __webpack_require__.c = installedModules; |
| 74 |
|
| 75 |
/******/ // __webpack_public_path__ |
| 76 |
/******/ __webpack_require__.p = ""; |
| 77 |
|
| 78 |
/******/ // Load entry module and return exports |
| 79 |
/******/ return __webpack_require__(0); |
| 80 |
/******/ }) |
| 81 |
/************************************************************************/ |
| 82 |
/******/ ([ |
| 83 |
/* 0 */ |
| 84 |
/***/ function(module, exports, __webpack_require__) { |
| 85 |
|
| 86 |
'use strict'; |
| 87 |
|
| 88 |
var Ajv; |
| 89 |
try { |
| 90 |
Ajv = __webpack_require__(1); |
| 91 |
} |
| 92 |
catch (err) { |
| 93 |
// no problem... when we need Ajv we will throw a neat exception |
| 94 |
} |
| 95 |
|
| 96 |
var treemode = __webpack_require__(51); |
| 97 |
var textmode = __webpack_require__(62); |
| 98 |
var util = __webpack_require__(54); |
| 99 |
|
| 100 |
/** |
| 101 |
* @constructor JSONEditor |
| 102 |
* @param {Element} container Container element |
| 103 |
* @param {Object} [options] Object with options. available options: |
| 104 |
* {String} mode Editor mode. Available values: |
| 105 |
* 'tree' (default), 'view', |
| 106 |
* 'form', 'text', and 'code'. |
| 107 |
* {function} onChange Callback method, triggered |
| 108 |
* on change of contents |
| 109 |
* {function} onError Callback method, triggered |
| 110 |
* when an error occurs |
| 111 |
* {Boolean} search Enable search box. |
| 112 |
* True by default |
| 113 |
* Only applicable for modes |
| 114 |
* 'tree', 'view', and 'form' |
| 115 |
* {Boolean} history Enable history (undo/redo). |
| 116 |
* True by default |
| 117 |
* Only applicable for modes |
| 118 |
* 'tree', 'view', and 'form' |
| 119 |
* {String} name Field name for the root node. |
| 120 |
* Only applicable for modes |
| 121 |
* 'tree', 'view', and 'form' |
| 122 |
* {Number} indentation Number of indentation |
| 123 |
* spaces. 4 by default. |
| 124 |
* Only applicable for |
| 125 |
* modes 'text' and 'code' |
| 126 |
* {boolean} escapeUnicode If true, unicode |
| 127 |
* characters are escaped. |
| 128 |
* false by default. |
| 129 |
* {boolean} sortObjectKeys If true, object keys are |
| 130 |
* sorted before display. |
| 131 |
* false by default. |
| 132 |
* @param {Object | undefined} json JSON object |
| 133 |
*/ |
| 134 |
function JSONEditor (container, options, json) { |
| 135 |
if (!(this instanceof JSONEditor)) { |
| 136 |
throw new Error('JSONEditor constructor called without "new".'); |
| 137 |
} |
| 138 |
|
| 139 |
// check for unsupported browser (IE8 and older) |
| 140 |
var ieVersion = util.getInternetExplorerVersion(); |
| 141 |
if (ieVersion != -1 && ieVersion < 9) { |
| 142 |
throw new Error('Unsupported browser, IE9 or newer required. ' + |
| 143 |
'Please install the newest version of your browser.'); |
| 144 |
} |
| 145 |
|
| 146 |
if (options) { |
| 147 |
// check for deprecated options |
| 148 |
if (options.error) { |
| 149 |
console.warn('Option "error" has been renamed to "onError"'); |
| 150 |
options.onError = options.error; |
| 151 |
delete options.error; |
| 152 |
} |
| 153 |
if (options.change) { |
| 154 |
console.warn('Option "change" has been renamed to "onChange"'); |
| 155 |
options.onChange = options.change; |
| 156 |
delete options.change; |
| 157 |
} |
| 158 |
if (options.editable) { |
| 159 |
console.warn('Option "editable" has been renamed to "onEditable"'); |
| 160 |
options.onEditable = options.editable; |
| 161 |
delete options.editable; |
| 162 |
} |
| 163 |
|
| 164 |
// validate options |
| 165 |
if (options) { |
| 166 |
var VALID_OPTIONS = [ |
| 167 |
'ace', 'theme', |
| 168 |
'ajv', 'schema', |
| 169 |
'onChange', 'onEditable', 'onError', 'onModeChange', |
| 170 |
'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation', 'sortObjectKeys' |
| 171 |
]; |
| 172 |
|
| 173 |
Object.keys(options).forEach(function (option) { |
| 174 |
if (VALID_OPTIONS.indexOf(option) === -1) { |
| 175 |
console.warn('Unknown option "' + option + '". This option will be ignored'); |
| 176 |
} |
| 177 |
}); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
if (arguments.length) { |
| 182 |
this._create(container, options, json); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
/** |
| 187 |
* Configuration for all registered modes. Example: |
| 188 |
* { |
| 189 |
* tree: { |
| 190 |
* mixin: TreeEditor, |
| 191 |
* data: 'json' |
| 192 |
* }, |
| 193 |
* text: { |
| 194 |
* mixin: TextEditor, |
| 195 |
* data: 'text' |
| 196 |
* } |
| 197 |
* } |
| 198 |
* |
| 199 |
* @type { Object.<String, {mixin: Object, data: String} > } |
| 200 |
*/ |
| 201 |
JSONEditor.modes = {}; |
| 202 |
|
| 203 |
// debounce interval for JSON schema vaidation in milliseconds |
| 204 |
JSONEditor.prototype.DEBOUNCE_INTERVAL = 150; |
| 205 |
|
| 206 |
/** |
| 207 |
* Create the JSONEditor |
| 208 |
* @param {Element} container Container element |
| 209 |
* @param {Object} [options] See description in constructor |
| 210 |
* @param {Object | undefined} json JSON object |
| 211 |
* @private |
| 212 |
*/ |
| 213 |
JSONEditor.prototype._create = function (container, options, json) { |
| 214 |
this.container = container; |
| 215 |
this.options = options || {}; |
| 216 |
this.json = json || {}; |
| 217 |
|
| 218 |
var mode = this.options.mode || 'tree'; |
| 219 |
this.setMode(mode); |
| 220 |
}; |
| 221 |
|
| 222 |
/** |
| 223 |
* Destroy the editor. Clean up DOM, event listeners, and web workers. |
| 224 |
*/ |
| 225 |
JSONEditor.prototype.destroy = function () {}; |
| 226 |
|
| 227 |
/** |
| 228 |
* Set JSON object in editor |
| 229 |
* @param {Object | undefined} json JSON data |
| 230 |
*/ |
| 231 |
JSONEditor.prototype.set = function (json) { |
| 232 |
this.json = json; |
| 233 |
}; |
| 234 |
|
| 235 |
/** |
| 236 |
* Get JSON from the editor |
| 237 |
* @returns {Object} json |
| 238 |
*/ |
| 239 |
JSONEditor.prototype.get = function () { |
| 240 |
return this.json; |
| 241 |
}; |
| 242 |
|
| 243 |
/** |
| 244 |
* Set string containing JSON for the editor |
| 245 |
* @param {String | undefined} jsonText |
| 246 |
*/ |
| 247 |
JSONEditor.prototype.setText = function (jsonText) { |
| 248 |
this.json = util.parse(jsonText); |
| 249 |
}; |
| 250 |
|
| 251 |
/** |
| 252 |
* Get stringified JSON contents from the editor |
| 253 |
* @returns {String} jsonText |
| 254 |
*/ |
| 255 |
JSONEditor.prototype.getText = function () { |
| 256 |
return JSON.stringify(this.json); |
| 257 |
}; |
| 258 |
|
| 259 |
/** |
| 260 |
* Set a field name for the root node. |
| 261 |
* @param {String | undefined} name |
| 262 |
*/ |
| 263 |
JSONEditor.prototype.setName = function (name) { |
| 264 |
if (!this.options) { |
| 265 |
this.options = {}; |
| 266 |
} |
| 267 |
this.options.name = name; |
| 268 |
}; |
| 269 |
|
| 270 |
/** |
| 271 |
* Get the field name for the root node. |
| 272 |
* @return {String | undefined} name |
| 273 |
*/ |
| 274 |
JSONEditor.prototype.getName = function () { |
| 275 |
return this.options && this.options.name; |
| 276 |
}; |
| 277 |
|
| 278 |
/** |
| 279 |
* Change the mode of the editor. |
| 280 |
* JSONEditor will be extended with all methods needed for the chosen mode. |
| 281 |
* @param {String} mode Available modes: 'tree' (default), 'view', 'form', |
| 282 |
* 'text', and 'code'. |
| 283 |
*/ |
| 284 |
JSONEditor.prototype.setMode = function (mode) { |
| 285 |
var container = this.container; |
| 286 |
var options = util.extend({}, this.options); |
| 287 |
var oldMode = options.mode; |
| 288 |
var data; |
| 289 |
var name; |
| 290 |
|
| 291 |
options.mode = mode; |
| 292 |
var config = JSONEditor.modes[mode]; |
| 293 |
if (config) { |
| 294 |
try { |
| 295 |
var asText = (config.data == 'text'); |
| 296 |
name = this.getName(); |
| 297 |
data = this[asText ? 'getText' : 'get'](); // get text or json |
| 298 |
|
| 299 |
this.destroy(); |
| 300 |
util.clear(this); |
| 301 |
util.extend(this, config.mixin); |
| 302 |
this.create(container, options); |
| 303 |
|
| 304 |
this.setName(name); |
| 305 |
this[asText ? 'setText' : 'set'](data); // set text or json |
| 306 |
|
| 307 |
if (typeof config.load === 'function') { |
| 308 |
try { |
| 309 |
config.load.call(this); |
| 310 |
} |
| 311 |
catch (err) { |
| 312 |
console.error(err); |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
if (typeof options.onModeChange === 'function' && mode !== oldMode) { |
| 317 |
try { |
| 318 |
options.onModeChange(mode, oldMode); |
| 319 |
} |
| 320 |
catch (err) { |
| 321 |
console.error(err); |
| 322 |
} |
| 323 |
} |
| 324 |
} |
| 325 |
catch (err) { |
| 326 |
this._onError(err); |
| 327 |
} |
| 328 |
} |
| 329 |
else { |
| 330 |
throw new Error('Unknown mode "' + options.mode + '"'); |
| 331 |
} |
| 332 |
}; |
| 333 |
|
| 334 |
/** |
| 335 |
* Get the current mode |
| 336 |
* @return {string} |
| 337 |
*/ |
| 338 |
JSONEditor.prototype.getMode = function () { |
| 339 |
return this.options.mode; |
| 340 |
}; |
| 341 |
|
| 342 |
/** |
| 343 |
* Throw an error. If an error callback is configured in options.error, this |
| 344 |
* callback will be invoked. Else, a regular error is thrown. |
| 345 |
* @param {Error} err |
| 346 |
* @private |
| 347 |
*/ |
| 348 |
JSONEditor.prototype._onError = function(err) { |
| 349 |
if (this.options && typeof this.options.onError === 'function') { |
| 350 |
this.options.onError(err); |
| 351 |
} |
| 352 |
else { |
| 353 |
throw err; |
| 354 |
} |
| 355 |
}; |
| 356 |
|
| 357 |
/** |
| 358 |
* Set a JSON schema for validation of the JSON object. |
| 359 |
* To remove the schema, call JSONEditor.setSchema(null) |
| 360 |
* @param {Object | null} schema |
| 361 |
*/ |
| 362 |
JSONEditor.prototype.setSchema = function (schema) { |
| 363 |
// compile a JSON schema validator if a JSON schema is provided |
| 364 |
if (schema) { |
| 365 |
var ajv; |
| 366 |
try { |
| 367 |
// grab ajv from options if provided, else create a new instance |
| 368 |
ajv = this.options.ajv || Ajv({ allErrors: true, verbose: true }); |
| 369 |
|
| 370 |
} |
| 371 |
catch (err) { |
| 372 |
console.warn('Failed to create an instance of Ajv, JSON Schema validation is not available. Please use a JSONEditor bundle including Ajv, or pass an instance of Ajv as via the configuration option `ajv`.'); |
| 373 |
} |
| 374 |
|
| 375 |
if (ajv) { |
| 376 |
this.validateSchema = ajv.compile(schema); |
| 377 |
|
| 378 |
// add schema to the options, so that when switching to an other mode, |
| 379 |
// the set schema is not lost |
| 380 |
this.options.schema = schema; |
| 381 |
|
| 382 |
// validate now |
| 383 |
this.validate(); |
| 384 |
} |
| 385 |
|
| 386 |
this.refresh(); // update DOM |
| 387 |
} |
| 388 |
else { |
| 389 |
// remove current schema |
| 390 |
this.validateSchema = null; |
| 391 |
this.options.schema = null; |
| 392 |
this.validate(); // to clear current error messages |
| 393 |
this.refresh(); // update DOM |
| 394 |
} |
| 395 |
}; |
| 396 |
|
| 397 |
/** |
| 398 |
* Validate current JSON object against the configured JSON schema |
| 399 |
* Throws an exception when no JSON schema is configured |
| 400 |
*/ |
| 401 |
JSONEditor.prototype.validate = function () { |
| 402 |
// must be implemented by treemode and textmode |
| 403 |
}; |
| 404 |
|
| 405 |
/** |
| 406 |
* Refresh the rendered contents |
| 407 |
*/ |
| 408 |
JSONEditor.prototype.refresh = function () { |
| 409 |
// can be implemented by treemode and textmode |
| 410 |
}; |
| 411 |
|
| 412 |
/** |
| 413 |
* Register a plugin with one ore multiple modes for the JSON Editor. |
| 414 |
* |
| 415 |
* A mode is described as an object with properties: |
| 416 |
* |
| 417 |
* - `mode: String` The name of the mode. |
| 418 |
* - `mixin: Object` An object containing the mixin functions which |
| 419 |
* will be added to the JSONEditor. Must contain functions |
| 420 |
* create, get, getText, set, and setText. May have |
| 421 |
* additional functions. |
| 422 |
* When the JSONEditor switches to a mixin, all mixin |
| 423 |
* functions are added to the JSONEditor, and then |
| 424 |
* the function `create(container, options)` is executed. |
| 425 |
* - `data: 'text' | 'json'` The type of data that will be used to load the mixin. |
| 426 |
* - `[load: function]` An optional function called after the mixin |
| 427 |
* has been loaded. |
| 428 |
* |
| 429 |
* @param {Object | Array} mode A mode object or an array with multiple mode objects. |
| 430 |
*/ |
| 431 |
JSONEditor.registerMode = function (mode) { |
| 432 |
var i, prop; |
| 433 |
|
| 434 |
if (util.isArray(mode)) { |
| 435 |
// multiple modes |
| 436 |
for (i = 0; i < mode.length; i++) { |
| 437 |
JSONEditor.registerMode(mode[i]); |
| 438 |
} |
| 439 |
} |
| 440 |
else { |
| 441 |
// validate the new mode |
| 442 |
if (!('mode' in mode)) throw new Error('Property "mode" missing'); |
| 443 |
if (!('mixin' in mode)) throw new Error('Property "mixin" missing'); |
| 444 |
if (!('data' in mode)) throw new Error('Property "data" missing'); |
| 445 |
var name = mode.mode; |
| 446 |
if (name in JSONEditor.modes) { |
| 447 |
throw new Error('Mode "' + name + '" already registered'); |
| 448 |
} |
| 449 |
|
| 450 |
// validate the mixin |
| 451 |
if (typeof mode.mixin.create !== 'function') { |
| 452 |
throw new Error('Required function "create" missing on mixin'); |
| 453 |
} |
| 454 |
var reserved = ['setMode', 'registerMode', 'modes']; |
| 455 |
for (i = 0; i < reserved.length; i++) { |
| 456 |
prop = reserved[i]; |
| 457 |
if (prop in mode.mixin) { |
| 458 |
throw new Error('Reserved property "' + prop + '" not allowed in mixin'); |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
JSONEditor.modes[name] = mode; |
| 463 |
} |
| 464 |
}; |
| 465 |
|
| 466 |
// register tree and text modes |
| 467 |
JSONEditor.registerMode(treemode); |
| 468 |
JSONEditor.registerMode(textmode); |
| 469 |
|
| 470 |
module.exports = JSONEditor; |
| 471 |
|
| 472 |
|
| 473 |
/***/ }, |
| 474 |
/* 1 */ |
| 475 |
/***/ function(module, exports, __webpack_require__) { |
| 476 |
|
| 477 |
'use strict'; |
| 478 |
|
| 479 |
var compileSchema = __webpack_require__(2) |
| 480 |
, resolve = __webpack_require__(3) |
| 481 |
, Cache = __webpack_require__(21) |
| 482 |
, SchemaObject = __webpack_require__(16) |
| 483 |
, stableStringify = __webpack_require__(12) |
| 484 |
, formats = __webpack_require__(22) |
| 485 |
, rules = __webpack_require__(23) |
| 486 |
, v5 = __webpack_require__(43) |
| 487 |
, util = __webpack_require__(11) |
| 488 |
, async = __webpack_require__(17) |
| 489 |
, co = __webpack_require__(19); |
| 490 |
|
| 491 |
module.exports = Ajv; |
| 492 |
|
| 493 |
Ajv.prototype.compileAsync = async.compile; |
| 494 |
Ajv.prototype.addKeyword = __webpack_require__(49); |
| 495 |
Ajv.ValidationError = __webpack_require__(20); |
| 496 |
|
| 497 |
var META_SCHEMA_ID = 'http://json-schema.org/draft-04/schema'; |
| 498 |
var SCHEMA_URI_FORMAT = /^(?:(?:[a-z][a-z0-9+-.]*:)?\/\/)?[^\s]*$/i; |
| 499 |
function SCHEMA_URI_FORMAT_FUNC(str) { |
| 500 |
return SCHEMA_URI_FORMAT.test(str); |
| 501 |
} |
| 502 |
|
| 503 |
var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes' ]; |
| 504 |
|
| 505 |
/** |
| 506 |
* Creates validator instance. |
| 507 |
* Usage: `Ajv(opts)` |
| 508 |
* @param {Object} opts optional options |
| 509 |
* @return {Object} ajv instance |
| 510 |
*/ |
| 511 |
function Ajv(opts) { |
| 512 |
if (!(this instanceof Ajv)) return new Ajv(opts); |
| 513 |
var self = this; |
| 514 |
|
| 515 |
opts = this._opts = util.copy(opts) || {}; |
| 516 |
this._schemas = {}; |
| 517 |
this._refs = {}; |
| 518 |
this._formats = formats(opts.format); |
| 519 |
this._cache = opts.cache || new Cache; |
| 520 |
this._loadingSchemas = {}; |
| 521 |
this.RULES = rules(); |
| 522 |
|
| 523 |
// this is done on purpose, so that methods are bound to the instance |
| 524 |
// (without using bind) so that they can be used without the instance |
| 525 |
this.validate = validate; |
| 526 |
this.compile = compile; |
| 527 |
this.addSchema = addSchema; |
| 528 |
this.addMetaSchema = addMetaSchema; |
| 529 |
this.validateSchema = validateSchema; |
| 530 |
this.getSchema = getSchema; |
| 531 |
this.removeSchema = removeSchema; |
| 532 |
this.addFormat = addFormat; |
| 533 |
this.errorsText = errorsText; |
| 534 |
|
| 535 |
this._addSchema = _addSchema; |
| 536 |
this._compile = _compile; |
| 537 |
|
| 538 |
opts.loopRequired = opts.loopRequired || Infinity; |
| 539 |
if (opts.async || opts.transpile) async.setup(opts); |
| 540 |
if (opts.beautify === true) opts.beautify = { indent_size: 2 }; |
| 541 |
if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true; |
| 542 |
this._metaOpts = getMetaSchemaOptions(); |
| 543 |
|
| 544 |
addInitialSchemas(); |
| 545 |
if (opts.formats) addInitialFormats(); |
| 546 |
if (opts.v5) v5.enable(this); |
| 547 |
if (typeof opts.meta == 'object') addMetaSchema(opts.meta); |
| 548 |
|
| 549 |
|
| 550 |
/** |
| 551 |
* Validate data using schema |
| 552 |
* Schema will be compiled and cached (using serialized JSON as key. [json-stable-stringify](https://github.com/substack/json-stable-stringify) is used to serialize. |
| 553 |
* @param {String|Object} schemaKeyRef key, ref or schema object |
| 554 |
* @param {Any} data to be validated |
| 555 |
* @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`). |
| 556 |
*/ |
| 557 |
function validate(schemaKeyRef, data) { |
| 558 |
var v; |
| 559 |
if (typeof schemaKeyRef == 'string') { |
| 560 |
v = getSchema(schemaKeyRef); |
| 561 |
if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"'); |
| 562 |
} else { |
| 563 |
var schemaObj = _addSchema(schemaKeyRef); |
| 564 |
v = schemaObj.validate || _compile(schemaObj); |
| 565 |
} |
| 566 |
|
| 567 |
var valid = v(data); |
| 568 |
if (v.async) return self._opts.async == '*' ? co(valid) : valid; |
| 569 |
self.errors = v.errors; |
| 570 |
return valid; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
/** |
| 575 |
* Create validating function for passed schema. |
| 576 |
* @param {Object} schema schema object |
| 577 |
* @return {Function} validating function |
| 578 |
*/ |
| 579 |
function compile(schema) { |
| 580 |
var schemaObj = _addSchema(schema); |
| 581 |
return schemaObj.validate || _compile(schemaObj); |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
/** |
| 586 |
* Adds schema to the instance. |
| 587 |
* @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored. |
| 588 |
* @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`. |
| 589 |
* @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead. |
| 590 |
* @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead. |
| 591 |
*/ |
| 592 |
function addSchema(schema, key, _skipValidation, _meta) { |
| 593 |
if (Array.isArray(schema)){ |
| 594 |
for (var i=0; i<schema.length; i++) addSchema(schema[i], undefined, _skipValidation, _meta); |
| 595 |
return; |
| 596 |
} |
| 597 |
// can key/id have # inside? |
| 598 |
key = resolve.normalizeId(key || schema.id); |
| 599 |
checkUnique(key); |
| 600 |
var schemaObj = self._schemas[key] = _addSchema(schema, _skipValidation, true); |
| 601 |
schemaObj.meta = _meta; |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
/** |
| 606 |
* Add schema that will be used to validate other schemas |
| 607 |
* options in META_IGNORE_OPTIONS are alway set to false |
| 608 |
* @param {Object} schema schema object |
| 609 |
* @param {String} key optional schema key |
| 610 |
* @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema |
| 611 |
*/ |
| 612 |
function addMetaSchema(schema, key, skipValidation) { |
| 613 |
addSchema(schema, key, skipValidation, true); |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
/** |
| 618 |
* Validate schema |
| 619 |
* @param {Object} schema schema to validate |
| 620 |
* @param {Boolean} throwOrLogError pass true to throw (or log) an error if invalid |
| 621 |
* @return {Boolean} true if schema is valid |
| 622 |
*/ |
| 623 |
function validateSchema(schema, throwOrLogError) { |
| 624 |
var $schema = schema.$schema || self._opts.defaultMeta || defaultMeta(); |
| 625 |
var currentUriFormat = self._formats.uri; |
| 626 |
self._formats.uri = typeof currentUriFormat == 'function' |
| 627 |
? SCHEMA_URI_FORMAT_FUNC |
| 628 |
: SCHEMA_URI_FORMAT; |
| 629 |
var valid = validate($schema, schema); |
| 630 |
self._formats.uri = currentUriFormat; |
| 631 |
if (!valid && throwOrLogError) { |
| 632 |
var message = 'schema is invalid:' + errorsText(); |
| 633 |
if (self._opts.validateSchema == 'log') console.error(message); |
| 634 |
else throw new Error(message); |
| 635 |
} |
| 636 |
return valid; |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
function defaultMeta() { |
| 641 |
var meta = self._opts.meta; |
| 642 |
self._opts.defaultMeta = typeof meta == 'object' |
| 643 |
? meta.id || meta |
| 644 |
: self._opts.v5 |
| 645 |
? v5.META_SCHEMA_ID |
| 646 |
: META_SCHEMA_ID; |
| 647 |
return self._opts.defaultMeta; |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
/** |
| 652 |
* Get compiled schema from the instance by `key` or `ref`. |
| 653 |
* @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id). |
| 654 |
* @return {Function} schema validating function (with property `schema`). |
| 655 |
*/ |
| 656 |
function getSchema(keyRef) { |
| 657 |
var schemaObj = _getSchemaObj(keyRef); |
| 658 |
switch (typeof schemaObj) { |
| 659 |
case 'object': return schemaObj.validate || _compile(schemaObj); |
| 660 |
case 'string': return getSchema(schemaObj); |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
function _getSchemaObj(keyRef) { |
| 666 |
keyRef = resolve.normalizeId(keyRef); |
| 667 |
return self._schemas[keyRef] || self._refs[keyRef]; |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
/** |
| 672 |
* Remove cached schema(s). |
| 673 |
* If no parameter is passed all schemas but meta-schemas are removed. |
| 674 |
* If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed. |
| 675 |
* Even if schema is referenced by other schemas it still can be removed as other schemas have local references. |
| 676 |
* @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object |
| 677 |
*/ |
| 678 |
function removeSchema(schemaKeyRef) { |
| 679 |
switch (typeof schemaKeyRef) { |
| 680 |
case 'undefined': |
| 681 |
_removeAllSchemas(self._schemas); |
| 682 |
_removeAllSchemas(self._refs); |
| 683 |
self._cache.clear(); |
| 684 |
return; |
| 685 |
case 'string': |
| 686 |
var schemaObj = _getSchemaObj(schemaKeyRef); |
| 687 |
if (schemaObj) self._cache.del(schemaObj.jsonStr); |
| 688 |
delete self._schemas[schemaKeyRef]; |
| 689 |
delete self._refs[schemaKeyRef]; |
| 690 |
return; |
| 691 |
case 'object': |
| 692 |
if (schemaKeyRef instanceof RegExp) { |
| 693 |
_removeAllSchemas(self._schemas, schemaKeyRef); |
| 694 |
_removeAllSchemas(self._refs, schemaKeyRef); |
| 695 |
return; |
| 696 |
} |
| 697 |
var jsonStr = stableStringify(schemaKeyRef); |
| 698 |
self._cache.del(jsonStr); |
| 699 |
var id = schemaKeyRef.id; |
| 700 |
if (id) { |
| 701 |
id = resolve.normalizeId(id); |
| 702 |
delete self._schemas[id]; |
| 703 |
delete self._refs[id]; |
| 704 |
} |
| 705 |
} |
| 706 |
|
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
function _removeAllSchemas(schemas, regex) { |
| 711 |
for (var keyRef in schemas) { |
| 712 |
var schemaObj = schemas[keyRef]; |
| 713 |
if (!schemaObj.meta && (!regex || regex.test(keyRef))) { |
| 714 |
self._cache.del(schemaObj.jsonStr); |
| 715 |
delete schemas[keyRef]; |
| 716 |
} |
| 717 |
} |
| 718 |
} |
| 719 |
|
| 720 |
|
| 721 |
function _addSchema(schema, skipValidation, shouldAddSchema) { |
| 722 |
if (typeof schema != 'object') throw new Error('schema should be object'); |
| 723 |
var jsonStr = stableStringify(schema); |
| 724 |
var cached = self._cache.get(jsonStr); |
| 725 |
if (cached) return cached; |
| 726 |
|
| 727 |
shouldAddSchema = shouldAddSchema || self._opts.addUsedSchema !== false; |
| 728 |
|
| 729 |
var id = resolve.normalizeId(schema.id); |
| 730 |
if (id && shouldAddSchema) checkUnique(id); |
| 731 |
|
| 732 |
if (self._opts.validateSchema !== false && !skipValidation) |
| 733 |
validateSchema(schema, true); |
| 734 |
|
| 735 |
var localRefs = resolve.ids.call(self, schema); |
| 736 |
|
| 737 |
var schemaObj = new SchemaObject({ |
| 738 |
id: id, |
| 739 |
schema: schema, |
| 740 |
localRefs: localRefs, |
| 741 |
jsonStr: jsonStr |
| 742 |
}); |
| 743 |
|
| 744 |
if (id[0] != '#' && shouldAddSchema) self._refs[id] = schemaObj; |
| 745 |
self._cache.put(jsonStr, schemaObj); |
| 746 |
|
| 747 |
return schemaObj; |
| 748 |
} |
| 749 |
|
| 750 |
|
| 751 |
function _compile(schemaObj, root) { |
| 752 |
if (schemaObj.compiling) { |
| 753 |
schemaObj.validate = callValidate; |
| 754 |
callValidate.schema = schemaObj.schema; |
| 755 |
callValidate.errors = null; |
| 756 |
callValidate.root = root ? root : callValidate; |
| 757 |
if (schemaObj.schema.$async === true) |
| 758 |
callValidate.async = true; |
| 759 |
return callValidate; |
| 760 |
} |
| 761 |
schemaObj.compiling = true; |
| 762 |
|
| 763 |
var currentOpts; |
| 764 |
if (schemaObj.meta) { |
| 765 |
currentOpts = self._opts; |
| 766 |
self._opts = self._metaOpts; |
| 767 |
} |
| 768 |
|
| 769 |
var v; |
| 770 |
try { v = compileSchema.call(self, schemaObj.schema, root, schemaObj.localRefs); } |
| 771 |
finally { |
| 772 |
schemaObj.compiling = false; |
| 773 |
if (schemaObj.meta) self._opts = currentOpts; |
| 774 |
} |
| 775 |
|
| 776 |
schemaObj.validate = v; |
| 777 |
schemaObj.refs = v.refs; |
| 778 |
schemaObj.refVal = v.refVal; |
| 779 |
schemaObj.root = v.root; |
| 780 |
return v; |
| 781 |
|
| 782 |
|
| 783 |
function callValidate() { |
| 784 |
var _validate = schemaObj.validate; |
| 785 |
var result = _validate.apply(null, arguments); |
| 786 |
callValidate.errors = _validate.errors; |
| 787 |
return result; |
| 788 |
} |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
/** |
| 793 |
* Convert array of error message objects to string |
| 794 |
* @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used. |
| 795 |
* @param {Object} options optional options with properties `separator` and `dataVar`. |
| 796 |
* @return {String} human readable string with all errors descriptions |
| 797 |
*/ |
| 798 |
function errorsText(errors, options) { |
| 799 |
errors = errors || self.errors; |
| 800 |
if (!errors) return 'No errors'; |
| 801 |
options = options || {}; |
| 802 |
var separator = options.separator === undefined ? ', ' : options.separator; |
| 803 |
var dataVar = options.dataVar === undefined ? 'data' : options.dataVar; |
| 804 |
|
| 805 |
var text = ''; |
| 806 |
for (var i=0; i<errors.length; i++) { |
| 807 |
var e = errors[i]; |
| 808 |
if (e) text += dataVar + e.dataPath + ' ' + e.message + separator; |
| 809 |
} |
| 810 |
return text.slice(0, -separator.length); |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
/** |
| 815 |
* Add custom format |
| 816 |
* @param {String} name format name |
| 817 |
* @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid) |
| 818 |
*/ |
| 819 |
function addFormat(name, format) { |
| 820 |
if (typeof format == 'string') format = new RegExp(format); |
| 821 |
self._formats[name] = format; |
| 822 |
} |
| 823 |
|
| 824 |
|
| 825 |
function addInitialSchemas() { |
| 826 |
if (self._opts.meta !== false) { |
| 827 |
var metaSchema = __webpack_require__(50); |
| 828 |
addMetaSchema(metaSchema, META_SCHEMA_ID, true); |
| 829 |
self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID; |
| 830 |
} |
| 831 |
|
| 832 |
var optsSchemas = self._opts.schemas; |
| 833 |
if (!optsSchemas) return; |
| 834 |
if (Array.isArray(optsSchemas)) addSchema(optsSchemas); |
| 835 |
else for (var key in optsSchemas) addSchema(optsSchemas[key], key); |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
function addInitialFormats() { |
| 840 |
for (var name in self._opts.formats) { |
| 841 |
var format = self._opts.formats[name]; |
| 842 |
addFormat(name, format); |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
function checkUnique(id) { |
| 848 |
if (self._schemas[id] || self._refs[id]) |
| 849 |
throw new Error('schema with key or id "' + id + '" already exists'); |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
function getMetaSchemaOptions() { |
| 854 |
var metaOpts = util.copy(self._opts); |
| 855 |
for (var i=0; i<META_IGNORE_OPTIONS.length; i++) |
| 856 |
delete metaOpts[META_IGNORE_OPTIONS[i]]; |
| 857 |
return metaOpts; |
| 858 |
} |
| 859 |
} |
| 860 |
|
| 861 |
|
| 862 |
/***/ }, |
| 863 |
/* 2 */ |
| 864 |
/***/ function(module, exports, __webpack_require__) { |
| 865 |
|
| 866 |
'use strict'; |
| 867 |
|
| 868 |
var resolve = __webpack_require__(3) |
| 869 |
, util = __webpack_require__(11) |
| 870 |
, stableStringify = __webpack_require__(12) |
| 871 |
, async = __webpack_require__(17); |
| 872 |
|
| 873 |
var beautify = (function() { try { return __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"js-beautify\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())).js_beautify; } catch(e) {/*empty*/} })(); |
| 874 |
|
| 875 |
var validateGenerator = __webpack_require__(18); |
| 876 |
|
| 877 |
module.exports = compile; |
| 878 |
|
| 879 |
|
| 880 |
/** |
| 881 |
* Compiles schema to validation function |
| 882 |
* @this Ajv |
| 883 |
* @param {Object} schema schema object |
| 884 |
* @param {Object} root object with information about the root schema for this schema |
| 885 |
* @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution |
| 886 |
* @param {String} baseId base ID for IDs in the schema |
| 887 |
* @return {Function} validation function |
| 888 |
*/ |
| 889 |
function compile(schema, root, localRefs, baseId) { |
| 890 |
/* jshint validthis: true, evil: true */ |
| 891 |
/* eslint no-shadow: 0 */ |
| 892 |
var self = this |
| 893 |
, opts = this._opts |
| 894 |
, refVal = [ undefined ] |
| 895 |
, refs = {} |
| 896 |
, patterns = [] |
| 897 |
, patternsHash = {} |
| 898 |
, defaults = [] |
| 899 |
, defaultsHash = {} |
| 900 |
, customRules = []; |
| 901 |
|
| 902 |
root = root || { schema: schema, refVal: refVal, refs: refs }; |
| 903 |
|
| 904 |
var formats = this._formats; |
| 905 |
var RULES = this.RULES; |
| 906 |
|
| 907 |
return localCompile(schema, root, localRefs, baseId); |
| 908 |
|
| 909 |
|
| 910 |
function localCompile(_schema, _root, localRefs, baseId) { |
| 911 |
var isRoot = !_root || (_root && _root.schema == _schema); |
| 912 |
if (_root.schema != root.schema) |
| 913 |
return compile.call(self, _schema, _root, localRefs, baseId); |
| 914 |
|
| 915 |
var $async = _schema.$async === true; |
| 916 |
if ($async && !opts.transpile) async.setup(opts); |
| 917 |
|
| 918 |
var sourceCode = validateGenerator({ |
| 919 |
isTop: true, |
| 920 |
schema: _schema, |
| 921 |
isRoot: isRoot, |
| 922 |
baseId: baseId, |
| 923 |
root: _root, |
| 924 |
schemaPath: '', |
| 925 |
errSchemaPath: '#', |
| 926 |
errorPath: '""', |
| 927 |
RULES: RULES, |
| 928 |
validate: validateGenerator, |
| 929 |
util: util, |
| 930 |
resolve: resolve, |
| 931 |
resolveRef: resolveRef, |
| 932 |
usePattern: usePattern, |
| 933 |
useDefault: useDefault, |
| 934 |
useCustomRule: useCustomRule, |
| 935 |
opts: opts, |
| 936 |
formats: formats, |
| 937 |
self: self |
| 938 |
}); |
| 939 |
|
| 940 |
sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode) |
| 941 |
+ vars(defaults, defaultCode) + vars(customRules, customRuleCode) |
| 942 |
+ sourceCode; |
| 943 |
|
| 944 |
if (opts.beautify) { |
| 945 |
/* istanbul ignore else */ |
| 946 |
if (beautify) sourceCode = beautify(sourceCode, opts.beautify); |
| 947 |
else console.error('"npm install js-beautify" to use beautify option'); |
| 948 |
} |
| 949 |
// console.log('\n\n\n *** \n', sourceCode); |
| 950 |
var validate, validateCode |
| 951 |
, transpile = opts._transpileFunc; |
| 952 |
try { |
| 953 |
validateCode = $async && transpile |
| 954 |
? transpile(sourceCode) |
| 955 |
: sourceCode; |
| 956 |
eval(validateCode); |
| 957 |
refVal[0] = validate; |
| 958 |
} catch(e) { |
| 959 |
console.error('Error compiling schema, function code:', validateCode); |
| 960 |
throw e; |
| 961 |
} |
| 962 |
|
| 963 |
validate.schema = _schema; |
| 964 |
validate.errors = null; |
| 965 |
validate.refs = refs; |
| 966 |
validate.refVal = refVal; |
| 967 |
validate.root = isRoot ? validate : _root; |
| 968 |
if ($async) validate.async = true; |
| 969 |
validate.sourceCode = sourceCode; |
| 970 |
|
| 971 |
return validate; |
| 972 |
} |
| 973 |
|
| 974 |
function resolveRef(baseId, ref, isRoot) { |
| 975 |
ref = resolve.url(baseId, ref); |
| 976 |
var refIndex = refs[ref]; |
| 977 |
var _refVal, refCode; |
| 978 |
if (refIndex !== undefined) { |
| 979 |
_refVal = refVal[refIndex]; |
| 980 |
refCode = 'refVal[' + refIndex + ']'; |
| 981 |
return resolvedRef(_refVal, refCode); |
| 982 |
} |
| 983 |
if (!isRoot) { |
| 984 |
var rootRefId = root.refs[ref]; |
| 985 |
if (rootRefId !== undefined) { |
| 986 |
_refVal = root.refVal[rootRefId]; |
| 987 |
refCode = addLocalRef(ref, _refVal); |
| 988 |
return resolvedRef(_refVal, refCode); |
| 989 |
} |
| 990 |
} |
| 991 |
|
| 992 |
refCode = addLocalRef(ref); |
| 993 |
var v = resolve.call(self, localCompile, root, ref); |
| 994 |
if (!v) { |
| 995 |
var localSchema = localRefs && localRefs[ref]; |
| 996 |
if (localSchema) { |
| 997 |
v = resolve.inlineRef(localSchema, opts.inlineRefs) |
| 998 |
? localSchema |
| 999 |
: compile.call(self, localSchema, root, localRefs, baseId); |
| 1000 |
} |
| 1001 |
} |
| 1002 |
|
| 1003 |
if (v) { |
| 1004 |
replaceLocalRef(ref, v); |
| 1005 |
return resolvedRef(v, refCode); |
| 1006 |
} |
| 1007 |
} |
| 1008 |
|
| 1009 |
function addLocalRef(ref, v) { |
| 1010 |
var refId = refVal.length; |
| 1011 |
refVal[refId] = v; |
| 1012 |
refs[ref] = refId; |
| 1013 |
return 'refVal' + refId; |
| 1014 |
} |
| 1015 |
|
| 1016 |
function replaceLocalRef(ref, v) { |
| 1017 |
var refId = refs[ref]; |
| 1018 |
refVal[refId] = v; |
| 1019 |
} |
| 1020 |
|
| 1021 |
function resolvedRef(refVal, code) { |
| 1022 |
return typeof refVal == 'object' |
| 1023 |
? { code: code, schema: refVal, inline: true } |
| 1024 |
: { code: code, async: refVal && refVal.async }; |
| 1025 |
} |
| 1026 |
|
| 1027 |
function usePattern(regexStr) { |
| 1028 |
var index = patternsHash[regexStr]; |
| 1029 |
if (index === undefined) { |
| 1030 |
index = patternsHash[regexStr] = patterns.length; |
| 1031 |
patterns[index] = regexStr; |
| 1032 |
} |
| 1033 |
return 'pattern' + index; |
| 1034 |
} |
| 1035 |
|
| 1036 |
function useDefault(value) { |
| 1037 |
switch (typeof value) { |
| 1038 |
case 'boolean': |
| 1039 |
case 'number': |
| 1040 |
return '' + value; |
| 1041 |
case 'string': |
| 1042 |
return util.toQuotedString(value); |
| 1043 |
case 'object': |
| 1044 |
if (value === null) return 'null'; |
| 1045 |
var valueStr = stableStringify(value); |
| 1046 |
var index = defaultsHash[valueStr]; |
| 1047 |
if (index === undefined) { |
| 1048 |
index = defaultsHash[valueStr] = defaults.length; |
| 1049 |
defaults[index] = value; |
| 1050 |
} |
| 1051 |
return 'default' + index; |
| 1052 |
} |
| 1053 |
} |
| 1054 |
|
| 1055 |
function useCustomRule(rule, schema, parentSchema, it) { |
| 1056 |
var compile = rule.definition.compile |
| 1057 |
, inline = rule.definition.inline |
| 1058 |
, macro = rule.definition.macro; |
| 1059 |
|
| 1060 |
var validate; |
| 1061 |
if (compile) { |
| 1062 |
validate = compile.call(self, schema, parentSchema); |
| 1063 |
} else if (macro) { |
| 1064 |
validate = macro.call(self, schema, parentSchema); |
| 1065 |
if (opts.validateSchema !== false) self.validateSchema(validate, true); |
| 1066 |
} else if (inline) { |
| 1067 |
validate = inline.call(self, it, rule.keyword, schema, parentSchema); |
| 1068 |
} else { |
| 1069 |
validate = rule.definition.validate; |
| 1070 |
} |
| 1071 |
|
| 1072 |
var index = customRules.length; |
| 1073 |
customRules[index] = validate; |
| 1074 |
|
| 1075 |
return { |
| 1076 |
code: 'customRule' + index, |
| 1077 |
validate: validate |
| 1078 |
}; |
| 1079 |
} |
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
function patternCode(i, patterns) { |
| 1084 |
return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ');'; |
| 1085 |
} |
| 1086 |
|
| 1087 |
|
| 1088 |
function defaultCode(i) { |
| 1089 |
return 'var default' + i + ' = defaults[' + i + '];'; |
| 1090 |
} |
| 1091 |
|
| 1092 |
|
| 1093 |
function refValCode(i, refVal) { |
| 1094 |
return refVal[i] ? 'var refVal' + i + ' = refVal[' + i + '];' : ''; |
| 1095 |
} |
| 1096 |
|
| 1097 |
|
| 1098 |
function customRuleCode(i) { |
| 1099 |
return 'var customRule' + i + ' = customRules[' + i + '];'; |
| 1100 |
} |
| 1101 |
|
| 1102 |
|
| 1103 |
function vars(arr, statement) { |
| 1104 |
if (!arr.length) return ''; |
| 1105 |
var code = ''; |
| 1106 |
for (var i=0; i<arr.length; i++) |
| 1107 |
code += statement(i, arr); |
| 1108 |
return code; |
| 1109 |
} |
| 1110 |
|
| 1111 |
|
| 1112 |
/*eslint-disable no-unused-vars */ |
| 1113 |
|
| 1114 |
/** |
| 1115 |
* Functions below are used inside compiled validations function |
| 1116 |
*/ |
| 1117 |
|
| 1118 |
var co = __webpack_require__(19); |
| 1119 |
|
| 1120 |
var ucs2length = util.ucs2length; |
| 1121 |
|
| 1122 |
var equal = __webpack_require__(10); |
| 1123 |
|
| 1124 |
// this error is thrown by async schemas to return validation errors via exception |
| 1125 |
var ValidationError = __webpack_require__(20); |
| 1126 |
|
| 1127 |
/*eslint-enable no-unused-vars */ |
| 1128 |
|
| 1129 |
|
| 1130 |
/***/ }, |
| 1131 |
/* 3 */ |
| 1132 |
/***/ function(module, exports, __webpack_require__) { |
| 1133 |
|
| 1134 |
'use strict'; |
| 1135 |
|
| 1136 |
var url = __webpack_require__(4) |
| 1137 |
, equal = __webpack_require__(10) |
| 1138 |
, util = __webpack_require__(11) |
| 1139 |
, SchemaObject = __webpack_require__(16); |
| 1140 |
|
| 1141 |
module.exports = resolve; |
| 1142 |
|
| 1143 |
resolve.normalizeId = normalizeId; |
| 1144 |
resolve.fullPath = getFullPath; |
| 1145 |
resolve.url = resolveUrl; |
| 1146 |
resolve.ids = resolveIds; |
| 1147 |
resolve.inlineRef = inlineRef; |
| 1148 |
|
| 1149 |
/** |
| 1150 |
* [resolve and compile the references ($ref)] |
| 1151 |
* @this Ajv |
| 1152 |
* @param {Function} compile reference to schema compilation funciton (localCompile) |
| 1153 |
* @param {Object} root object with information about the root schema for the current schema |
| 1154 |
* @param {String} ref reference to resolve |
| 1155 |
* @return {Object|Function} schema object (if the schema can be inlined) or validation function |
| 1156 |
*/ |
| 1157 |
function resolve(compile, root, ref) { |
| 1158 |
/* jshint validthis: true */ |
| 1159 |
var refVal = this._refs[ref]; |
| 1160 |
if (typeof refVal == 'string') { |
| 1161 |
if (this._refs[refVal]) refVal = this._refs[refVal]; |
| 1162 |
else return resolve.call(this, compile, root, refVal); |
| 1163 |
} |
| 1164 |
|
| 1165 |
refVal = refVal || this._schemas[ref]; |
| 1166 |
if (refVal instanceof SchemaObject) { |
| 1167 |
return inlineRef(refVal.schema, this._opts.inlineRefs) |
| 1168 |
? refVal.schema |
| 1169 |
: refVal.validate || this._compile(refVal); |
| 1170 |
} |
| 1171 |
|
| 1172 |
var res = _resolve.call(this, root, ref); |
| 1173 |
var schema, v, baseId; |
| 1174 |
if (res) { |
| 1175 |
schema = res.schema; |
| 1176 |
root = res.root; |
| 1177 |
baseId = res.baseId; |
| 1178 |
} |
| 1179 |
|
| 1180 |
if (schema instanceof SchemaObject) { |
| 1181 |
v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId); |
| 1182 |
} else if (schema) { |
| 1183 |
v = inlineRef(schema, this._opts.inlineRefs) |
| 1184 |
? schema |
| 1185 |
: compile.call(this, schema, root, undefined, baseId); |
| 1186 |
} |
| 1187 |
|
| 1188 |
return v; |
| 1189 |
} |
| 1190 |
|
| 1191 |
|
| 1192 |
/* @this Ajv */ |
| 1193 |
function _resolve(root, ref) { |
| 1194 |
/* jshint validthis: true */ |
| 1195 |
var p = url.parse(ref, false, true) |
| 1196 |
, refPath = _getFullPath(p) |
| 1197 |
, baseId = getFullPath(root.schema.id); |
| 1198 |
if (refPath !== baseId) { |
| 1199 |
var id = normalizeId(refPath); |
| 1200 |
var refVal = this._refs[id]; |
| 1201 |
if (typeof refVal == 'string') { |
| 1202 |
return resolveRecursive.call(this, root, refVal, p); |
| 1203 |
} else if (refVal instanceof SchemaObject) { |
| 1204 |
if (!refVal.validate) this._compile(refVal); |
| 1205 |
root = refVal; |
| 1206 |
} else { |
| 1207 |
refVal = this._schemas[id]; |
| 1208 |
if (refVal instanceof SchemaObject) { |
| 1209 |
if (!refVal.validate) this._compile(refVal); |
| 1210 |
if (id == normalizeId(ref)) |
| 1211 |
return { schema: refVal, root: root, baseId: baseId }; |
| 1212 |
root = refVal; |
| 1213 |
} |
| 1214 |
} |
| 1215 |
if (!root.schema) return; |
| 1216 |
baseId = getFullPath(root.schema.id); |
| 1217 |
} |
| 1218 |
return getJsonPointer.call(this, p, baseId, root.schema, root); |
| 1219 |
} |
| 1220 |
|
| 1221 |
|
| 1222 |
/* @this Ajv */ |
| 1223 |
function resolveRecursive(root, ref, parsedRef) { |
| 1224 |
/* jshint validthis: true */ |
| 1225 |
var res = _resolve.call(this, root, ref); |
| 1226 |
if (res) { |
| 1227 |
var schema = res.schema; |
| 1228 |
var baseId = res.baseId; |
| 1229 |
root = res.root; |
| 1230 |
if (schema.id) baseId = resolveUrl(baseId, schema.id); |
| 1231 |
return getJsonPointer.call(this, parsedRef, baseId, schema, root); |
| 1232 |
} |
| 1233 |
} |
| 1234 |
|
| 1235 |
|
| 1236 |
var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']); |
| 1237 |
/* @this Ajv */ |
| 1238 |
function getJsonPointer(parsedRef, baseId, schema, root) { |
| 1239 |
/* jshint validthis: true */ |
| 1240 |
parsedRef.hash = parsedRef.hash || ''; |
| 1241 |
if (parsedRef.hash.slice(0,2) != '#/') return; |
| 1242 |
var parts = parsedRef.hash.split('/'); |
| 1243 |
|
| 1244 |
for (var i = 1; i < parts.length; i++) { |
| 1245 |
var part = parts[i]; |
| 1246 |
if (part) { |
| 1247 |
part = util.unescapeFragment(part); |
| 1248 |
schema = schema[part]; |
| 1249 |
if (!schema) break; |
| 1250 |
if (schema.id && !PREVENT_SCOPE_CHANGE[part]) baseId = resolveUrl(baseId, schema.id); |
| 1251 |
if (schema.$ref) { |
| 1252 |
var $ref = resolveUrl(baseId, schema.$ref); |
| 1253 |
var res = _resolve.call(this, root, $ref); |
| 1254 |
if (res) { |
| 1255 |
schema = res.schema; |
| 1256 |
root = res.root; |
| 1257 |
baseId = res.baseId; |
| 1258 |
} |
| 1259 |
} |
| 1260 |
} |
| 1261 |
} |
| 1262 |
if (schema && schema != root.schema) |
| 1263 |
return { schema: schema, root: root, baseId: baseId }; |
| 1264 |
} |
| 1265 |
|
| 1266 |
|
| 1267 |
var SIMPLE_INLINED = util.toHash([ |
| 1268 |
'type', 'format', 'pattern', |
| 1269 |
'maxLength', 'minLength', |
| 1270 |
'maxProperties', 'minProperties', |
| 1271 |
'maxItems', 'minItems', |
| 1272 |
'maximum', 'minimum', |
| 1273 |
'uniqueItems', 'multipleOf', |
| 1274 |
'required', 'enum' |
| 1275 |
]); |
| 1276 |
function inlineRef(schema, limit) { |
| 1277 |
if (limit === false) return false; |
| 1278 |
if (limit === undefined || limit === true) return checkNoRef(schema); |
| 1279 |
else if (limit) return countKeys(schema) <= limit; |
| 1280 |
} |
| 1281 |
|
| 1282 |
|
| 1283 |
function checkNoRef(schema) { |
| 1284 |
var item; |
| 1285 |
if (Array.isArray(schema)) { |
| 1286 |
for (var i=0; i<schema.length; i++) { |
| 1287 |
item = schema[i]; |
| 1288 |
if (typeof item == 'object' && !checkNoRef(item)) return false; |
| 1289 |
} |
| 1290 |
} else { |
| 1291 |
for (var key in schema) { |
| 1292 |
if (key == '$ref') return false; |
| 1293 |
item = schema[key]; |
| 1294 |
if (typeof item == 'object' && !checkNoRef(item)) return false; |
| 1295 |
} |
| 1296 |
} |
| 1297 |
return true; |
| 1298 |
} |
| 1299 |
|
| 1300 |
|
| 1301 |
function countKeys(schema) { |
| 1302 |
var count = 0, item; |
| 1303 |
if (Array.isArray(schema)) { |
| 1304 |
for (var i=0; i<schema.length; i++) { |
| 1305 |
item = schema[i]; |
| 1306 |
if (typeof item == 'object') count += countKeys(item); |
| 1307 |
if (count == Infinity) return Infinity; |
| 1308 |
} |
| 1309 |
} else { |
| 1310 |
for (var key in schema) { |
| 1311 |
if (key == '$ref') return Infinity; |
| 1312 |
if (SIMPLE_INLINED[key]) { |
| 1313 |
count++; |
| 1314 |
} else { |
| 1315 |
item = schema[key]; |
| 1316 |
if (typeof item == 'object') count += countKeys(item) + 1; |
| 1317 |
if (count == Infinity) return Infinity; |
| 1318 |
} |
| 1319 |
} |
| 1320 |
} |
| 1321 |
return count; |
| 1322 |
} |
| 1323 |
|
| 1324 |
|
| 1325 |
function getFullPath(id, normalize) { |
| 1326 |
if (normalize !== false) id = normalizeId(id); |
| 1327 |
var p = url.parse(id, false, true); |
| 1328 |
return _getFullPath(p); |
| 1329 |
} |
| 1330 |
|
| 1331 |
|
| 1332 |
function _getFullPath(p) { |
| 1333 |
return (p.protocol||'') + (p.protocol?'//':'') + (p.host||'') + (p.path||'') + '#'; |
| 1334 |
} |
| 1335 |
|
| 1336 |
|
| 1337 |
var TRAILING_SLASH_HASH = /#\/?$/; |
| 1338 |
function normalizeId(id) { |
| 1339 |
return id ? id.replace(TRAILING_SLASH_HASH, '') : ''; |
| 1340 |
} |
| 1341 |
|
| 1342 |
|
| 1343 |
function resolveUrl(baseId, id) { |
| 1344 |
id = normalizeId(id); |
| 1345 |
return url.resolve(baseId, id); |
| 1346 |
} |
| 1347 |
|
| 1348 |
|
| 1349 |
/* @this Ajv */ |
| 1350 |
function resolveIds(schema) { |
| 1351 |
/* eslint no-shadow: 0 */ |
| 1352 |
/* jshint validthis: true */ |
| 1353 |
var id = normalizeId(schema.id); |
| 1354 |
var localRefs = {}; |
| 1355 |
_resolveIds.call(this, schema, getFullPath(id, false), id); |
| 1356 |
return localRefs; |
| 1357 |
|
| 1358 |
function _resolveIds(schema, fullPath, baseId) { |
| 1359 |
/* jshint validthis: true */ |
| 1360 |
if (Array.isArray(schema)) { |
| 1361 |
for (var i=0; i<schema.length; i++) |
| 1362 |
_resolveIds.call(this, schema[i], fullPath+'/'+i, baseId); |
| 1363 |
} else if (schema && typeof schema == 'object') { |
| 1364 |
if (typeof schema.id == 'string') { |
| 1365 |
var id = baseId = baseId |
| 1366 |
? url.resolve(baseId, schema.id) |
| 1367 |
: schema.id; |
| 1368 |
id = normalizeId(id); |
| 1369 |
|
| 1370 |
var refVal = this._refs[id]; |
| 1371 |
if (typeof refVal == 'string') refVal = this._refs[refVal]; |
| 1372 |
if (refVal && refVal.schema) { |
| 1373 |
if (!equal(schema, refVal.schema)) |
| 1374 |
throw new Error('id "' + id + '" resolves to more than one schema'); |
| 1375 |
} else if (id != normalizeId(fullPath)) { |
| 1376 |
if (id[0] == '#') { |
| 1377 |
if (localRefs[id] && !equal(schema, localRefs[id])) |
| 1378 |
throw new Error('id "' + id + '" resolves to more than one schema'); |
| 1379 |
localRefs[id] = schema; |
| 1380 |
} else { |
| 1381 |
this._refs[id] = fullPath; |
| 1382 |
} |
| 1383 |
} |
| 1384 |
} |
| 1385 |
for (var key in schema) |
| 1386 |
_resolveIds.call(this, schema[key], fullPath+'/'+util.escapeFragment(key), baseId); |
| 1387 |
} |
| 1388 |
} |
| 1389 |
} |
| 1390 |
|
| 1391 |
|
| 1392 |
/***/ }, |
| 1393 |
/* 4 */ |
| 1394 |
/***/ function(module, exports, __webpack_require__) { |
| 1395 |
|
| 1396 |
// Copyright Joyent, Inc. and other Node contributors. |
| 1397 |
// |
| 1398 |
// Permission is hereby granted, free of charge, to any person obtaining a |
| 1399 |
// copy of this software and associated documentation files (the |
| 1400 |
// "Software"), to deal in the Software without restriction, including |
| 1401 |
// without limitation the rights to use, copy, modify, merge, publish, |
| 1402 |
// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 1403 |
// persons to whom the Software is furnished to do so, subject to the |
| 1404 |
// following conditions: |
| 1405 |
// |
| 1406 |
// The above copyright notice and this permission notice shall be included |
| 1407 |
// in all copies or substantial portions of the Software. |
| 1408 |
// |
| 1409 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 1410 |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 1411 |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 1412 |
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 1413 |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 1414 |
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 1415 |
// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 1416 |
|
| 1417 |
var punycode = __webpack_require__(5); |
| 1418 |
|
| 1419 |
exports.parse = urlParse; |
| 1420 |
exports.resolve = urlResolve; |
| 1421 |
exports.resolveObject = urlResolveObject; |
| 1422 |
exports.format = urlFormat; |
| 1423 |
|
| 1424 |
exports.Url = Url; |
| 1425 |
|
| 1426 |
function Url() { |
| 1427 |
this.protocol = null; |
| 1428 |
this.slashes = null; |
| 1429 |
this.auth = null; |
| 1430 |
this.host = null; |
| 1431 |
this.port = null; |
| 1432 |
this.hostname = null; |
| 1433 |
this.hash = null; |
| 1434 |
this.search = null; |
| 1435 |
this.query = null; |
| 1436 |
this.pathname = null; |
| 1437 |
this.path = null; |
| 1438 |
this.href = null; |
| 1439 |
} |
| 1440 |
|
| 1441 |
// Reference: RFC 3986, RFC 1808, RFC 2396 |
| 1442 |
|
| 1443 |
// define these here so at least they only have to be |
| 1444 |
// compiled once on the first module load. |
| 1445 |
var protocolPattern = /^([a-z0-9.+-]+:)/i, |
| 1446 |
portPattern = /:[0-9]*$/, |
| 1447 |
|
| 1448 |
// RFC 2396: characters reserved for delimiting URLs. |
| 1449 |
// We actually just auto-escape these. |
| 1450 |
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'], |
| 1451 |
|
| 1452 |
// RFC 2396: characters not allowed for various reasons. |
| 1453 |
unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims), |
| 1454 |
|
| 1455 |
// Allowed by RFCs, but cause of XSS attacks. Always escape these. |
| 1456 |
autoEscape = ['\''].concat(unwise), |
| 1457 |
// Characters that are never ever allowed in a hostname. |
| 1458 |
// Note that any invalid chars are also handled, but these |
| 1459 |
// are the ones that are *expected* to be seen, so we fast-path |
| 1460 |
// them. |
| 1461 |
nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape), |
| 1462 |
hostEndingChars = ['/', '?', '#'], |
| 1463 |
hostnameMaxLen = 255, |
| 1464 |
hostnamePartPattern = /^[a-z0-9A-Z_-]{0,63}$/, |
| 1465 |
hostnamePartStart = /^([a-z0-9A-Z_-]{0,63})(.*)$/, |
| 1466 |
// protocols that can allow "unsafe" and "unwise" chars. |
| 1467 |
unsafeProtocol = { |
| 1468 |
'javascript': true, |
| 1469 |
'javascript:': true |
| 1470 |
}, |
| 1471 |
// protocols that never have a hostname. |
| 1472 |
hostlessProtocol = { |
| 1473 |
'javascript': true, |
| 1474 |
'javascript:': true |
| 1475 |
}, |
| 1476 |
// protocols that always contain a // bit. |
| 1477 |
slashedProtocol = { |
| 1478 |
'http': true, |
| 1479 |
'https': true, |
| 1480 |
'ftp': true, |
| 1481 |
'gopher': true, |
| 1482 |
'file': true, |
| 1483 |
'http:': true, |
| 1484 |
'https:': true, |
| 1485 |
'ftp:': true, |
| 1486 |
'gopher:': true, |
| 1487 |
'file:': true |
| 1488 |
}, |
| 1489 |
querystring = __webpack_require__(7); |
| 1490 |
|
| 1491 |
function urlParse(url, parseQueryString, slashesDenoteHost) { |
| 1492 |
if (url && isObject(url) && url instanceof Url) return url; |
| 1493 |
|
| 1494 |
var u = new Url; |
| 1495 |
u.parse(url, parseQueryString, slashesDenoteHost); |
| 1496 |
return u; |
| 1497 |
} |
| 1498 |
|
| 1499 |
Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { |
| 1500 |
if (!isString(url)) { |
| 1501 |
throw new TypeError("Parameter 'url' must be a string, not " + typeof url); |
| 1502 |
} |
| 1503 |
|
| 1504 |
var rest = url; |
| 1505 |
|
| 1506 |
// trim before proceeding. |
| 1507 |
// This is to support parse stuff like " http://foo.com \n" |
| 1508 |
rest = rest.trim(); |
| 1509 |
|
| 1510 |
var proto = protocolPattern.exec(rest); |
| 1511 |
if (proto) { |
| 1512 |
proto = proto[0]; |
| 1513 |
var lowerProto = proto.toLowerCase(); |
| 1514 |
this.protocol = lowerProto; |
| 1515 |
rest = rest.substr(proto.length); |
| 1516 |
} |
| 1517 |
|
| 1518 |
// figure out if it's got a host |
| 1519 |
// user@server is *always* interpreted as a hostname, and url |
| 1520 |
// resolution will treat //foo/bar as host=foo,path=bar because that's |
| 1521 |
// how the browser resolves relative URLs. |
| 1522 |
if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { |
| 1523 |
var slashes = rest.substr(0, 2) === '//'; |
| 1524 |
if (slashes && !(proto && hostlessProtocol[proto])) { |
| 1525 |
rest = rest.substr(2); |
| 1526 |
this.slashes = true; |
| 1527 |
} |
| 1528 |
} |
| 1529 |
|
| 1530 |
if (!hostlessProtocol[proto] && |
| 1531 |
(slashes || (proto && !slashedProtocol[proto]))) { |
| 1532 |
|
| 1533 |
// there's a hostname. |
| 1534 |
// the first instance of /, ?, ;, or # ends the host. |
| 1535 |
// |
| 1536 |
// If there is an @ in the hostname, then non-host chars *are* allowed |
| 1537 |
// to the left of the last @ sign, unless some host-ending character |
| 1538 |
// comes *before* the @-sign. |
| 1539 |
// URLs are obnoxious. |
| 1540 |
// |
| 1541 |
// ex: |
| 1542 |
// http://a@b@c/ => user:a@b host:c |
| 1543 |
// http://a@b?@c => user:a host:c path:/?@c |
| 1544 |
|
| 1545 |
// v0.12 TODO(isaacs): This is not quite how Chrome does things. |
| 1546 |
// Review our test case against browsers more comprehensively. |
| 1547 |
|
| 1548 |
// find the first instance of any hostEndingChars |
| 1549 |
var hostEnd = -1; |
| 1550 |
for (var i = 0; i < hostEndingChars.length; i++) { |
| 1551 |
var hec = rest.indexOf(hostEndingChars[i]); |
| 1552 |
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) |
| 1553 |
hostEnd = hec; |
| 1554 |
} |
| 1555 |
|
| 1556 |
// at this point, either we have an explicit point where the |
| 1557 |
// auth portion cannot go past, or the last @ char is the decider. |
| 1558 |
var auth, atSign; |
| 1559 |
if (hostEnd === -1) { |
| 1560 |
// atSign can be anywhere. |
| 1561 |
atSign = rest.lastIndexOf('@'); |
| 1562 |
} else { |
| 1563 |
// atSign must be in auth portion. |
| 1564 |
// http://a@b/c@d => host:b auth:a path:/c@d |
| 1565 |
atSign = rest.lastIndexOf('@', hostEnd); |
| 1566 |
} |
| 1567 |
|
| 1568 |
// Now we have a portion which is definitely the auth. |
| 1569 |
// Pull that off. |
| 1570 |
if (atSign !== -1) { |
| 1571 |
auth = rest.slice(0, atSign); |
| 1572 |
rest = rest.slice(atSign + 1); |
| 1573 |
this.auth = decodeURIComponent(auth); |
| 1574 |
} |
| 1575 |
|
| 1576 |
// the host is the remaining to the left of the first non-host char |
| 1577 |
hostEnd = -1; |
| 1578 |
for (var i = 0; i < nonHostChars.length; i++) { |
| 1579 |
var hec = rest.indexOf(nonHostChars[i]); |
| 1580 |
if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) |
| 1581 |
hostEnd = hec; |
| 1582 |
} |
| 1583 |
// if we still have not hit it, then the entire thing is a host. |
| 1584 |
if (hostEnd === -1) |
| 1585 |
hostEnd = rest.length; |
| 1586 |
|
| 1587 |
this.host = rest.slice(0, hostEnd); |
| 1588 |
rest = rest.slice(hostEnd); |
| 1589 |
|
| 1590 |
// pull out port. |
| 1591 |
this.parseHost(); |
| 1592 |
|
| 1593 |
// we've indicated that there is a hostname, |
| 1594 |
// so even if it's empty, it has to be present. |
| 1595 |
this.hostname = this.hostname || ''; |
| 1596 |
|
| 1597 |
// if hostname begins with [ and ends with ] |
| 1598 |
// assume that it's an IPv6 address. |
| 1599 |
var ipv6Hostname = this.hostname[0] === '[' && |
| 1600 |
this.hostname[this.hostname.length - 1] === ']'; |
| 1601 |
|
| 1602 |
// validate a little. |
| 1603 |
if (!ipv6Hostname) { |
| 1604 |
var hostparts = this.hostname.split(/\./); |
| 1605 |
for (var i = 0, l = hostparts.length; i < l; i++) { |
| 1606 |
var part = hostparts[i]; |
| 1607 |
if (!part) continue; |
| 1608 |
if (!part.match(hostnamePartPattern)) { |
| 1609 |
var newpart = ''; |
| 1610 |
for (var j = 0, k = part.length; j < k; j++) { |
| 1611 |
if (part.charCodeAt(j) > 127) { |
| 1612 |
// we replace non-ASCII char with a temporary placeholder |
| 1613 |
// we need this to make sure size of hostname is not |
| 1614 |
// broken by replacing non-ASCII by nothing |
| 1615 |
newpart += 'x'; |
| 1616 |
} else { |
| 1617 |
newpart += part[j]; |
| 1618 |
} |
| 1619 |
} |
| 1620 |
// we test again with ASCII char only |
| 1621 |
if (!newpart.match(hostnamePartPattern)) { |
| 1622 |
var validParts = hostparts.slice(0, i); |
| 1623 |
var notHost = hostparts.slice(i + 1); |
| 1624 |
var bit = part.match(hostnamePartStart); |
| 1625 |
if (bit) { |
| 1626 |
validParts.push(bit[1]); |
| 1627 |
notHost.unshift(bit[2]); |
| 1628 |
} |
| 1629 |
if (notHost.length) { |
| 1630 |
rest = '/' + notHost.join('.') + rest; |
| 1631 |
} |
| 1632 |
this.hostname = validParts.join('.'); |
| 1633 |
break; |
| 1634 |
} |
| 1635 |
} |
| 1636 |
} |
| 1637 |
} |
| 1638 |
|
| 1639 |
if (this.hostname.length > hostnameMaxLen) { |
| 1640 |
this.hostname = ''; |
| 1641 |
} else { |
| 1642 |
// hostnames are always lower case. |
| 1643 |
this.hostname = this.hostname.toLowerCase(); |
| 1644 |
} |
| 1645 |
|
| 1646 |
if (!ipv6Hostname) { |
| 1647 |
// IDNA Support: Returns a puny coded representation of "domain". |
| 1648 |
// It only converts the part of the domain name that |
| 1649 |
// has non ASCII characters. I.e. it dosent matter if |
| 1650 |
// you call it with a domain that already is in ASCII. |
| 1651 |
var domainArray = this.hostname.split('.'); |
| 1652 |
var newOut = []; |
| 1653 |
for (var i = 0; i < domainArray.length; ++i) { |
| 1654 |
var s = domainArray[i]; |
| 1655 |
newOut.push(s.match(/[^A-Za-z0-9_-]/) ? |
| 1656 |
'xn--' + punycode.encode(s) : s); |
| 1657 |
} |
| 1658 |
this.hostname = newOut.join('.'); |
| 1659 |
} |
| 1660 |
|
| 1661 |
var p = this.port ? ':' + this.port : ''; |
| 1662 |
var h = this.hostname || ''; |
| 1663 |
this.host = h + p; |
| 1664 |
this.href += this.host; |
| 1665 |
|
| 1666 |
// strip [ and ] from the hostname |
| 1667 |
// the host field still retains them, though |
| 1668 |
if (ipv6Hostname) { |
| 1669 |
this.hostname = this.hostname.substr(1, this.hostname.length - 2); |
| 1670 |
if (rest[0] !== '/') { |
| 1671 |
rest = '/' + rest; |
| 1672 |
} |
| 1673 |
} |
| 1674 |
} |
| 1675 |
|
| 1676 |
// now rest is set to the post-host stuff. |
| 1677 |
// chop off any delim chars. |
| 1678 |
if (!unsafeProtocol[lowerProto]) { |
| 1679 |
|
| 1680 |
// First, make 100% sure that any "autoEscape" chars get |
| 1681 |
// escaped, even if encodeURIComponent doesn't think they |
| 1682 |
// need to be. |
| 1683 |
for (var i = 0, l = autoEscape.length; i < l; i++) { |
| 1684 |
var ae = autoEscape[i]; |
| 1685 |
var esc = encodeURIComponent(ae); |
| 1686 |
if (esc === ae) { |
| 1687 |
esc = escape(ae); |
| 1688 |
} |
| 1689 |
rest = rest.split(ae).join(esc); |
| 1690 |
} |
| 1691 |
} |
| 1692 |
|
| 1693 |
|
| 1694 |
// chop off from the tail first. |
| 1695 |
var hash = rest.indexOf('#'); |
| 1696 |
if (hash !== -1) { |
| 1697 |
// got a fragment string. |
| 1698 |
this.hash = rest.substr(hash); |
| 1699 |
rest = rest.slice(0, hash); |
| 1700 |
} |
| 1701 |
var qm = rest.indexOf('?'); |
| 1702 |
if (qm !== -1) { |
| 1703 |
this.search = rest.substr(qm); |
| 1704 |
this.query = rest.substr(qm + 1); |
| 1705 |
if (parseQueryString) { |
| 1706 |
this.query = querystring.parse(this.query); |
| 1707 |
} |
| 1708 |
rest = rest.slice(0, qm); |
| 1709 |
} else if (parseQueryString) { |
| 1710 |
// no query string, but parseQueryString still requested |
| 1711 |
this.search = ''; |
| 1712 |
this.query = {}; |
| 1713 |
} |
| 1714 |
if (rest) this.pathname = rest; |
| 1715 |
if (slashedProtocol[lowerProto] && |
| 1716 |
this.hostname && !this.pathname) { |
| 1717 |
this.pathname = '/'; |
| 1718 |
} |
| 1719 |
|
| 1720 |
//to support http.request |
| 1721 |
if (this.pathname || this.search) { |
| 1722 |
var p = this.pathname || ''; |
| 1723 |
var s = this.search || ''; |
| 1724 |
this.path = p + s; |
| 1725 |
} |
| 1726 |
|
| 1727 |
// finally, reconstruct the href based on what has been validated. |
| 1728 |
this.href = this.format(); |
| 1729 |
return this; |
| 1730 |
}; |
| 1731 |
|
| 1732 |
// format a parsed object into a url string |
| 1733 |
function urlFormat(obj) { |
| 1734 |
// ensure it's an object, and not a string url. |
| 1735 |
// If it's an obj, this is a no-op. |
| 1736 |
// this way, you can call url_format() on strings |
| 1737 |
// to clean up potentially wonky urls. |
| 1738 |
if (isString(obj)) obj = urlParse(obj); |
| 1739 |
if (!(obj instanceof Url)) return Url.prototype.format.call(obj); |
| 1740 |
return obj.format(); |
| 1741 |
} |
| 1742 |
|
| 1743 |
Url.prototype.format = function() { |
| 1744 |
var auth = this.auth || ''; |
| 1745 |
if (auth) { |
| 1746 |
auth = encodeURIComponent(auth); |
| 1747 |
auth = auth.replace(/%3A/i, ':'); |
| 1748 |
auth += '@'; |
| 1749 |
} |
| 1750 |
|
| 1751 |
var protocol = this.protocol || '', |
| 1752 |
pathname = this.pathname || '', |
| 1753 |
hash = this.hash || '', |
| 1754 |
host = false, |
| 1755 |
query = ''; |
| 1756 |
|
| 1757 |
if (this.host) { |
| 1758 |
host = auth + this.host; |
| 1759 |
} else if (this.hostname) { |
| 1760 |
host = auth + (this.hostname.indexOf(':') === -1 ? |
| 1761 |
this.hostname : |
| 1762 |
'[' + this.hostname + ']'); |
| 1763 |
if (this.port) { |
| 1764 |
host += ':' + this.port; |
| 1765 |
} |
| 1766 |
} |
| 1767 |
|
| 1768 |
if (this.query && |
| 1769 |
isObject(this.query) && |
| 1770 |
Object.keys(this.query).length) { |
| 1771 |
query = querystring.stringify(this.query); |
| 1772 |
} |
| 1773 |
|
| 1774 |
var search = this.search || (query && ('?' + query)) || ''; |
| 1775 |
|
| 1776 |
if (protocol && protocol.substr(-1) !== ':') protocol += ':'; |
| 1777 |
|
| 1778 |
// only the slashedProtocols get the //. Not mailto:, xmpp:, etc. |
| 1779 |
// unless they had them to begin with. |
| 1780 |
if (this.slashes || |
| 1781 |
(!protocol || slashedProtocol[protocol]) && host !== false) { |
| 1782 |
host = '//' + (host || ''); |
| 1783 |
if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname; |
| 1784 |
} else if (!host) { |
| 1785 |
host = ''; |
| 1786 |
} |
| 1787 |
|
| 1788 |
if (hash && hash.charAt(0) !== '#') hash = '#' + hash; |
| 1789 |
if (search && search.charAt(0) !== '?') search = '?' + search; |
| 1790 |
|
| 1791 |
pathname = pathname.replace(/[?#]/g, function(match) { |
| 1792 |
return encodeURIComponent(match); |
| 1793 |
}); |
| 1794 |
search = search.replace('#', '%23'); |
| 1795 |
|
| 1796 |
return protocol + host + pathname + search + hash; |
| 1797 |
}; |
| 1798 |
|
| 1799 |
function urlResolve(source, relative) { |
| 1800 |
return urlParse(source, false, true).resolve(relative); |
| 1801 |
} |
| 1802 |
|
| 1803 |
Url.prototype.resolve = function(relative) { |
| 1804 |
return this.resolveObject(urlParse(relative, false, true)).format(); |
| 1805 |
}; |
| 1806 |
|
| 1807 |
function urlResolveObject(source, relative) { |
| 1808 |
if (!source) return relative; |
| 1809 |
return urlParse(source, false, true).resolveObject(relative); |
| 1810 |
} |
| 1811 |
|
| 1812 |
Url.prototype.resolveObject = function(relative) { |
| 1813 |
if (isString(relative)) { |
| 1814 |
var rel = new Url(); |
| 1815 |
rel.parse(relative, false, true); |
| 1816 |
relative = rel; |
| 1817 |
} |
| 1818 |
|
| 1819 |
var result = new Url(); |
| 1820 |
Object.keys(this).forEach(function(k) { |
| 1821 |
result[k] = this[k]; |
| 1822 |
}, this); |
| 1823 |
|
| 1824 |
// hash is always overridden, no matter what. |
| 1825 |
// even href="" will remove it. |
| 1826 |
result.hash = relative.hash; |
| 1827 |
|
| 1828 |
// if the relative url is empty, then there's nothing left to do here. |
| 1829 |
if (relative.href === '') { |
| 1830 |
result.href = result.format(); |
| 1831 |
return result; |
| 1832 |
} |
| 1833 |
|
| 1834 |
// hrefs like //foo/bar always cut to the protocol. |
| 1835 |
if (relative.slashes && !relative.protocol) { |
| 1836 |
// take everything except the protocol from relative |
| 1837 |
Object.keys(relative).forEach(function(k) { |
| 1838 |
if (k !== 'protocol') |
| 1839 |
result[k] = relative[k]; |
| 1840 |
}); |
| 1841 |
|
| 1842 |
//urlParse appends trailing / to urls like http://www.example.com |
| 1843 |
if (slashedProtocol[result.protocol] && |
| 1844 |
result.hostname && !result.pathname) { |
| 1845 |
result.path = result.pathname = '/'; |
| 1846 |
} |
| 1847 |
|
| 1848 |
result.href = result.format(); |
| 1849 |
return result; |
| 1850 |
} |
| 1851 |
|
| 1852 |
if (relative.protocol && relative.protocol !== result.protocol) { |
| 1853 |
// if it's a known url protocol, then changing |
| 1854 |
// the protocol does weird things |
| 1855 |
// first, if it's not file:, then we MUST have a host, |
| 1856 |
// and if there was a path |
| 1857 |
// to begin with, then we MUST have a path. |
| 1858 |
// if it is file:, then the host is dropped, |
| 1859 |
// because that's known to be hostless. |
| 1860 |
// anything else is assumed to be absolute. |
| 1861 |
if (!slashedProtocol[relative.protocol]) { |
| 1862 |
Object.keys(relative).forEach(function(k) { |
| 1863 |
result[k] = relative[k]; |
| 1864 |
}); |
| 1865 |
result.href = result.format(); |
| 1866 |
return result; |
| 1867 |
} |
| 1868 |
|
| 1869 |
result.protocol = relative.protocol; |
| 1870 |
if (!relative.host && !hostlessProtocol[relative.protocol]) { |
| 1871 |
var relPath = (relative.pathname || '').split('/'); |
| 1872 |
while (relPath.length && !(relative.host = relPath.shift())); |
| 1873 |
if (!relative.host) relative.host = ''; |
| 1874 |
if (!relative.hostname) relative.hostname = ''; |
| 1875 |
if (relPath[0] !== '') relPath.unshift(''); |
| 1876 |
if (relPath.length < 2) relPath.unshift(''); |
| 1877 |
result.pathname = relPath.join('/'); |
| 1878 |
} else { |
| 1879 |
result.pathname = relative.pathname; |
| 1880 |
} |
| 1881 |
result.search = relative.search; |
| 1882 |
result.query = relative.query; |
| 1883 |
result.host = relative.host || ''; |
| 1884 |
result.auth = relative.auth; |
| 1885 |
result.hostname = relative.hostname || relative.host; |
| 1886 |
result.port = relative.port; |
| 1887 |
// to support http.request |
| 1888 |
if (result.pathname || result.search) { |
| 1889 |
var p = result.pathname || ''; |
| 1890 |
var s = result.search || ''; |
| 1891 |
result.path = p + s; |
| 1892 |
} |
| 1893 |
result.slashes = result.slashes || relative.slashes; |
| 1894 |
result.href = result.format(); |
| 1895 |
return result; |
| 1896 |
} |
| 1897 |
|
| 1898 |
var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'), |
| 1899 |
isRelAbs = ( |
| 1900 |
relative.host || |
| 1901 |
relative.pathname && relative.pathname.charAt(0) === '/' |
| 1902 |
), |
| 1903 |
mustEndAbs = (isRelAbs || isSourceAbs || |
| 1904 |
(result.host && relative.pathname)), |
| 1905 |
removeAllDots = mustEndAbs, |
| 1906 |
srcPath = result.pathname && result.pathname.split('/') || [], |
| 1907 |
relPath = relative.pathname && relative.pathname.split('/') || [], |
| 1908 |
psychotic = result.protocol && !slashedProtocol[result.protocol]; |
| 1909 |
|
| 1910 |
// if the url is a non-slashed url, then relative |
| 1911 |
// links like ../.. should be able |
| 1912 |
// to crawl up to the hostname, as well. This is strange. |
| 1913 |
// result.protocol has already been set by now. |
| 1914 |
// Later on, put the first path part into the host field. |
| 1915 |
if (psychotic) { |
| 1916 |
result.hostname = ''; |
| 1917 |
result.port = null; |
| 1918 |
if (result.host) { |
| 1919 |
if (srcPath[0] === '') srcPath[0] = result.host; |
| 1920 |
else srcPath.unshift(result.host); |
| 1921 |
} |
| 1922 |
result.host = ''; |
| 1923 |
if (relative.protocol) { |
| 1924 |
relative.hostname = null; |
| 1925 |
relative.port = null; |
| 1926 |
if (relative.host) { |
| 1927 |
if (relPath[0] === '') relPath[0] = relative.host; |
| 1928 |
else relPath.unshift(relative.host); |
| 1929 |
} |
| 1930 |
relative.host = null; |
| 1931 |
} |
| 1932 |
mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === ''); |
| 1933 |
} |
| 1934 |
|
| 1935 |
if (isRelAbs) { |
| 1936 |
// it's absolute. |
| 1937 |
result.host = (relative.host || relative.host === '') ? |
| 1938 |
relative.host : result.host; |
| 1939 |
result.hostname = (relative.hostname || relative.hostname === '') ? |
| 1940 |
relative.hostname : result.hostname; |
| 1941 |
result.search = relative.search; |
| 1942 |
result.query = relative.query; |
| 1943 |
srcPath = relPath; |
| 1944 |
// fall through to the dot-handling below. |
| 1945 |
} else if (relPath.length) { |
| 1946 |
// it's relative |
| 1947 |
// throw away the existing file, and take the new path instead. |
| 1948 |
if (!srcPath) srcPath = []; |
| 1949 |
srcPath.pop(); |
| 1950 |
srcPath = srcPath.concat(relPath); |
| 1951 |
result.search = relative.search; |
| 1952 |
result.query = relative.query; |
| 1953 |
} else if (!isNullOrUndefined(relative.search)) { |
| 1954 |
// just pull out the search. |
| 1955 |
// like href='?foo'. |
| 1956 |
// Put this after the other two cases because it simplifies the booleans |
| 1957 |
if (psychotic) { |
| 1958 |
result.hostname = result.host = srcPath.shift(); |
| 1959 |
//occationaly the auth can get stuck only in host |
| 1960 |
//this especialy happens in cases like |
| 1961 |
//url.resolveObject('mailto:local1@domain1', 'local2@domain2') |
| 1962 |
var authInHost = result.host && result.host.indexOf('@') > 0 ? |
| 1963 |
result.host.split('@') : false; |
| 1964 |
if (authInHost) { |
| 1965 |
result.auth = authInHost.shift(); |
| 1966 |
result.host = result.hostname = authInHost.shift(); |
| 1967 |
} |
| 1968 |
} |
| 1969 |
result.search = relative.search; |
| 1970 |
result.query = relative.query; |
| 1971 |
//to support http.request |
| 1972 |
if (!isNull(result.pathname) || !isNull(result.search)) { |
| 1973 |
result.path = (result.pathname ? result.pathname : '') + |
| 1974 |
(result.search ? result.search : ''); |
| 1975 |
} |
| 1976 |
result.href = result.format(); |
| 1977 |
return result; |
| 1978 |
} |
| 1979 |
|
| 1980 |
if (!srcPath.length) { |
| 1981 |
// no path at all. easy. |
| 1982 |
// we've already handled the other stuff above. |
| 1983 |
result.pathname = null; |
| 1984 |
//to support http.request |
| 1985 |
if (result.search) { |
| 1986 |
result.path = '/' + result.search; |
| 1987 |
} else { |
| 1988 |
result.path = null; |
| 1989 |
} |
| 1990 |
result.href = result.format(); |
| 1991 |
return result; |
| 1992 |
} |
| 1993 |
|
| 1994 |
// if a url ENDs in . or .., then it must get a trailing slash. |
| 1995 |
// however, if it ends in anything else non-slashy, |
| 1996 |
// then it must NOT get a trailing slash. |
| 1997 |
var last = srcPath.slice(-1)[0]; |
| 1998 |
var hasTrailingSlash = ( |
| 1999 |
(result.host || relative.host) && (last === '.' || last === '..') || |
| 2000 |
last === ''); |
| 2001 |
|
| 2002 |
// strip single dots, resolve double dots to parent dir |
| 2003 |
// if the path tries to go above the root, `up` ends up > 0 |
| 2004 |
var up = 0; |
| 2005 |
for (var i = srcPath.length; i >= 0; i--) { |
| 2006 |
last = srcPath[i]; |
| 2007 |
if (last == '.') { |
| 2008 |
srcPath.splice(i, 1); |
| 2009 |
} else if (last === '..') { |
| 2010 |
srcPath.splice(i, 1); |
| 2011 |
up++; |
| 2012 |
} else if (up) { |
| 2013 |
srcPath.splice(i, 1); |
| 2014 |
up--; |
| 2015 |
} |
| 2016 |
} |
| 2017 |
|
| 2018 |
// if the path is allowed to go above the root, restore leading ..s |
| 2019 |
if (!mustEndAbs && !removeAllDots) { |
| 2020 |
for (; up--; up) { |
| 2021 |
srcPath.unshift('..'); |
| 2022 |
} |
| 2023 |
} |
| 2024 |
|
| 2025 |
if (mustEndAbs && srcPath[0] !== '' && |
| 2026 |
(!srcPath[0] || srcPath[0].charAt(0) !== '/')) { |
| 2027 |
srcPath.unshift(''); |
| 2028 |
} |
| 2029 |
|
| 2030 |
if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) { |
| 2031 |
srcPath.push(''); |
| 2032 |
} |
| 2033 |
|
| 2034 |
var isAbsolute = srcPath[0] === '' || |
| 2035 |
(srcPath[0] && srcPath[0].charAt(0) === '/'); |
| 2036 |
|
| 2037 |
// put the host back |
| 2038 |
if (psychotic) { |
| 2039 |
result.hostname = result.host = isAbsolute ? '' : |
| 2040 |
srcPath.length ? srcPath.shift() : ''; |
| 2041 |
//occationaly the auth can get stuck only in host |
| 2042 |
//this especialy happens in cases like |
| 2043 |
//url.resolveObject('mailto:local1@domain1', 'local2@domain2') |
| 2044 |
var authInHost = result.host && result.host.indexOf('@') > 0 ? |
| 2045 |
result.host.split('@') : false; |
| 2046 |
if (authInHost) { |
| 2047 |
result.auth = authInHost.shift(); |
| 2048 |
result.host = result.hostname = authInHost.shift(); |
| 2049 |
} |
| 2050 |
} |
| 2051 |
|
| 2052 |
mustEndAbs = mustEndAbs || (result.host && srcPath.length); |
| 2053 |
|
| 2054 |
if (mustEndAbs && !isAbsolute) { |
| 2055 |
srcPath.unshift(''); |
| 2056 |
} |
| 2057 |
|
| 2058 |
if (!srcPath.length) { |
| 2059 |
result.pathname = null; |
| 2060 |
result.path = null; |
| 2061 |
} else { |
| 2062 |
result.pathname = srcPath.join('/'); |
| 2063 |
} |
| 2064 |
|
| 2065 |
//to support request.http |
| 2066 |
if (!isNull(result.pathname) || !isNull(result.search)) { |
| 2067 |
result.path = (result.pathname ? result.pathname : '') + |
| 2068 |
(result.search ? result.search : ''); |
| 2069 |
} |
| 2070 |
result.auth = relative.auth || result.auth; |
| 2071 |
result.slashes = result.slashes || relative.slashes; |
| 2072 |
result.href = result.format(); |
| 2073 |
return result; |
| 2074 |
}; |
| 2075 |
|
| 2076 |
Url.prototype.parseHost = function() { |
| 2077 |
var host = this.host; |
| 2078 |
var port = portPattern.exec(host); |
| 2079 |
if (port) { |
| 2080 |
port = port[0]; |
| 2081 |
if (port !== ':') { |
| 2082 |
this.port = port.substr(1); |
| 2083 |
} |
| 2084 |
host = host.substr(0, host.length - port.length); |
| 2085 |
} |
| 2086 |
if (host) this.hostname = host; |
| 2087 |
}; |
| 2088 |
|
| 2089 |
function isString(arg) { |
| 2090 |
return typeof arg === "string"; |
| 2091 |
} |
| 2092 |
|
| 2093 |
function isObject(arg) { |
| 2094 |
return typeof arg === 'object' && arg !== null; |
| 2095 |
} |
| 2096 |
|
| 2097 |
function isNull(arg) { |
| 2098 |
return arg === null; |
| 2099 |
} |
| 2100 |
function isNullOrUndefined(arg) { |
| 2101 |
return arg == null; |
| 2102 |
} |
| 2103 |
|
| 2104 |
|
| 2105 |
/***/ }, |
| 2106 |
/* 5 */ |
| 2107 |
/***/ function(module, exports, __webpack_require__) { |
| 2108 |
|
| 2109 |
var __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module, global) {/*! https://mths.be/punycode v1.3.2 by @mathias */ |
| 2110 |
;(function(root) { |
| 2111 |
|
| 2112 |
/** Detect free variables */ |
| 2113 |
var freeExports = typeof exports == 'object' && exports && |
| 2114 |
!exports.nodeType && exports; |
| 2115 |
var freeModule = typeof module == 'object' && module && |
| 2116 |
!module.nodeType && module; |
| 2117 |
var freeGlobal = typeof global == 'object' && global; |
| 2118 |
if ( |
| 2119 |
freeGlobal.global === freeGlobal || |
| 2120 |
freeGlobal.window === freeGlobal || |
| 2121 |
freeGlobal.self === freeGlobal |
| 2122 |
) { |
| 2123 |
root = freeGlobal; |
| 2124 |
} |
| 2125 |
|
| 2126 |
/** |
| 2127 |
* The `punycode` object. |
| 2128 |
* @name punycode |
| 2129 |
* @type Object |
| 2130 |
*/ |
| 2131 |
var punycode, |
| 2132 |
|
| 2133 |
/** Highest positive signed 32-bit float value */ |
| 2134 |
maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 |
| 2135 |
|
| 2136 |
/** Bootstring parameters */ |
| 2137 |
base = 36, |
| 2138 |
tMin = 1, |
| 2139 |
tMax = 26, |
| 2140 |
skew = 38, |
| 2141 |
damp = 700, |
| 2142 |
initialBias = 72, |
| 2143 |
initialN = 128, // 0x80 |
| 2144 |
delimiter = '-', // '\x2D' |
| 2145 |
|
| 2146 |
/** Regular expressions */ |
| 2147 |
regexPunycode = /^xn--/, |
| 2148 |
regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars |
| 2149 |
regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators |
| 2150 |
|
| 2151 |
/** Error messages */ |
| 2152 |
errors = { |
| 2153 |
'overflow': 'Overflow: input needs wider integers to process', |
| 2154 |
'not-basic': 'Illegal input >= 0x80 (not a basic code point)', |
| 2155 |
'invalid-input': 'Invalid input' |
| 2156 |
}, |
| 2157 |
|
| 2158 |
/** Convenience shortcuts */ |
| 2159 |
baseMinusTMin = base - tMin, |
| 2160 |
floor = Math.floor, |
| 2161 |
stringFromCharCode = String.fromCharCode, |
| 2162 |
|
| 2163 |
/** Temporary variable */ |
| 2164 |
key; |
| 2165 |
|
| 2166 |
/*--------------------------------------------------------------------------*/ |
| 2167 |
|
| 2168 |
/** |
| 2169 |
* A generic error utility function. |
| 2170 |
* @private |
| 2171 |
* @param {String} type The error type. |
| 2172 |
* @returns {Error} Throws a `RangeError` with the applicable error message. |
| 2173 |
*/ |
| 2174 |
function error(type) { |
| 2175 |
throw RangeError(errors[type]); |
| 2176 |
} |
| 2177 |
|
| 2178 |
/** |
| 2179 |
* A generic `Array#map` utility function. |
| 2180 |
* @private |
| 2181 |
* @param {Array} array The array to iterate over. |
| 2182 |
* @param {Function} callback The function that gets called for every array |
| 2183 |
* item. |
| 2184 |
* @returns {Array} A new array of values returned by the callback function. |
| 2185 |
*/ |
| 2186 |
function map(array, fn) { |
| 2187 |
var length = array.length; |
| 2188 |
var result = []; |
| 2189 |
while (length--) { |
| 2190 |
result[length] = fn(array[length]); |
| 2191 |
} |
| 2192 |
return result; |
| 2193 |
} |
| 2194 |
|
| 2195 |
/** |
| 2196 |
* A simple `Array#map`-like wrapper to work with domain name strings or email |
| 2197 |
* addresses. |
| 2198 |
* @private |
| 2199 |
* @param {String} domain The domain name or email address. |
| 2200 |
* @param {Function} callback The function that gets called for every |
| 2201 |
* character. |
| 2202 |
* @returns {Array} A new string of characters returned by the callback |
| 2203 |
* function. |
| 2204 |
*/ |
| 2205 |
function mapDomain(string, fn) { |
| 2206 |
var parts = string.split('@'); |
| 2207 |
var result = ''; |
| 2208 |
if (parts.length > 1) { |
| 2209 |
// In email addresses, only the domain name should be punycoded. Leave |
| 2210 |
// the local part (i.e. everything up to `@`) intact. |
| 2211 |
result = parts[0] + '@'; |
| 2212 |
string = parts[1]; |
| 2213 |
} |
| 2214 |
// Avoid `split(regex)` for IE8 compatibility. See #17. |
| 2215 |
string = string.replace(regexSeparators, '\x2E'); |
| 2216 |
var labels = string.split('.'); |
| 2217 |
var encoded = map(labels, fn).join('.'); |
| 2218 |
return result + encoded; |
| 2219 |
} |
| 2220 |
|
| 2221 |
/** |
| 2222 |
* Creates an array containing the numeric code points of each Unicode |
| 2223 |
* character in the string. While JavaScript uses UCS-2 internally, |
| 2224 |
* this function will convert a pair of surrogate halves (each of which |
| 2225 |
* UCS-2 exposes as separate characters) into a single code point, |
| 2226 |
* matching UTF-16. |
| 2227 |
* @see `punycode.ucs2.encode` |
| 2228 |
* @see <https://mathiasbynens.be/notes/javascript-encoding> |
| 2229 |
* @memberOf punycode.ucs2 |
| 2230 |
* @name decode |
| 2231 |
* @param {String} string The Unicode input string (UCS-2). |
| 2232 |
* @returns {Array} The new array of code points. |
| 2233 |
*/ |
| 2234 |
function ucs2decode(string) { |
| 2235 |
var output = [], |
| 2236 |
counter = 0, |
| 2237 |
length = string.length, |
| 2238 |
value, |
| 2239 |
extra; |
| 2240 |
while (counter < length) { |
| 2241 |
value = string.charCodeAt(counter++); |
| 2242 |
if (value >= 0xD800 && value <= 0xDBFF && counter < length) { |
| 2243 |
// high surrogate, and there is a next character |
| 2244 |
extra = string.charCodeAt(counter++); |
| 2245 |
if ((extra & 0xFC00) == 0xDC00) { // low surrogate |
| 2246 |
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); |
| 2247 |
} else { |
| 2248 |
// unmatched surrogate; only append this code unit, in case the next |
| 2249 |
// code unit is the high surrogate of a surrogate pair |
| 2250 |
output.push(value); |
| 2251 |
counter--; |
| 2252 |
} |
| 2253 |
} else { |
| 2254 |
output.push(value); |
| 2255 |
} |
| 2256 |
} |
| 2257 |
return output; |
| 2258 |
} |
| 2259 |
|
| 2260 |
/** |
| 2261 |
* Creates a string based on an array of numeric code points. |
| 2262 |
* @see `punycode.ucs2.decode` |
| 2263 |
* @memberOf punycode.ucs2 |
| 2264 |
* @name encode |
| 2265 |
* @param {Array} codePoints The array of numeric code points. |
| 2266 |
* @returns {String} The new Unicode string (UCS-2). |
| 2267 |
*/ |
| 2268 |
function ucs2encode(array) { |
| 2269 |
return map(array, function(value) { |
| 2270 |
var output = ''; |
| 2271 |
if (value > 0xFFFF) { |
| 2272 |
value -= 0x10000; |
| 2273 |
output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); |
| 2274 |
value = 0xDC00 | value & 0x3FF; |
| 2275 |
} |
| 2276 |
output += stringFromCharCode(value); |
| 2277 |
return output; |
| 2278 |
}).join(''); |
| 2279 |
} |
| 2280 |
|
| 2281 |
/** |
| 2282 |
* Converts a basic code point into a digit/integer. |
| 2283 |
* @see `digitToBasic()` |
| 2284 |
* @private |
| 2285 |
* @param {Number} codePoint The basic numeric code point value. |
| 2286 |
* @returns {Number} The numeric value of a basic code point (for use in |
| 2287 |
* representing integers) in the range `0` to `base - 1`, or `base` if |
| 2288 |
* the code point does not represent a value. |
| 2289 |
*/ |
| 2290 |
function basicToDigit(codePoint) { |
| 2291 |
if (codePoint - 48 < 10) { |
| 2292 |
return codePoint - 22; |
| 2293 |
} |
| 2294 |
if (codePoint - 65 < 26) { |
| 2295 |
return codePoint - 65; |
| 2296 |
} |
| 2297 |
if (codePoint - 97 < 26) { |
| 2298 |
return codePoint - 97; |
| 2299 |
} |
| 2300 |
return base; |
| 2301 |
} |
| 2302 |
|
| 2303 |
/** |
| 2304 |
* Converts a digit/integer into a basic code point. |
| 2305 |
* @see `basicToDigit()` |
| 2306 |
* @private |
| 2307 |
* @param {Number} digit The numeric value of a basic code point. |
| 2308 |
* @returns {Number} The basic code point whose value (when used for |
| 2309 |
* representing integers) is `digit`, which needs to be in the range |
| 2310 |
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is |
| 2311 |
* used; else, the lowercase form is used. The behavior is undefined |
| 2312 |
* if `flag` is non-zero and `digit` has no uppercase form. |
| 2313 |
*/ |
| 2314 |
function digitToBasic(digit, flag) { |
| 2315 |
// 0..25 map to ASCII a..z or A..Z |
| 2316 |
// 26..35 map to ASCII 0..9 |
| 2317 |
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); |
| 2318 |
} |
| 2319 |
|
| 2320 |
/** |
| 2321 |
* Bias adaptation function as per section 3.4 of RFC 3492. |
| 2322 |
* http://tools.ietf.org/html/rfc3492#section-3.4 |
| 2323 |
* @private |
| 2324 |
*/ |
| 2325 |
function adapt(delta, numPoints, firstTime) { |
| 2326 |
var k = 0; |
| 2327 |
delta = firstTime ? floor(delta / damp) : delta >> 1; |
| 2328 |
delta += floor(delta / numPoints); |
| 2329 |
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { |
| 2330 |
delta = floor(delta / baseMinusTMin); |
| 2331 |
} |
| 2332 |
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); |
| 2333 |
} |
| 2334 |
|
| 2335 |
/** |
| 2336 |
* Converts a Punycode string of ASCII-only symbols to a string of Unicode |
| 2337 |
* symbols. |
| 2338 |
* @memberOf punycode |
| 2339 |
* @param {String} input The Punycode string of ASCII-only symbols. |
| 2340 |
* @returns {String} The resulting string of Unicode symbols. |
| 2341 |
*/ |
| 2342 |
function decode(input) { |
| 2343 |
// Don't use UCS-2 |
| 2344 |
var output = [], |
| 2345 |
inputLength = input.length, |
| 2346 |
out, |
| 2347 |
i = 0, |
| 2348 |
n = initialN, |
| 2349 |
bias = initialBias, |
| 2350 |
basic, |
| 2351 |
j, |
| 2352 |
index, |
| 2353 |
oldi, |
| 2354 |
w, |
| 2355 |
k, |
| 2356 |
digit, |
| 2357 |
t, |
| 2358 |
/** Cached calculation results */ |
| 2359 |
baseMinusT; |
| 2360 |
|
| 2361 |
// Handle the basic code points: let `basic` be the number of input code |
| 2362 |
// points before the last delimiter, or `0` if there is none, then copy |
| 2363 |
// the first basic code points to the output. |
| 2364 |
|
| 2365 |
basic = input.lastIndexOf(delimiter); |
| 2366 |
if (basic < 0) { |
| 2367 |
basic = 0; |
| 2368 |
} |
| 2369 |
|
| 2370 |
for (j = 0; j < basic; ++j) { |
| 2371 |
// if it's not a basic code point |
| 2372 |
if (input.charCodeAt(j) >= 0x80) { |
| 2373 |
error('not-basic'); |
| 2374 |
} |
| 2375 |
output.push(input.charCodeAt(j)); |
| 2376 |
} |
| 2377 |
|
| 2378 |
// Main decoding loop: start just after the last delimiter if any basic code |
| 2379 |
// points were copied; start at the beginning otherwise. |
| 2380 |
|
| 2381 |
for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { |
| 2382 |
|
| 2383 |
// `index` is the index of the next character to be consumed. |
| 2384 |
// Decode a generalized variable-length integer into `delta`, |
| 2385 |
// which gets added to `i`. The overflow checking is easier |
| 2386 |
// if we increase `i` as we go, then subtract off its starting |
| 2387 |
// value at the end to obtain `delta`. |
| 2388 |
for (oldi = i, w = 1, k = base; /* no condition */; k += base) { |
| 2389 |
|
| 2390 |
if (index >= inputLength) { |
| 2391 |
error('invalid-input'); |
| 2392 |
} |
| 2393 |
|
| 2394 |
digit = basicToDigit(input.charCodeAt(index++)); |
| 2395 |
|
| 2396 |
if (digit >= base || digit > floor((maxInt - i) / w)) { |
| 2397 |
error('overflow'); |
| 2398 |
} |
| 2399 |
|
| 2400 |
i += digit * w; |
| 2401 |
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); |
| 2402 |
|
| 2403 |
if (digit < t) { |
| 2404 |
break; |
| 2405 |
} |
| 2406 |
|
| 2407 |
baseMinusT = base - t; |
| 2408 |
if (w > floor(maxInt / baseMinusT)) { |
| 2409 |
error('overflow'); |
| 2410 |
} |
| 2411 |
|
| 2412 |
w *= baseMinusT; |
| 2413 |
|
| 2414 |
} |
| 2415 |
|
| 2416 |
out = output.length + 1; |
| 2417 |
bias = adapt(i - oldi, out, oldi == 0); |
| 2418 |
|
| 2419 |
// `i` was supposed to wrap around from `out` to `0`, |
| 2420 |
// incrementing `n` each time, so we'll fix that now: |
| 2421 |
if (floor(i / out) > maxInt - n) { |
| 2422 |
error('overflow'); |
| 2423 |
} |
| 2424 |
|
| 2425 |
n += floor(i / out); |
| 2426 |
i %= out; |
| 2427 |
|
| 2428 |
// Insert `n` at position `i` of the output |
| 2429 |
output.splice(i++, 0, n); |
| 2430 |
|
| 2431 |
} |
| 2432 |
|
| 2433 |
return ucs2encode(output); |
| 2434 |
} |
| 2435 |
|
| 2436 |
/** |
| 2437 |
* Converts a string of Unicode symbols (e.g. a domain name label) to a |
| 2438 |
* Punycode string of ASCII-only symbols. |
| 2439 |
* @memberOf punycode |
| 2440 |
* @param {String} input The string of Unicode symbols. |
| 2441 |
* @returns {String} The resulting Punycode string of ASCII-only symbols. |
| 2442 |
*/ |
| 2443 |
function encode(input) { |
| 2444 |
var n, |
| 2445 |
delta, |
| 2446 |
handledCPCount, |
| 2447 |
basicLength, |
| 2448 |
bias, |
| 2449 |
j, |
| 2450 |
m, |
| 2451 |
q, |
| 2452 |
k, |
| 2453 |
t, |
| 2454 |
currentValue, |
| 2455 |
output = [], |
| 2456 |
/** `inputLength` will hold the number of code points in `input`. */ |
| 2457 |
inputLength, |
| 2458 |
/** Cached calculation results */ |
| 2459 |
handledCPCountPlusOne, |
| 2460 |
baseMinusT, |
| 2461 |
qMinusT; |
| 2462 |
|
| 2463 |
// Convert the input in UCS-2 to Unicode |
| 2464 |
input = ucs2decode(input); |
| 2465 |
|
| 2466 |
// Cache the length |
| 2467 |
inputLength = input.length; |
| 2468 |
|
| 2469 |
// Initialize the state |
| 2470 |
n = initialN; |
| 2471 |
delta = 0; |
| 2472 |
bias = initialBias; |
| 2473 |
|
| 2474 |
// Handle the basic code points |
| 2475 |
for (j = 0; j < inputLength; ++j) { |
| 2476 |
currentValue = input[j]; |
| 2477 |
if (currentValue < 0x80) { |
| 2478 |
output.push(stringFromCharCode(currentValue)); |
| 2479 |
} |
| 2480 |
} |
| 2481 |
|
| 2482 |
handledCPCount = basicLength = output.length; |
| 2483 |
|
| 2484 |
// `handledCPCount` is the number of code points that have been handled; |
| 2485 |
// `basicLength` is the number of basic code points. |
| 2486 |
|
| 2487 |
// Finish the basic string - if it is not empty - with a delimiter |
| 2488 |
if (basicLength) { |
| 2489 |
output.push(delimiter); |
| 2490 |
} |
| 2491 |
|
| 2492 |
// Main encoding loop: |
| 2493 |
while (handledCPCount < inputLength) { |
| 2494 |
|
| 2495 |
// All non-basic code points < n have been handled already. Find the next |
| 2496 |
// larger one: |
| 2497 |
for (m = maxInt, j = 0; j < inputLength; ++j) { |
| 2498 |
currentValue = input[j]; |
| 2499 |
if (currentValue >= n && currentValue < m) { |
| 2500 |
m = currentValue; |
| 2501 |
} |
| 2502 |
} |
| 2503 |
|
| 2504 |
// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>, |
| 2505 |
// but guard against overflow |
| 2506 |
handledCPCountPlusOne = handledCPCount + 1; |
| 2507 |
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { |
| 2508 |
error('overflow'); |
| 2509 |
} |
| 2510 |
|
| 2511 |
delta += (m - n) * handledCPCountPlusOne; |
| 2512 |
n = m; |
| 2513 |
|
| 2514 |
for (j = 0; j < inputLength; ++j) { |
| 2515 |
currentValue = input[j]; |
| 2516 |
|
| 2517 |
if (currentValue < n && ++delta > maxInt) { |
| 2518 |
error('overflow'); |
| 2519 |
} |
| 2520 |
|
| 2521 |
if (currentValue == n) { |
| 2522 |
// Represent delta as a generalized variable-length integer |
| 2523 |
for (q = delta, k = base; /* no condition */; k += base) { |
| 2524 |
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); |
| 2525 |
if (q < t) { |
| 2526 |
break; |
| 2527 |
} |
| 2528 |
qMinusT = q - t; |
| 2529 |
baseMinusT = base - t; |
| 2530 |
output.push( |
| 2531 |
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) |
| 2532 |
); |
| 2533 |
q = floor(qMinusT / baseMinusT); |
| 2534 |
} |
| 2535 |
|
| 2536 |
output.push(stringFromCharCode(digitToBasic(q, 0))); |
| 2537 |
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); |
| 2538 |
delta = 0; |
| 2539 |
++handledCPCount; |
| 2540 |
} |
| 2541 |
} |
| 2542 |
|
| 2543 |
++delta; |
| 2544 |
++n; |
| 2545 |
|
| 2546 |
} |
| 2547 |
return output.join(''); |
| 2548 |
} |
| 2549 |
|
| 2550 |
/** |
| 2551 |
* Converts a Punycode string representing a domain name or an email address |
| 2552 |
* to Unicode. Only the Punycoded parts of the input will be converted, i.e. |
| 2553 |
* it doesn't matter if you call it on a string that has already been |
| 2554 |
* converted to Unicode. |
| 2555 |
* @memberOf punycode |
| 2556 |
* @param {String} input The Punycoded domain name or email address to |
| 2557 |
* convert to Unicode. |
| 2558 |
* @returns {String} The Unicode representation of the given Punycode |
| 2559 |
* string. |
| 2560 |
*/ |
| 2561 |
function toUnicode(input) { |
| 2562 |
return mapDomain(input, function(string) { |
| 2563 |
return regexPunycode.test(string) |
| 2564 |
? decode(string.slice(4).toLowerCase()) |
| 2565 |
: string; |
| 2566 |
}); |
| 2567 |
} |
| 2568 |
|
| 2569 |
/** |
| 2570 |
* Converts a Unicode string representing a domain name or an email address to |
| 2571 |
* Punycode. Only the non-ASCII parts of the domain name will be converted, |
| 2572 |
* i.e. it doesn't matter if you call it with a domain that's already in |
| 2573 |
* ASCII. |
| 2574 |
* @memberOf punycode |
| 2575 |
* @param {String} input The domain name or email address to convert, as a |
| 2576 |
* Unicode string. |
| 2577 |
* @returns {String} The Punycode representation of the given domain name or |
| 2578 |
* email address. |
| 2579 |
*/ |
| 2580 |
function toASCII(input) { |
| 2581 |
return mapDomain(input, function(string) { |
| 2582 |
return regexNonASCII.test(string) |
| 2583 |
? 'xn--' + encode(string) |
| 2584 |
: string; |
| 2585 |
}); |
| 2586 |
} |
| 2587 |
|
| 2588 |
/*--------------------------------------------------------------------------*/ |
| 2589 |
|
| 2590 |
/** Define the public API */ |
| 2591 |
punycode = { |
| 2592 |
/** |
| 2593 |
* A string representing the current Punycode.js version number. |
| 2594 |
* @memberOf punycode |
| 2595 |
* @type String |
| 2596 |
*/ |
| 2597 |
'version': '1.3.2', |
| 2598 |
/** |
| 2599 |
* An object of methods to convert from JavaScript's internal character |
| 2600 |
* representation (UCS-2) to Unicode code points, and back. |
| 2601 |
* @see <https://mathiasbynens.be/notes/javascript-encoding> |
| 2602 |
* @memberOf punycode |
| 2603 |
* @type Object |
| 2604 |
*/ |
| 2605 |
'ucs2': { |
| 2606 |
'decode': ucs2decode, |
| 2607 |
'encode': ucs2encode |
| 2608 |
}, |
| 2609 |
'decode': decode, |
| 2610 |
'encode': encode, |
| 2611 |
'toASCII': toASCII, |
| 2612 |
'toUnicode': toUnicode |
| 2613 |
}; |
| 2614 |
|
| 2615 |
/** Expose `punycode` */ |
| 2616 |
// Some AMD build optimizers, like r.js, check for specific condition patterns |
| 2617 |
// like the following: |
| 2618 |
if ( |
| 2619 |
true |
| 2620 |
) { |
| 2621 |
!(__WEBPACK_AMD_DEFINE_RESULT__ = function() { |
| 2622 |
return punycode; |
| 2623 |
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); |
| 2624 |
} else if (freeExports && freeModule) { |
| 2625 |
if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+ |
| 2626 |
freeModule.exports = punycode; |
| 2627 |
} else { // in Narwhal or RingoJS v0.7.0- |
| 2628 |
for (key in punycode) { |
| 2629 |
punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); |
| 2630 |
} |
| 2631 |
} |
| 2632 |
} else { // in Rhino or a web browser |
| 2633 |
root.punycode = punycode; |
| 2634 |
} |
| 2635 |
|
| 2636 |
}(this)); |
| 2637 |
|
| 2638 |
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(6)(module), (function() { return this; }()))) |
| 2639 |
|
| 2640 |
/***/ }, |
| 2641 |
/* 6 */ |
| 2642 |
/***/ function(module, exports) { |
| 2643 |
|
| 2644 |
module.exports = function(module) { |
| 2645 |
if(!module.webpackPolyfill) { |
| 2646 |
module.deprecate = function() {}; |
| 2647 |
module.paths = []; |
| 2648 |
// module.parent = undefined by default |
| 2649 |
module.children = []; |
| 2650 |
module.webpackPolyfill = 1; |
| 2651 |
} |
| 2652 |
return module; |
| 2653 |
} |
| 2654 |
|
| 2655 |
|
| 2656 |
/***/ }, |
| 2657 |
/* 7 */ |
| 2658 |
/***/ function(module, exports, __webpack_require__) { |
| 2659 |
|
| 2660 |
'use strict'; |
| 2661 |
|
| 2662 |
exports.decode = exports.parse = __webpack_require__(8); |
| 2663 |
exports.encode = exports.stringify = __webpack_require__(9); |
| 2664 |
|
| 2665 |
|
| 2666 |
/***/ }, |
| 2667 |
/* 8 */ |
| 2668 |
/***/ function(module, exports) { |
| 2669 |
|
| 2670 |
// Copyright Joyent, Inc. and other Node contributors. |
| 2671 |
// |
| 2672 |
// Permission is hereby granted, free of charge, to any person obtaining a |
| 2673 |
// copy of this software and associated documentation files (the |
| 2674 |
// "Software"), to deal in the Software without restriction, including |
| 2675 |
// without limitation the rights to use, copy, modify, merge, publish, |
| 2676 |
// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 2677 |
// persons to whom the Software is furnished to do so, subject to the |
| 2678 |
// following conditions: |
| 2679 |
// |
| 2680 |
// The above copyright notice and this permission notice shall be included |
| 2681 |
// in all copies or substantial portions of the Software. |
| 2682 |
// |
| 2683 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 2684 |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 2685 |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 2686 |
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 2687 |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 2688 |
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 2689 |
// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 2690 |
|
| 2691 |
'use strict'; |
| 2692 |
|
| 2693 |
// If obj.hasOwnProperty has been overridden, then calling |
| 2694 |
// obj.hasOwnProperty(prop) will break. |
| 2695 |
// See: https://github.com/joyent/node/issues/1707 |
| 2696 |
function hasOwnProperty(obj, prop) { |
| 2697 |
return Object.prototype.hasOwnProperty.call(obj, prop); |
| 2698 |
} |
| 2699 |
|
| 2700 |
module.exports = function(qs, sep, eq, options) { |
| 2701 |
sep = sep || '&'; |
| 2702 |
eq = eq || '='; |
| 2703 |
var obj = {}; |
| 2704 |
|
| 2705 |
if (typeof qs !== 'string' || qs.length === 0) { |
| 2706 |
return obj; |
| 2707 |
} |
| 2708 |
|
| 2709 |
var regexp = /\+/g; |
| 2710 |
qs = qs.split(sep); |
| 2711 |
|
| 2712 |
var maxKeys = 1000; |
| 2713 |
if (options && typeof options.maxKeys === 'number') { |
| 2714 |
maxKeys = options.maxKeys; |
| 2715 |
} |
| 2716 |
|
| 2717 |
var len = qs.length; |
| 2718 |
// maxKeys <= 0 means that we should not limit keys count |
| 2719 |
if (maxKeys > 0 && len > maxKeys) { |
| 2720 |
len = maxKeys; |
| 2721 |
} |
| 2722 |
|
| 2723 |
for (var i = 0; i < len; ++i) { |
| 2724 |
var x = qs[i].replace(regexp, '%20'), |
| 2725 |
idx = x.indexOf(eq), |
| 2726 |
kstr, vstr, k, v; |
| 2727 |
|
| 2728 |
if (idx >= 0) { |
| 2729 |
kstr = x.substr(0, idx); |
| 2730 |
vstr = x.substr(idx + 1); |
| 2731 |
} else { |
| 2732 |
kstr = x; |
| 2733 |
vstr = ''; |
| 2734 |
} |
| 2735 |
|
| 2736 |
k = decodeURIComponent(kstr); |
| 2737 |
v = decodeURIComponent(vstr); |
| 2738 |
|
| 2739 |
if (!hasOwnProperty(obj, k)) { |
| 2740 |
obj[k] = v; |
| 2741 |
} else if (Array.isArray(obj[k])) { |
| 2742 |
obj[k].push(v); |
| 2743 |
} else { |
| 2744 |
obj[k] = [obj[k], v]; |
| 2745 |
} |
| 2746 |
} |
| 2747 |
|
| 2748 |
return obj; |
| 2749 |
}; |
| 2750 |
|
| 2751 |
|
| 2752 |
/***/ }, |
| 2753 |
/* 9 */ |
| 2754 |
/***/ function(module, exports) { |
| 2755 |
|
| 2756 |
// Copyright Joyent, Inc. and other Node contributors. |
| 2757 |
// |
| 2758 |
// Permission is hereby granted, free of charge, to any person obtaining a |
| 2759 |
// copy of this software and associated documentation files (the |
| 2760 |
// "Software"), to deal in the Software without restriction, including |
| 2761 |
// without limitation the rights to use, copy, modify, merge, publish, |
| 2762 |
// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 2763 |
// persons to whom the Software is furnished to do so, subject to the |
| 2764 |
// following conditions: |
| 2765 |
// |
| 2766 |
// The above copyright notice and this permission notice shall be included |
| 2767 |
// in all copies or substantial portions of the Software. |
| 2768 |
// |
| 2769 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 2770 |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 2771 |
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 2772 |
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 2773 |
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 2774 |
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 2775 |
// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 2776 |
|
| 2777 |
'use strict'; |
| 2778 |
|
| 2779 |
var stringifyPrimitive = function(v) { |
| 2780 |
switch (typeof v) { |
| 2781 |
case 'string': |
| 2782 |
return v; |
| 2783 |
|
| 2784 |
case 'boolean': |
| 2785 |
return v ? 'true' : 'false'; |
| 2786 |
|
| 2787 |
case 'number': |
| 2788 |
return isFinite(v) ? v : ''; |
| 2789 |
|
| 2790 |
default: |
| 2791 |
return ''; |
| 2792 |
} |
| 2793 |
}; |
| 2794 |
|
| 2795 |
module.exports = function(obj, sep, eq, name) { |
| 2796 |
sep = sep || '&'; |
| 2797 |
eq = eq || '='; |
| 2798 |
if (obj === null) { |
| 2799 |
obj = undefined; |
| 2800 |
} |
| 2801 |
|
| 2802 |
if (typeof obj === 'object') { |
| 2803 |
return Object.keys(obj).map(function(k) { |
| 2804 |
var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; |
| 2805 |
if (Array.isArray(obj[k])) { |
| 2806 |
return obj[k].map(function(v) { |
| 2807 |
return ks + encodeURIComponent(stringifyPrimitive(v)); |
| 2808 |
}).join(sep); |
| 2809 |
} else { |
| 2810 |
return ks + encodeURIComponent(stringifyPrimitive(obj[k])); |
| 2811 |
} |
| 2812 |
}).join(sep); |
| 2813 |
|
| 2814 |
} |
| 2815 |
|
| 2816 |
if (!name) return ''; |
| 2817 |
return encodeURIComponent(stringifyPrimitive(name)) + eq + |
| 2818 |
encodeURIComponent(stringifyPrimitive(obj)); |
| 2819 |
}; |
| 2820 |
|
| 2821 |
|
| 2822 |
/***/ }, |
| 2823 |
/* 10 */ |
| 2824 |
/***/ function(module, exports) { |
| 2825 |
|
| 2826 |
'use strict'; |
| 2827 |
|
| 2828 |
module.exports = function equal(a, b) { |
| 2829 |
if (a === b) return true; |
| 2830 |
|
| 2831 |
var arrA = Array.isArray(a) |
| 2832 |
, arrB = Array.isArray(b) |
| 2833 |
, i; |
| 2834 |
|
| 2835 |
if (arrA && arrB) { |
| 2836 |
if (a.length != b.length) return false; |
| 2837 |
for (i = 0; i < a.length; i++) |
| 2838 |
if (!equal(a[i], b[i])) return false; |
| 2839 |
return true; |
| 2840 |
} |
| 2841 |
|
| 2842 |
if (arrA != arrB) return false; |
| 2843 |
|
| 2844 |
if (a && b && typeof a === 'object' && typeof b === 'object') { |
| 2845 |
var keys = Object.keys(a); |
| 2846 |
|
| 2847 |
if (keys.length !== Object.keys(b).length) return false; |
| 2848 |
|
| 2849 |
for (i = 0; i < keys.length; i++) |
| 2850 |
if (b[keys[i]] === undefined) return false; |
| 2851 |
|
| 2852 |
for (i = 0; i < keys.length; i++) |
| 2853 |
if(!equal(a[keys[i]], b[keys[i]])) return false; |
| 2854 |
|
| 2855 |
return true; |
| 2856 |
} |
| 2857 |
|
| 2858 |
return false; |
| 2859 |
}; |
| 2860 |
|
| 2861 |
|
| 2862 |
/***/ }, |
| 2863 |
/* 11 */ |
| 2864 |
/***/ function(module, exports, __webpack_require__) { |
| 2865 |
|
| 2866 |
'use strict'; |
| 2867 |
|
| 2868 |
|
| 2869 |
module.exports = { |
| 2870 |
copy: copy, |
| 2871 |
checkDataType: checkDataType, |
| 2872 |
checkDataTypes: checkDataTypes, |
| 2873 |
coerceToTypes: coerceToTypes, |
| 2874 |
toHash: toHash, |
| 2875 |
getProperty: getProperty, |
| 2876 |
escapeQuotes: escapeQuotes, |
| 2877 |
ucs2length: ucs2length, |
| 2878 |
varOccurences: varOccurences, |
| 2879 |
varReplace: varReplace, |
| 2880 |
cleanUpCode: cleanUpCode, |
| 2881 |
cleanUpVarErrors: cleanUpVarErrors, |
| 2882 |
schemaHasRules: schemaHasRules, |
| 2883 |
stableStringify: __webpack_require__(12), |
| 2884 |
toQuotedString: toQuotedString, |
| 2885 |
getPathExpr: getPathExpr, |
| 2886 |
getPath: getPath, |
| 2887 |
getData: getData, |
| 2888 |
unescapeFragment: unescapeFragment, |
| 2889 |
escapeFragment: escapeFragment, |
| 2890 |
escapeJsonPointer: escapeJsonPointer |
| 2891 |
}; |
| 2892 |
|
| 2893 |
|
| 2894 |
function copy(o, to) { |
| 2895 |
to = to || {}; |
| 2896 |
for (var key in o) to[key] = o[key]; |
| 2897 |
return to; |
| 2898 |
} |
| 2899 |
|
| 2900 |
|
| 2901 |
function checkDataType(dataType, data, negate) { |
| 2902 |
var EQUAL = negate ? ' !== ' : ' === ' |
| 2903 |
, AND = negate ? ' || ' : ' && ' |
| 2904 |
, OK = negate ? '!' : '' |
| 2905 |
, NOT = negate ? '' : '!'; |
| 2906 |
switch (dataType) { |
| 2907 |
case 'null': return data + EQUAL + 'null'; |
| 2908 |
case 'array': return OK + 'Array.isArray(' + data + ')'; |
| 2909 |
case 'object': return '(' + OK + data + AND + |
| 2910 |
'typeof ' + data + EQUAL + '"object"' + AND + |
| 2911 |
NOT + 'Array.isArray(' + data + '))'; |
| 2912 |
case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND + |
| 2913 |
NOT + '(' + data + ' % 1))'; |
| 2914 |
default: return 'typeof ' + data + EQUAL + '"' + dataType + '"'; |
| 2915 |
} |
| 2916 |
} |
| 2917 |
|
| 2918 |
|
| 2919 |
function checkDataTypes(dataTypes, data) { |
| 2920 |
switch (dataTypes.length) { |
| 2921 |
case 1: return checkDataType(dataTypes[0], data, true); |
| 2922 |
default: |
| 2923 |
var code = ''; |
| 2924 |
var types = toHash(dataTypes); |
| 2925 |
if (types.array && types.object) { |
| 2926 |
code = types.null ? '(': '(!' + data + ' || '; |
| 2927 |
code += 'typeof ' + data + ' !== "object")'; |
| 2928 |
delete types.null; |
| 2929 |
delete types.array; |
| 2930 |
delete types.object; |
| 2931 |
} |
| 2932 |
if (types.number) delete types.integer; |
| 2933 |
for (var t in types) |
| 2934 |
code += (code ? ' && ' : '' ) + checkDataType(t, data, true); |
| 2935 |
|
| 2936 |
return code; |
| 2937 |
} |
| 2938 |
} |
| 2939 |
|
| 2940 |
|
| 2941 |
var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]); |
| 2942 |
function coerceToTypes(dataTypes) { |
| 2943 |
if (Array.isArray(dataTypes)) { |
| 2944 |
var types = []; |
| 2945 |
for (var i=0; i<dataTypes.length; i++) { |
| 2946 |
var t = dataTypes[i]; |
| 2947 |
if (COERCE_TO_TYPES[t]) types[types.length] = t; |
| 2948 |
} |
| 2949 |
if (types.length) return types; |
| 2950 |
} else if (COERCE_TO_TYPES[dataTypes]) { |
| 2951 |
return [dataTypes]; |
| 2952 |
} |
| 2953 |
} |
| 2954 |
|
| 2955 |
|
| 2956 |
function toHash(arr) { |
| 2957 |
var hash = {}; |
| 2958 |
for (var i=0; i<arr.length; i++) hash[arr[i]] = true; |
| 2959 |
return hash; |
| 2960 |
} |
| 2961 |
|
| 2962 |
|
| 2963 |
var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i; |
| 2964 |
var SINGLE_QUOTE = /'|\\/g; |
| 2965 |
function getProperty(key) { |
| 2966 |
return typeof key == 'number' |
| 2967 |
? '[' + key + ']' |
| 2968 |
: IDENTIFIER.test(key) |
| 2969 |
? '.' + key |
| 2970 |
: "['" + key.replace(SINGLE_QUOTE, '\\$&') + "']"; |
| 2971 |
} |
| 2972 |
|
| 2973 |
|
| 2974 |
function escapeQuotes(str) { |
| 2975 |
return str.replace(SINGLE_QUOTE, '\\$&'); |
| 2976 |
} |
| 2977 |
|
| 2978 |
|
| 2979 |
// https://mathiasbynens.be/notes/javascript-encoding |
| 2980 |
// https://github.com/bestiejs/punycode.js - punycode.ucs2.decode |
| 2981 |
function ucs2length(str) { |
| 2982 |
var length = 0 |
| 2983 |
, len = str.length |
| 2984 |
, pos = 0 |
| 2985 |
, value; |
| 2986 |
while (pos < len) { |
| 2987 |
length++; |
| 2988 |
value = str.charCodeAt(pos++); |
| 2989 |
if (value >= 0xD800 && value <= 0xDBFF && pos < len) { |
| 2990 |
// high surrogate, and there is a next character |
| 2991 |
value = str.charCodeAt(pos); |
| 2992 |
if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate |
| 2993 |
} |
| 2994 |
} |
| 2995 |
return length; |
| 2996 |
} |
| 2997 |
|
| 2998 |
|
| 2999 |
function varOccurences(str, dataVar) { |
| 3000 |
dataVar += '[^0-9]'; |
| 3001 |
var matches = str.match(new RegExp(dataVar, 'g')); |
| 3002 |
return matches ? matches.length : 0; |
| 3003 |
} |
| 3004 |
|
| 3005 |
|
| 3006 |
function varReplace(str, dataVar, expr) { |
| 3007 |
dataVar += '([^0-9])'; |
| 3008 |
expr = expr.replace(/\$/g, '$$$$'); |
| 3009 |
return str.replace(new RegExp(dataVar, 'g'), expr + '$1'); |
| 3010 |
} |
| 3011 |
|
| 3012 |
|
| 3013 |
var EMPTY_ELSE = /else\s*{\s*}/g |
| 3014 |
, EMPTY_IF_NO_ELSE = /if\s*\([^)]+\)\s*\{\s*\}(?!\s*else)/g |
| 3015 |
, EMPTY_IF_WITH_ELSE = /if\s*\(([^)]+)\)\s*\{\s*\}\s*else(?!\s*if)/g; |
| 3016 |
function cleanUpCode(out) { |
| 3017 |
return out.replace(EMPTY_ELSE, '') |
| 3018 |
.replace(EMPTY_IF_NO_ELSE, '') |
| 3019 |
.replace(EMPTY_IF_WITH_ELSE, 'if (!($1))'); |
| 3020 |
} |
| 3021 |
|
| 3022 |
|
| 3023 |
var ERRORS_REGEXP = /[^v\.]errors/g |
| 3024 |
, REMOVE_ERRORS = /var errors = 0;|var vErrors = null;|validate.errors = vErrors;/g |
| 3025 |
, REMOVE_ERRORS_ASYNC = /var errors = 0;|var vErrors = null;/g |
| 3026 |
, RETURN_VALID = 'return errors === 0;' |
| 3027 |
, RETURN_TRUE = 'validate.errors = null; return true;' |
| 3028 |
, RETURN_ASYNC = /if \(errors === 0\) return true;\s*else throw new ValidationError\(vErrors\);/ |
| 3029 |
, RETURN_TRUE_ASYNC = 'return true;'; |
| 3030 |
|
| 3031 |
function cleanUpVarErrors(out, async) { |
| 3032 |
var matches = out.match(ERRORS_REGEXP); |
| 3033 |
if (!matches || matches.length !== 2) return out; |
| 3034 |
return async |
| 3035 |
? out.replace(REMOVE_ERRORS_ASYNC, '') |
| 3036 |
.replace(RETURN_ASYNC, RETURN_TRUE_ASYNC) |
| 3037 |
: out.replace(REMOVE_ERRORS, '') |
| 3038 |
.replace(RETURN_VALID, RETURN_TRUE); |
| 3039 |
} |
| 3040 |
|
| 3041 |
|
| 3042 |
function schemaHasRules(schema, rules) { |
| 3043 |
for (var key in schema) if (rules[key]) return true; |
| 3044 |
} |
| 3045 |
|
| 3046 |
|
| 3047 |
function toQuotedString(str) { |
| 3048 |
return '\'' + escapeQuotes(str) + '\''; |
| 3049 |
} |
| 3050 |
|
| 3051 |
|
| 3052 |
function getPathExpr(currentPath, expr, jsonPointers, isNumber) { |
| 3053 |
var path = jsonPointers // false by default |
| 3054 |
? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')') |
| 3055 |
: (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\''); |
| 3056 |
return joinPaths(currentPath, path); |
| 3057 |
} |
| 3058 |
|
| 3059 |
|
| 3060 |
function getPath(currentPath, prop, jsonPointers) { |
| 3061 |
var path = jsonPointers // false by default |
| 3062 |
? toQuotedString('/' + escapeJsonPointer(prop)) |
| 3063 |
: toQuotedString(getProperty(prop)); |
| 3064 |
return joinPaths(currentPath, path); |
| 3065 |
} |
| 3066 |
|
| 3067 |
|
| 3068 |
var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/; |
| 3069 |
function getData($data, lvl, paths) { |
| 3070 |
var matches = $data.match(RELATIVE_JSON_POINTER); |
| 3071 |
if (!matches) throw new Error('Invalid relative JSON-pointer: ' + $data); |
| 3072 |
var up = +matches[1]; |
| 3073 |
var jsonPointer = matches[2]; |
| 3074 |
if (jsonPointer == '#') { |
| 3075 |
if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl); |
| 3076 |
return paths[lvl - up]; |
| 3077 |
} |
| 3078 |
|
| 3079 |
if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl); |
| 3080 |
var data = 'data' + ((lvl - up) || ''); |
| 3081 |
if (!jsonPointer) return data; |
| 3082 |
|
| 3083 |
var expr = data; |
| 3084 |
var segments = jsonPointer.split('/'); |
| 3085 |
for (var i=0; i<segments.length; i++) { |
| 3086 |
var segment = segments[i]; |
| 3087 |
if (segment) { |
| 3088 |
data += getProperty(unescapeJsonPointer(segment)); |
| 3089 |
expr += ' && ' + data; |
| 3090 |
} |
| 3091 |
} |
| 3092 |
return expr; |
| 3093 |
} |
| 3094 |
|
| 3095 |
|
| 3096 |
function joinPaths (a, b) { |
| 3097 |
if (a == '""') return b; |
| 3098 |
return (a + ' + ' + b).replace(/' \+ '/g, ''); |
| 3099 |
} |
| 3100 |
|
| 3101 |
|
| 3102 |
function unescapeFragment(str) { |
| 3103 |
return unescapeJsonPointer(decodeURIComponent(str)); |
| 3104 |
} |
| 3105 |
|
| 3106 |
|
| 3107 |
function escapeFragment(str) { |
| 3108 |
return encodeURIComponent(escapeJsonPointer(str)); |
| 3109 |
} |
| 3110 |
|
| 3111 |
|
| 3112 |
function escapeJsonPointer(str) { |
| 3113 |
return str.replace(/~/g, '~0').replace(/\//g, '~1'); |
| 3114 |
} |
| 3115 |
|
| 3116 |
|
| 3117 |
function unescapeJsonPointer(str) { |
| 3118 |
return str.replace(/~1/g, '/').replace(/~0/g, '~'); |
| 3119 |
} |
| 3120 |
|
| 3121 |
|
| 3122 |
/***/ }, |
| 3123 |
/* 12 */ |
| 3124 |
/***/ function(module, exports, __webpack_require__) { |
| 3125 |
|
| 3126 |
var json = typeof JSON !== 'undefined' ? JSON : __webpack_require__(13); |
| 3127 |
|
| 3128 |
module.exports = function (obj, opts) { |
| 3129 |
if (!opts) opts = {}; |
| 3130 |
if (typeof opts === 'function') opts = { cmp: opts }; |
| 3131 |
var space = opts.space || ''; |
| 3132 |
if (typeof space === 'number') space = Array(space+1).join(' '); |
| 3133 |
var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false; |
| 3134 |
var replacer = opts.replacer || function(key, value) { return value; }; |
| 3135 |
|
| 3136 |
var cmp = opts.cmp && (function (f) { |
| 3137 |
return function (node) { |
| 3138 |
return function (a, b) { |
| 3139 |
var aobj = { key: a, value: node[a] }; |
| 3140 |
var bobj = { key: b, value: node[b] }; |
| 3141 |
return f(aobj, bobj); |
| 3142 |
}; |
| 3143 |
}; |
| 3144 |
})(opts.cmp); |
| 3145 |
|
| 3146 |
var seen = []; |
| 3147 |
return (function stringify (parent, key, node, level) { |
| 3148 |
var indent = space ? ('\n' + new Array(level + 1).join(space)) : ''; |
| 3149 |
var colonSeparator = space ? ': ' : ':'; |
| 3150 |
|
| 3151 |
if (node && node.toJSON && typeof node.toJSON === 'function') { |
| 3152 |
node = node.toJSON(); |
| 3153 |
} |
| 3154 |
|
| 3155 |
node = replacer.call(parent, key, node); |
| 3156 |
|
| 3157 |
if (node === undefined) { |
| 3158 |
return; |
| 3159 |
} |
| 3160 |
if (typeof node !== 'object' || node === null) { |
| 3161 |
return json.stringify(node); |
| 3162 |
} |
| 3163 |
if (isArray(node)) { |
| 3164 |
var out = []; |
| 3165 |
for (var i = 0; i < node.length; i++) { |
| 3166 |
var item = stringify(node, i, node[i], level+1) || json.stringify(null); |
| 3167 |
out.push(indent + space + item); |
| 3168 |
} |
| 3169 |
return '[' + out.join(',') + indent + ']'; |
| 3170 |
} |
| 3171 |
else { |
| 3172 |
if (seen.indexOf(node) !== -1) { |
| 3173 |
if (cycles) return json.stringify('__cycle__'); |
| 3174 |
throw new TypeError('Converting circular structure to JSON'); |
| 3175 |
} |
| 3176 |
else seen.push(node); |
| 3177 |
|
| 3178 |
var keys = objectKeys(node).sort(cmp && cmp(node)); |
| 3179 |
var out = []; |
| 3180 |
for (var i = 0; i < keys.length; i++) { |
| 3181 |
var key = keys[i]; |
| 3182 |
var value = stringify(node, key, node[key], level+1); |
| 3183 |
|
| 3184 |
if(!value) continue; |
| 3185 |
|
| 3186 |
var keyValue = json.stringify(key) |
| 3187 |
+ colonSeparator |
| 3188 |
+ value; |
| 3189 |
; |
| 3190 |
out.push(indent + space + keyValue); |
| 3191 |
} |
| 3192 |
seen.splice(seen.indexOf(node), 1); |
| 3193 |
return '{' + out.join(',') + indent + '}'; |
| 3194 |
} |
| 3195 |
})({ '': obj }, '', obj, 0); |
| 3196 |
}; |
| 3197 |
|
| 3198 |
var isArray = Array.isArray || function (x) { |
| 3199 |
return {}.toString.call(x) === '[object Array]'; |
| 3200 |
}; |
| 3201 |
|
| 3202 |
var objectKeys = Object.keys || function (obj) { |
| 3203 |
var has = Object.prototype.hasOwnProperty || function () { return true }; |
| 3204 |
var keys = []; |
| 3205 |
for (var key in obj) { |
| 3206 |
if (has.call(obj, key)) keys.push(key); |
| 3207 |
} |
| 3208 |
return keys; |
| 3209 |
}; |
| 3210 |
|
| 3211 |
|
| 3212 |
/***/ }, |
| 3213 |
/* 13 */ |
| 3214 |
/***/ function(module, exports, __webpack_require__) { |
| 3215 |
|
| 3216 |
exports.parse = __webpack_require__(14); |
| 3217 |
exports.stringify = __webpack_require__(15); |
| 3218 |
|
| 3219 |
|
| 3220 |
/***/ }, |
| 3221 |
/* 14 */ |
| 3222 |
/***/ function(module, exports) { |
| 3223 |
|
| 3224 |
var at, // The index of the current character |
| 3225 |
ch, // The current character |
| 3226 |
escapee = { |
| 3227 |
'"': '"', |
| 3228 |
'\\': '\\', |
| 3229 |
'/': '/', |
| 3230 |
b: '\b', |
| 3231 |
f: '\f', |
| 3232 |
n: '\n', |
| 3233 |
r: '\r', |
| 3234 |
t: '\t' |
| 3235 |
}, |
| 3236 |
text, |
| 3237 |
|
| 3238 |
error = function (m) { |
| 3239 |
// Call error when something is wrong. |
| 3240 |
throw { |
| 3241 |
name: 'SyntaxError', |
| 3242 |
message: m, |
| 3243 |
at: at, |
| 3244 |
text: text |
| 3245 |
}; |
| 3246 |
}, |
| 3247 |
|
| 3248 |
next = function (c) { |
| 3249 |
// If a c parameter is provided, verify that it matches the current character. |
| 3250 |
if (c && c !== ch) { |
| 3251 |
error("Expected '" + c + "' instead of '" + ch + "'"); |
| 3252 |
} |
| 3253 |
|
| 3254 |
// Get the next character. When there are no more characters, |
| 3255 |
// return the empty string. |
| 3256 |
|
| 3257 |
ch = text.charAt(at); |
| 3258 |
at += 1; |
| 3259 |
return ch; |
| 3260 |
}, |
| 3261 |
|
| 3262 |
number = function () { |
| 3263 |
// Parse a number value. |
| 3264 |
var number, |
| 3265 |
string = ''; |
| 3266 |
|
| 3267 |
if (ch === '-') { |
| 3268 |
string = '-'; |
| 3269 |
next('-'); |
| 3270 |
} |
| 3271 |
while (ch >= '0' && ch <= '9') { |
| 3272 |
string += ch; |
| 3273 |
next(); |
| 3274 |
} |
| 3275 |
if (ch === '.') { |
| 3276 |
string += '.'; |
| 3277 |
while (next() && ch >= '0' && ch <= '9') { |
| 3278 |
string += ch; |
| 3279 |
} |
| 3280 |
} |
| 3281 |
if (ch === 'e' || ch === 'E') { |
| 3282 |
string += ch; |
| 3283 |
next(); |
| 3284 |
if (ch === '-' || ch === '+') { |
| 3285 |
string += ch; |
| 3286 |
next(); |
| 3287 |
} |
| 3288 |
while (ch >= '0' && ch <= '9') { |
| 3289 |
string += ch; |
| 3290 |
next(); |
| 3291 |
} |
| 3292 |
} |
| 3293 |
number = +string; |
| 3294 |
if (!isFinite(number)) { |
| 3295 |
error("Bad number"); |
| 3296 |
} else { |
| 3297 |
return number; |
| 3298 |
} |
| 3299 |
}, |
| 3300 |
|
| 3301 |
string = function () { |
| 3302 |
// Parse a string value. |
| 3303 |
var hex, |
| 3304 |
i, |
| 3305 |
string = '', |
| 3306 |
uffff; |
| 3307 |
|
| 3308 |
// When parsing for string values, we must look for " and \ characters. |
| 3309 |
if (ch === '"') { |
| 3310 |
while (next()) { |
| 3311 |
if (ch === '"') { |
| 3312 |
next(); |
| 3313 |
return string; |
| 3314 |
} else if (ch === '\\') { |
| 3315 |
next(); |
| 3316 |
if (ch === 'u') { |
| 3317 |
uffff = 0; |
| 3318 |
for (i = 0; i < 4; i += 1) { |
| 3319 |
hex = parseInt(next(), 16); |
| 3320 |
if (!isFinite(hex)) { |
| 3321 |
break; |
| 3322 |
} |
| 3323 |
uffff = uffff * 16 + hex; |
| 3324 |
} |
| 3325 |
string += String.fromCharCode(uffff); |
| 3326 |
} else if (typeof escapee[ch] === 'string') { |
| 3327 |
string += escapee[ch]; |
| 3328 |
} else { |
| 3329 |
break; |
| 3330 |
} |
| 3331 |
} else { |
| 3332 |
string += ch; |
| 3333 |
} |
| 3334 |
} |
| 3335 |
} |
| 3336 |
error("Bad string"); |
| 3337 |
}, |
| 3338 |
|
| 3339 |
white = function () { |
| 3340 |
|
| 3341 |
// Skip whitespace. |
| 3342 |
|
| 3343 |
while (ch && ch <= ' ') { |
| 3344 |
next(); |
| 3345 |
} |
| 3346 |
}, |
| 3347 |
|
| 3348 |
word = function () { |
| 3349 |
|
| 3350 |
// true, false, or null. |
| 3351 |
|
| 3352 |
switch (ch) { |
| 3353 |
case 't': |
| 3354 |
next('t'); |
| 3355 |
next('r'); |
| 3356 |
next('u'); |
| 3357 |
next('e'); |
| 3358 |
return true; |
| 3359 |
case 'f': |
| 3360 |
next('f'); |
| 3361 |
next('a'); |
| 3362 |
next('l'); |
| 3363 |
next('s'); |
| 3364 |
next('e'); |
| 3365 |
return false; |
| 3366 |
case 'n': |
| 3367 |
next('n'); |
| 3368 |
next('u'); |
| 3369 |
next('l'); |
| 3370 |
next('l'); |
| 3371 |
return null; |
| 3372 |
} |
| 3373 |
error("Unexpected '" + ch + "'"); |
| 3374 |
}, |
| 3375 |
|
| 3376 |
value, // Place holder for the value function. |
| 3377 |
|
| 3378 |
array = function () { |
| 3379 |
|
| 3380 |
// Parse an array value. |
| 3381 |
|
| 3382 |
var array = []; |
| 3383 |
|
| 3384 |
if (ch === '[') { |
| 3385 |
next('['); |
| 3386 |
white(); |
| 3387 |
if (ch === ']') { |
| 3388 |
next(']'); |
| 3389 |
return array; // empty array |
| 3390 |
} |
| 3391 |
while (ch) { |
| 3392 |
array.push(value()); |
| 3393 |
white(); |
| 3394 |
if (ch === ']') { |
| 3395 |
next(']'); |
| 3396 |
return array; |
| 3397 |
} |
| 3398 |
next(','); |
| 3399 |
white(); |
| 3400 |
} |
| 3401 |
} |
| 3402 |
error("Bad array"); |
| 3403 |
}, |
| 3404 |
|
| 3405 |
object = function () { |
| 3406 |
|
| 3407 |
// Parse an object value. |
| 3408 |
|
| 3409 |
var key, |
| 3410 |
object = {}; |
| 3411 |
|
| 3412 |
if (ch === '{') { |
| 3413 |
next('{'); |
| 3414 |
white(); |
| 3415 |
if (ch === '}') { |
| 3416 |
next('}'); |
| 3417 |
return object; // empty object |
| 3418 |
} |
| 3419 |
while (ch) { |
| 3420 |
key = string(); |
| 3421 |
white(); |
| 3422 |
next(':'); |
| 3423 |
if (Object.hasOwnProperty.call(object, key)) { |
| 3424 |
error('Duplicate key "' + key + '"'); |
| 3425 |
} |
| 3426 |
object[key] = value(); |
| 3427 |
white(); |
| 3428 |
if (ch === '}') { |
| 3429 |
next('}'); |
| 3430 |
return object; |
| 3431 |
} |
| 3432 |
next(','); |
| 3433 |
white(); |
| 3434 |
} |
| 3435 |
} |
| 3436 |
error("Bad object"); |
| 3437 |
}; |
| 3438 |
|
| 3439 |
value = function () { |
| 3440 |
|
| 3441 |
// Parse a JSON value. It could be an object, an array, a string, a number, |
| 3442 |
// or a word. |
| 3443 |
|
| 3444 |
white(); |
| 3445 |
switch (ch) { |
| 3446 |
case '{': |
| 3447 |
return object(); |
| 3448 |
case '[': |
| 3449 |
return array(); |
| 3450 |
case '"': |
| 3451 |
return string(); |
| 3452 |
case '-': |
| 3453 |
return number(); |
| 3454 |
default: |
| 3455 |
return ch >= '0' && ch <= '9' ? number() : word(); |
| 3456 |
} |
| 3457 |
}; |
| 3458 |
|
| 3459 |
// Return the json_parse function. It will have access to all of the above |
| 3460 |
// functions and variables. |
| 3461 |
|
| 3462 |
module.exports = function (source, reviver) { |
| 3463 |
var result; |
| 3464 |
|
| 3465 |
text = source; |
| 3466 |
at = 0; |
| 3467 |
ch = ' '; |
| 3468 |
result = value(); |
| 3469 |
white(); |
| 3470 |
if (ch) { |
| 3471 |
error("Syntax error"); |
| 3472 |
} |
| 3473 |
|
| 3474 |
// If there is a reviver function, we recursively walk the new structure, |
| 3475 |
// passing each name/value pair to the reviver function for possible |
| 3476 |
// transformation, starting with a temporary root object that holds the result |
| 3477 |
// in an empty key. If there is not a reviver function, we simply return the |
| 3478 |
// result. |
| 3479 |
|
| 3480 |
return typeof reviver === 'function' ? (function walk(holder, key) { |
| 3481 |
var k, v, value = holder[key]; |
| 3482 |
if (value && typeof value === 'object') { |
| 3483 |
for (k in value) { |
| 3484 |
if (Object.prototype.hasOwnProperty.call(value, k)) { |
| 3485 |
v = walk(value, k); |
| 3486 |
if (v !== undefined) { |
| 3487 |
value[k] = v; |
| 3488 |
} else { |
| 3489 |
delete value[k]; |
| 3490 |
} |
| 3491 |
} |
| 3492 |
} |
| 3493 |
} |
| 3494 |
return reviver.call(holder, key, value); |
| 3495 |
}({'': result}, '')) : result; |
| 3496 |
}; |
| 3497 |
|
| 3498 |
|
| 3499 |
/***/ }, |
| 3500 |
/* 15 */ |
| 3501 |
/***/ function(module, exports) { |
| 3502 |
|
| 3503 |
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, |
| 3504 |
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, |
| 3505 |
gap, |
| 3506 |
indent, |
| 3507 |
meta = { // table of character substitutions |
| 3508 |
'\b': '\\b', |
| 3509 |
'\t': '\\t', |
| 3510 |
'\n': '\\n', |
| 3511 |
'\f': '\\f', |
| 3512 |
'\r': '\\r', |
| 3513 |
'"' : '\\"', |
| 3514 |
'\\': '\\\\' |
| 3515 |
}, |
| 3516 |
rep; |
| 3517 |
|
| 3518 |
function quote(string) { |
| 3519 |
// If the string contains no control characters, no quote characters, and no |
| 3520 |
// backslash characters, then we can safely slap some quotes around it. |
| 3521 |
// Otherwise we must also replace the offending characters with safe escape |
| 3522 |
// sequences. |
| 3523 |
|
| 3524 |
escapable.lastIndex = 0; |
| 3525 |
return escapable.test(string) ? '"' + string.replace(escapable, function (a) { |
| 3526 |
var c = meta[a]; |
| 3527 |
return typeof c === 'string' ? c : |
| 3528 |
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); |
| 3529 |
}) + '"' : '"' + string + '"'; |
| 3530 |
} |
| 3531 |
|
| 3532 |
function str(key, holder) { |
| 3533 |
// Produce a string from holder[key]. |
| 3534 |
var i, // The loop counter. |
| 3535 |
k, // The member key. |
| 3536 |
v, // The member value. |
| 3537 |
length, |
| 3538 |
mind = gap, |
| 3539 |
partial, |
| 3540 |
value = holder[key]; |
| 3541 |
|
| 3542 |
// If the value has a toJSON method, call it to obtain a replacement value. |
| 3543 |
if (value && typeof value === 'object' && |
| 3544 |
typeof value.toJSON === 'function') { |
| 3545 |
value = value.toJSON(key); |
| 3546 |
} |
| 3547 |
|
| 3548 |
// If we were called with a replacer function, then call the replacer to |
| 3549 |
// obtain a replacement value. |
| 3550 |
if (typeof rep === 'function') { |
| 3551 |
value = rep.call(holder, key, value); |
| 3552 |
} |
| 3553 |
|
| 3554 |
// What happens next depends on the value's type. |
| 3555 |
switch (typeof value) { |
| 3556 |
case 'string': |
| 3557 |
return quote(value); |
| 3558 |
|
| 3559 |
case 'number': |
| 3560 |
// JSON numbers must be finite. Encode non-finite numbers as null. |
| 3561 |
return isFinite(value) ? String(value) : 'null'; |
| 3562 |
|
| 3563 |
case 'boolean': |
| 3564 |
case 'null': |
| 3565 |
// If the value is a boolean or null, convert it to a string. Note: |
| 3566 |
// typeof null does not produce 'null'. The case is included here in |
| 3567 |
// the remote chance that this gets fixed someday. |
| 3568 |
return String(value); |
| 3569 |
|
| 3570 |
case 'object': |
| 3571 |
if (!value) return 'null'; |
| 3572 |
gap += indent; |
| 3573 |
partial = []; |
| 3574 |
|
| 3575 |
// Array.isArray |
| 3576 |
if (Object.prototype.toString.apply(value) === '[object Array]') { |
| 3577 |
length = value.length; |
| 3578 |
for (i = 0; i < length; i += 1) { |
| 3579 |
partial[i] = str(i, value) || 'null'; |
| 3580 |
} |
| 3581 |
|
| 3582 |
// Join all of the elements together, separated with commas, and |
| 3583 |
// wrap them in brackets. |
| 3584 |
v = partial.length === 0 ? '[]' : gap ? |
| 3585 |
'[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : |
| 3586 |
'[' + partial.join(',') + ']'; |
| 3587 |
gap = mind; |
| 3588 |
return v; |
| 3589 |
} |
| 3590 |
|
| 3591 |
// If the replacer is an array, use it to select the members to be |
| 3592 |
// stringified. |
| 3593 |
if (rep && typeof rep === 'object') { |
| 3594 |
length = rep.length; |
| 3595 |
for (i = 0; i < length; i += 1) { |
| 3596 |
k = rep[i]; |
| 3597 |
if (typeof k === 'string') { |
| 3598 |
v = str(k, value); |
| 3599 |
if (v) { |
| 3600 |
partial.push(quote(k) + (gap ? ': ' : ':') + v); |
| 3601 |
} |
| 3602 |
} |
| 3603 |
} |
| 3604 |
} |
| 3605 |
else { |
| 3606 |
// Otherwise, iterate through all of the keys in the object. |
| 3607 |
for (k in value) { |
| 3608 |
if (Object.prototype.hasOwnProperty.call(value, k)) { |
| 3609 |
v = str(k, value); |
| 3610 |
if (v) { |
| 3611 |
partial.push(quote(k) + (gap ? ': ' : ':') + v); |
| 3612 |
} |
| 3613 |
} |
| 3614 |
} |
| 3615 |
} |
| 3616 |
|
| 3617 |
// Join all of the member texts together, separated with commas, |
| 3618 |
// and wrap them in braces. |
| 3619 |
|
| 3620 |
v = partial.length === 0 ? '{}' : gap ? |
| 3621 |
'{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : |
| 3622 |
'{' + partial.join(',') + '}'; |
| 3623 |
gap = mind; |
| 3624 |
return v; |
| 3625 |
} |
| 3626 |
} |
| 3627 |
|
| 3628 |
module.exports = function (value, replacer, space) { |
| 3629 |
var i; |
| 3630 |
gap = ''; |
| 3631 |
indent = ''; |
| 3632 |
|
| 3633 |
// If the space parameter is a number, make an indent string containing that |
| 3634 |
// many spaces. |
| 3635 |
if (typeof space === 'number') { |
| 3636 |
for (i = 0; i < space; i += 1) { |
| 3637 |
indent += ' '; |
| 3638 |
} |
| 3639 |
} |
| 3640 |
// If the space parameter is a string, it will be used as the indent string. |
| 3641 |
else if (typeof space === 'string') { |
| 3642 |
indent = space; |
| 3643 |
} |
| 3644 |
|
| 3645 |
// If there is a replacer, it must be a function or an array. |
| 3646 |
// Otherwise, throw an error. |
| 3647 |
rep = replacer; |
| 3648 |
if (replacer && typeof replacer !== 'function' |
| 3649 |
&& (typeof replacer !== 'object' || typeof replacer.length !== 'number')) { |
| 3650 |
throw new Error('JSON.stringify'); |
| 3651 |
} |
| 3652 |
|
| 3653 |
// Make a fake root object containing our value under the key of ''. |
| 3654 |
// Return the result of stringifying the value. |
| 3655 |
return str('', {'': value}); |
| 3656 |
}; |
| 3657 |
|
| 3658 |
|
| 3659 |
/***/ }, |
| 3660 |
/* 16 */ |
| 3661 |
/***/ function(module, exports, __webpack_require__) { |
| 3662 |
|
| 3663 |
'use strict'; |
| 3664 |
|
| 3665 |
var util = __webpack_require__(11); |
| 3666 |
|
| 3667 |
module.exports = SchemaObject; |
| 3668 |
|
| 3669 |
function SchemaObject(obj) { |
| 3670 |
util.copy(obj, this); |
| 3671 |
} |
| 3672 |
|
| 3673 |
|
| 3674 |
/***/ }, |
| 3675 |
/* 17 */ |
| 3676 |
/***/ function(module, exports, __webpack_require__) { |
| 3677 |
|
| 3678 |
'use strict'; |
| 3679 |
|
| 3680 |
module.exports = { |
| 3681 |
setup: setupAsync, |
| 3682 |
compile: compileAsync |
| 3683 |
}; |
| 3684 |
|
| 3685 |
|
| 3686 |
var util = __webpack_require__(11); |
| 3687 |
|
| 3688 |
var ASYNC = { |
| 3689 |
'*': checkGenerators, |
| 3690 |
'co*': checkGenerators, |
| 3691 |
'es7': checkAsyncFunction |
| 3692 |
}; |
| 3693 |
|
| 3694 |
var TRANSPILE = { |
| 3695 |
'nodent': getNodent, |
| 3696 |
'regenerator': getRegenerator |
| 3697 |
}; |
| 3698 |
|
| 3699 |
var MODES = [ |
| 3700 |
{ async: 'co*' }, |
| 3701 |
{ async: 'es7', transpile: 'nodent' }, |
| 3702 |
{ async: 'co*', transpile: 'regenerator' } |
| 3703 |
]; |
| 3704 |
|
| 3705 |
|
| 3706 |
var regenerator, nodent; |
| 3707 |
|
| 3708 |
|
| 3709 |
function setupAsync(opts, required) { |
| 3710 |
if (required !== false) required = true; |
| 3711 |
var async = opts.async |
| 3712 |
, transpile = opts.transpile |
| 3713 |
, check; |
| 3714 |
|
| 3715 |
switch (typeof transpile) { |
| 3716 |
case 'string': |
| 3717 |
var get = TRANSPILE[transpile]; |
| 3718 |
if (!get) throw new Error('bad transpiler: ' + transpile); |
| 3719 |
return (opts._transpileFunc = get(opts, required)); |
| 3720 |
case 'undefined': |
| 3721 |
case 'boolean': |
| 3722 |
if (typeof async == 'string') { |
| 3723 |
check = ASYNC[async]; |
| 3724 |
if (!check) throw new Error('bad async mode: ' + async); |
| 3725 |
return (opts.transpile = check(opts, required)); |
| 3726 |
} |
| 3727 |
|
| 3728 |
for (var i=0; i<MODES.length; i++) { |
| 3729 |
var _opts = MODES[i]; |
| 3730 |
if (setupAsync(_opts, false)) { |
| 3731 |
util.copy(_opts, opts); |
| 3732 |
return opts.transpile; |
| 3733 |
} |
| 3734 |
} |
| 3735 |
/* istanbul ignore next */ |
| 3736 |
throw new Error('generators, nodent and regenerator are not available'); |
| 3737 |
case 'function': |
| 3738 |
return (opts._transpileFunc = opts.transpile); |
| 3739 |
default: |
| 3740 |
throw new Error('bad transpiler: ' + transpile); |
| 3741 |
} |
| 3742 |
} |
| 3743 |
|
| 3744 |
|
| 3745 |
function checkGenerators(opts, required) { |
| 3746 |
/* jshint evil: true */ |
| 3747 |
try { |
| 3748 |
eval('(function*(){})()'); |
| 3749 |
return true; |
| 3750 |
} catch(e) { |
| 3751 |
/* istanbul ignore next */ |
| 3752 |
if (required) throw new Error('generators not supported'); |
| 3753 |
} |
| 3754 |
} |
| 3755 |
|
| 3756 |
|
| 3757 |
function checkAsyncFunction(opts, required) { |
| 3758 |
/* jshint evil: true */ |
| 3759 |
try { |
| 3760 |
eval('(async function(){})()'); |
| 3761 |
/* istanbul ignore next */ |
| 3762 |
return true; |
| 3763 |
} catch(e) { |
| 3764 |
if (required) throw new Error('es7 async functions not supported'); |
| 3765 |
} |
| 3766 |
} |
| 3767 |
|
| 3768 |
|
| 3769 |
function getRegenerator(opts, required) { |
| 3770 |
try { |
| 3771 |
if (!regenerator) { |
| 3772 |
regenerator = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"regenerator\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())); |
| 3773 |
regenerator.runtime(); |
| 3774 |
} |
| 3775 |
if (!opts.async || opts.async === true) |
| 3776 |
opts.async = 'es7'; |
| 3777 |
return regeneratorTranspile; |
| 3778 |
} catch(e) { |
| 3779 |
/* istanbul ignore next */ |
| 3780 |
if (required) throw new Error('regenerator not available'); |
| 3781 |
} |
| 3782 |
} |
| 3783 |
|
| 3784 |
|
| 3785 |
function regeneratorTranspile(code) { |
| 3786 |
return regenerator.compile(code).code; |
| 3787 |
} |
| 3788 |
|
| 3789 |
|
| 3790 |
function getNodent(opts, required) { |
| 3791 |
/* jshint evil: true */ |
| 3792 |
try { |
| 3793 |
if (!nodent) nodent = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module \"nodent\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()))({ log: false, dontInstallRequireHook: true }); |
| 3794 |
if (opts.async != 'es7') { |
| 3795 |
if (opts.async && opts.async !== true) console.warn('nodent transpiles only es7 async functions'); |
| 3796 |
opts.async = 'es7'; |
| 3797 |
} |
| 3798 |
return nodentTranspile; |
| 3799 |
} catch(e) { |
| 3800 |
/* istanbul ignore next */ |
| 3801 |
if (required) throw new Error('nodent not available'); |
| 3802 |
} |
| 3803 |
} |
| 3804 |
|
| 3805 |
|
| 3806 |
function nodentTranspile(code) { |
| 3807 |
return nodent.compile(code, '', { promises: true, sourcemap: false }).code; |
| 3808 |
} |
| 3809 |
|
| 3810 |
|
| 3811 |
/** |
| 3812 |
* Creates validating function for passed schema with asynchronous loading of missing schemas. |
| 3813 |
* `loadSchema` option should be a function that accepts schema uri and node-style callback. |
| 3814 |
* @this Ajv |
| 3815 |
* @param {Object} schema schema object |
| 3816 |
* @param {Function} callback node-style callback, it is always called with 2 parameters: error (or null) and validating function. |
| 3817 |
*/ |
| 3818 |
function compileAsync(schema, callback) { |
| 3819 |
/* eslint no-shadow: 0 */ |
| 3820 |
/* jshint validthis: true */ |
| 3821 |
var schemaObj; |
| 3822 |
var self = this; |
| 3823 |
try { |
| 3824 |
schemaObj = this._addSchema(schema); |
| 3825 |
} catch(e) { |
| 3826 |
setTimeout(function() { callback(e); }); |
| 3827 |
return; |
| 3828 |
} |
| 3829 |
if (schemaObj.validate) { |
| 3830 |
setTimeout(function() { callback(null, schemaObj.validate); }); |
| 3831 |
} else { |
| 3832 |
if (typeof this._opts.loadSchema != 'function') |
| 3833 |
throw new Error('options.loadSchema should be a function'); |
| 3834 |
_compileAsync(schema, callback, true); |
| 3835 |
} |
| 3836 |
|
| 3837 |
|
| 3838 |
function _compileAsync(schema, callback, firstCall) { |
| 3839 |
var validate; |
| 3840 |
try { validate = self.compile(schema); } |
| 3841 |
catch(e) { |
| 3842 |
if (e.missingSchema) loadMissingSchema(e); |
| 3843 |
else deferCallback(e); |
| 3844 |
return; |
| 3845 |
} |
| 3846 |
deferCallback(null, validate); |
| 3847 |
|
| 3848 |
function loadMissingSchema(e) { |
| 3849 |
var ref = e.missingSchema; |
| 3850 |
if (self._refs[ref] || self._schemas[ref]) |
| 3851 |
return callback(new Error('Schema ' + ref + ' is loaded but' + e.missingRef + 'cannot be resolved')); |
| 3852 |
var _callbacks = self._loadingSchemas[ref]; |
| 3853 |
if (_callbacks) { |
| 3854 |
if (typeof _callbacks == 'function') |
| 3855 |
self._loadingSchemas[ref] = [_callbacks, schemaLoaded]; |
| 3856 |
else |
| 3857 |
_callbacks[_callbacks.length] = schemaLoaded; |
| 3858 |
} else { |
| 3859 |
self._loadingSchemas[ref] = schemaLoaded; |
| 3860 |
self._opts.loadSchema(ref, function (err, sch) { |
| 3861 |
var _callbacks = self._loadingSchemas[ref]; |
| 3862 |
delete self._loadingSchemas[ref]; |
| 3863 |
if (typeof _callbacks == 'function') { |
| 3864 |
_callbacks(err, sch); |
| 3865 |
} else { |
| 3866 |
for (var i=0; i<_callbacks.length; i++) |
| 3867 |
_callbacks[i](err, sch); |
| 3868 |
} |
| 3869 |
}); |
| 3870 |
} |
| 3871 |
|
| 3872 |
function schemaLoaded(err, sch) { |
| 3873 |
if (err) return callback(err); |
| 3874 |
if (!(self._refs[ref] || self._schemas[ref])) { |
| 3875 |
try { |
| 3876 |
self.addSchema(sch, ref); |
| 3877 |
} catch(e) { |
| 3878 |
callback(e); |
| 3879 |
return; |
| 3880 |
} |
| 3881 |
} |
| 3882 |
_compileAsync(schema, callback); |
| 3883 |
} |
| 3884 |
} |
| 3885 |
|
| 3886 |
function deferCallback(err, validate) { |
| 3887 |
if (firstCall) setTimeout(function() { callback(err, validate); }); |
| 3888 |
else return callback(err, validate); |
| 3889 |
} |
| 3890 |
} |
| 3891 |
} |
| 3892 |
|
| 3893 |
|
| 3894 |
/***/ }, |
| 3895 |
/* 18 */ |
| 3896 |
/***/ function(module, exports) { |
| 3897 |
|
| 3898 |
'use strict'; |
| 3899 |
module.exports = function generate_validate(it, $keyword) { |
| 3900 |
var out = ''; |
| 3901 |
var $async = it.schema.$async === true; |
| 3902 |
if (it.isTop) { |
| 3903 |
var $top = it.isTop, |
| 3904 |
$lvl = it.level = 0, |
| 3905 |
$dataLvl = it.dataLevel = 0, |
| 3906 |
$data = 'data'; |
| 3907 |
it.rootId = it.resolve.fullPath(it.root.schema.id); |
| 3908 |
it.baseId = it.baseId || it.rootId; |
| 3909 |
if ($async) { |
| 3910 |
it.async = true; |
| 3911 |
var $es7 = it.opts.async == 'es7'; |
| 3912 |
it.yieldAwait = $es7 ? 'await' : 'yield'; |
| 3913 |
} |
| 3914 |
delete it.isTop; |
| 3915 |
it.dataPathArr = [undefined]; |
| 3916 |
out += ' validate = '; |
| 3917 |
if ($async) { |
| 3918 |
if ($es7) { |
| 3919 |
out += ' (async function '; |
| 3920 |
} else { |
| 3921 |
if (it.opts.async == 'co*') { |
| 3922 |
out += 'co.wrap'; |
| 3923 |
} |
| 3924 |
out += '(function* '; |
| 3925 |
} |
| 3926 |
} else { |
| 3927 |
out += ' (function '; |
| 3928 |
} |
| 3929 |
out += ' (data, dataPath, parentData, parentDataProperty) { \'use strict\'; var vErrors = null; '; |
| 3930 |
out += ' var errors = 0; '; |
| 3931 |
} else { |
| 3932 |
var $lvl = it.level, |
| 3933 |
$dataLvl = it.dataLevel, |
| 3934 |
$data = 'data' + ($dataLvl || ''); |
| 3935 |
if (it.schema.id) it.baseId = it.resolve.url(it.baseId, it.schema.id); |
| 3936 |
if ($async && !it.async) throw new Error('async schema in sync schema'); |
| 3937 |
out += ' var errs_' + ($lvl) + ' = errors;'; |
| 3938 |
} |
| 3939 |
var $valid = 'valid' + $lvl, |
| 3940 |
$breakOnError = !it.opts.allErrors, |
| 3941 |
$closingBraces1 = '', |
| 3942 |
$closingBraces2 = '', |
| 3943 |
$errorKeyword; |
| 3944 |
var $typeSchema = it.schema.type, |
| 3945 |
$typeIsArray = Array.isArray($typeSchema); |
| 3946 |
if ($typeSchema && it.opts.coerceTypes) { |
| 3947 |
var $coerceToTypes = it.util.coerceToTypes($typeSchema); |
| 3948 |
if ($coerceToTypes) { |
| 3949 |
var $schemaPath = it.schemaPath + '.type', |
| 3950 |
$errSchemaPath = it.errSchemaPath + '/type', |
| 3951 |
$method = $typeIsArray ? 'checkDataTypes' : 'checkDataType'; |
| 3952 |
out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { '; |
| 3953 |
var $dataType = 'dataType' + $lvl, |
| 3954 |
$coerced = 'coerced' + $lvl; |
| 3955 |
out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; var ' + ($coerced) + ' = undefined; '; |
| 3956 |
var $bracesCoercion = ''; |
| 3957 |
var arr1 = $coerceToTypes; |
| 3958 |
if (arr1) { |
| 3959 |
var $type, $i = -1, |
| 3960 |
l1 = arr1.length - 1; |
| 3961 |
while ($i < l1) { |
| 3962 |
$type = arr1[$i += 1]; |
| 3963 |
if ($i) { |
| 3964 |
out += ' if (' + ($coerced) + ' === undefined) { '; |
| 3965 |
$bracesCoercion += '}'; |
| 3966 |
} |
| 3967 |
if ($type == 'string') { |
| 3968 |
out += ' if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; '; |
| 3969 |
} else if ($type == 'number' || $type == 'integer') { |
| 3970 |
out += ' if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' '; |
| 3971 |
if ($type == 'integer') { |
| 3972 |
out += ' && !(' + ($data) + ' % 1)'; |
| 3973 |
} |
| 3974 |
out += ')) ' + ($coerced) + ' = +' + ($data) + '; '; |
| 3975 |
} else if ($type == 'boolean') { |
| 3976 |
out += ' if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; '; |
| 3977 |
} else if ($type == 'null') { |
| 3978 |
out += ' if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; '; |
| 3979 |
} |
| 3980 |
} |
| 3981 |
} |
| 3982 |
out += ' ' + ($bracesCoercion) + ' if (' + ($coerced) + ' === undefined) { '; |
| 3983 |
var $$outStack = $$outStack || []; |
| 3984 |
$$outStack.push(out); |
| 3985 |
out = ''; /* istanbul ignore else */ |
| 3986 |
if (it.createErrors !== false) { |
| 3987 |
out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { type: \''; |
| 3988 |
if ($typeIsArray) { |
| 3989 |
out += '' + ($typeSchema.join(",")); |
| 3990 |
} else { |
| 3991 |
out += '' + ($typeSchema); |
| 3992 |
} |
| 3993 |
out += '\' } '; |
| 3994 |
if (it.opts.messages !== false) { |
| 3995 |
out += ' , message: \'should be '; |
| 3996 |
if ($typeIsArray) { |
| 3997 |
out += '' + ($typeSchema.join(",")); |
| 3998 |
} else { |
| 3999 |
out += '' + ($typeSchema); |
| 4000 |
} |
| 4001 |
out += '\' '; |
| 4002 |
} |
| 4003 |
if (it.opts.verbose) { |
| 4004 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4005 |
} |
| 4006 |
out += ' } '; |
| 4007 |
} else { |
| 4008 |
out += ' {} '; |
| 4009 |
} |
| 4010 |
var __err = out; |
| 4011 |
out = $$outStack.pop(); |
| 4012 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4013 |
if (it.async) { |
| 4014 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 4015 |
} else { |
| 4016 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 4017 |
} |
| 4018 |
} else { |
| 4019 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4020 |
} |
| 4021 |
out += ' } else { '; |
| 4022 |
if ($dataLvl) { |
| 4023 |
var $parentData = 'data' + (($dataLvl - 1) || ''), |
| 4024 |
$dataProperty = it.dataPathArr[$dataLvl]; |
| 4025 |
out += ' ' + ($data) + ' = ' + ($parentData) + '[' + ($dataProperty) + '] = ' + ($coerced) + '; '; |
| 4026 |
} else { |
| 4027 |
out += ' data = ' + ($coerced) + '; if (parentData !== undefined) parentData[parentDataProperty] = ' + ($coerced) + '; '; |
| 4028 |
} |
| 4029 |
out += ' } } '; |
| 4030 |
} |
| 4031 |
} |
| 4032 |
var arr2 = it.RULES; |
| 4033 |
if (arr2) { |
| 4034 |
var $rulesGroup, i2 = -1, |
| 4035 |
l2 = arr2.length - 1; |
| 4036 |
while (i2 < l2) { |
| 4037 |
$rulesGroup = arr2[i2 += 1]; |
| 4038 |
if ($shouldUseGroup($rulesGroup)) { |
| 4039 |
if ($rulesGroup.type) { |
| 4040 |
out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { '; |
| 4041 |
} |
| 4042 |
if (it.opts.useDefaults && !it.compositeRule) { |
| 4043 |
if ($rulesGroup.type == 'object' && it.schema.properties) { |
| 4044 |
var $schema = it.schema.properties, |
| 4045 |
$schemaKeys = Object.keys($schema); |
| 4046 |
var arr3 = $schemaKeys; |
| 4047 |
if (arr3) { |
| 4048 |
var $propertyKey, i3 = -1, |
| 4049 |
l3 = arr3.length - 1; |
| 4050 |
while (i3 < l3) { |
| 4051 |
$propertyKey = arr3[i3 += 1]; |
| 4052 |
var $sch = $schema[$propertyKey]; |
| 4053 |
if ($sch.default !== undefined) { |
| 4054 |
var $passData = $data + it.util.getProperty($propertyKey); |
| 4055 |
out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = '; |
| 4056 |
if (it.opts.useDefaults == 'clone') { |
| 4057 |
out += ' ' + (JSON.stringify($sch.default)) + ' '; |
| 4058 |
} else { |
| 4059 |
out += ' ' + (it.useDefault($sch.default)) + ' '; |
| 4060 |
} |
| 4061 |
out += '; '; |
| 4062 |
} |
| 4063 |
} |
| 4064 |
} |
| 4065 |
} else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) { |
| 4066 |
var arr4 = it.schema.items; |
| 4067 |
if (arr4) { |
| 4068 |
var $sch, $i = -1, |
| 4069 |
l4 = arr4.length - 1; |
| 4070 |
while ($i < l4) { |
| 4071 |
$sch = arr4[$i += 1]; |
| 4072 |
if ($sch.default !== undefined) { |
| 4073 |
var $passData = $data + '[' + $i + ']'; |
| 4074 |
out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = '; |
| 4075 |
if (it.opts.useDefaults == 'clone') { |
| 4076 |
out += ' ' + (JSON.stringify($sch.default)) + ' '; |
| 4077 |
} else { |
| 4078 |
out += ' ' + (it.useDefault($sch.default)) + ' '; |
| 4079 |
} |
| 4080 |
out += '; '; |
| 4081 |
} |
| 4082 |
} |
| 4083 |
} |
| 4084 |
} |
| 4085 |
} |
| 4086 |
var arr5 = $rulesGroup.rules; |
| 4087 |
if (arr5) { |
| 4088 |
var $rule, i5 = -1, |
| 4089 |
l5 = arr5.length - 1; |
| 4090 |
while (i5 < l5) { |
| 4091 |
$rule = arr5[i5 += 1]; |
| 4092 |
if ($shouldUseRule($rule)) { |
| 4093 |
if ($rule.custom) { |
| 4094 |
var $schema = it.schema[$rule.keyword], |
| 4095 |
$ruleValidate = it.useCustomRule($rule, $schema, it.schema, it), |
| 4096 |
$ruleErrs = $ruleValidate.code + '.errors', |
| 4097 |
$schemaPath = it.schemaPath + '.' + $rule.keyword, |
| 4098 |
$errSchemaPath = it.errSchemaPath + '/' + $rule.keyword, |
| 4099 |
$errs = 'errs' + $lvl, |
| 4100 |
$i = 'i' + $lvl, |
| 4101 |
$ruleErr = 'ruleErr' + $lvl, |
| 4102 |
$rDef = $rule.definition, |
| 4103 |
$asyncKeyword = $rDef.async, |
| 4104 |
$inline = $rDef.inline, |
| 4105 |
$macro = $rDef.macro; |
| 4106 |
if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema'); |
| 4107 |
if (!($inline || $macro)) { |
| 4108 |
out += '' + ($ruleErrs) + ' = null;'; |
| 4109 |
} |
| 4110 |
out += 'var ' + ($errs) + ' = errors;var valid' + ($lvl) + ';'; |
| 4111 |
if ($inline && $rDef.statements) { |
| 4112 |
out += ' ' + ($ruleValidate.validate); |
| 4113 |
} else if ($macro) { |
| 4114 |
var $it = it.util.copy(it); |
| 4115 |
$it.level++; |
| 4116 |
$it.schema = $ruleValidate.validate; |
| 4117 |
$it.schemaPath = ''; |
| 4118 |
var $wasComposite = it.compositeRule; |
| 4119 |
it.compositeRule = $it.compositeRule = true; |
| 4120 |
var $code = it.validate($it).replace(/validate\.schema/g, $ruleValidate.code); |
| 4121 |
it.compositeRule = $it.compositeRule = $wasComposite; |
| 4122 |
out += ' ' + ($code); |
| 4123 |
} else if ($rDef.compile || $rDef.validate) { |
| 4124 |
var $$outStack = $$outStack || []; |
| 4125 |
$$outStack.push(out); |
| 4126 |
out = ''; |
| 4127 |
out += ' ' + ($ruleValidate.code) + '.call( '; |
| 4128 |
if (it.opts.passContext) { |
| 4129 |
out += 'this'; |
| 4130 |
} else { |
| 4131 |
out += 'self'; |
| 4132 |
} |
| 4133 |
var $validateArgs = $ruleValidate.validate.length; |
| 4134 |
if ($rDef.compile || $rDef.schema === false) { |
| 4135 |
out += ' , ' + ($data) + ' '; |
| 4136 |
} else { |
| 4137 |
out += ' , validate.schema' + ($schemaPath) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' '; |
| 4138 |
} |
| 4139 |
out += ' , (dataPath || \'\')'; |
| 4140 |
if (it.errorPath != '""') { |
| 4141 |
out += ' + ' + (it.errorPath); |
| 4142 |
} |
| 4143 |
if ($dataLvl) { |
| 4144 |
out += ' , data' + (($dataLvl - 1) || '') + ' , ' + (it.dataPathArr[$dataLvl]) + ' '; |
| 4145 |
} else { |
| 4146 |
out += ' , parentData , parentDataProperty '; |
| 4147 |
} |
| 4148 |
out += ' ) '; |
| 4149 |
var def_callRuleValidate = out; |
| 4150 |
out = $$outStack.pop(); |
| 4151 |
if ($rDef.errors !== false) { |
| 4152 |
if ($asyncKeyword) { |
| 4153 |
$ruleErrs = 'customErrors' + $lvl; |
| 4154 |
out += ' var ' + ($ruleErrs) + ' = null; try { valid' + ($lvl) + ' = ' + (it.yieldAwait) + (def_callRuleValidate) + '; } catch (e) { valid' + ($lvl) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } '; |
| 4155 |
} else { |
| 4156 |
out += ' ' + ($ruleValidate.code) + '.errors = null; '; |
| 4157 |
} |
| 4158 |
} |
| 4159 |
} |
| 4160 |
out += 'if (! '; |
| 4161 |
if ($inline) { |
| 4162 |
if ($rDef.statements) { |
| 4163 |
out += ' valid' + ($lvl) + ' '; |
| 4164 |
} else { |
| 4165 |
out += ' (' + ($ruleValidate.validate) + ') '; |
| 4166 |
} |
| 4167 |
} else if ($macro) { |
| 4168 |
out += ' valid' + ($it.level) + ' '; |
| 4169 |
} else { |
| 4170 |
if ($asyncKeyword) { |
| 4171 |
if ($rDef.errors === false) { |
| 4172 |
out += ' (' + (it.yieldAwait) + (def_callRuleValidate) + ') '; |
| 4173 |
} else { |
| 4174 |
out += ' valid' + ($lvl) + ' '; |
| 4175 |
} |
| 4176 |
} else { |
| 4177 |
out += ' ' + (def_callRuleValidate) + ' '; |
| 4178 |
} |
| 4179 |
} |
| 4180 |
out += ') { '; |
| 4181 |
$errorKeyword = $rule.keyword; |
| 4182 |
var $$outStack = $$outStack || []; |
| 4183 |
$$outStack.push(out); |
| 4184 |
out = ''; |
| 4185 |
var $$outStack = $$outStack || []; |
| 4186 |
$$outStack.push(out); |
| 4187 |
out = ''; /* istanbul ignore else */ |
| 4188 |
if (it.createErrors !== false) { |
| 4189 |
out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { keyword: \'' + ($rule.keyword) + '\' } '; |
| 4190 |
if (it.opts.messages !== false) { |
| 4191 |
out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' '; |
| 4192 |
} |
| 4193 |
if (it.opts.verbose) { |
| 4194 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4195 |
} |
| 4196 |
out += ' } '; |
| 4197 |
} else { |
| 4198 |
out += ' {} '; |
| 4199 |
} |
| 4200 |
var __err = out; |
| 4201 |
out = $$outStack.pop(); |
| 4202 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4203 |
if (it.async) { |
| 4204 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 4205 |
} else { |
| 4206 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 4207 |
} |
| 4208 |
} else { |
| 4209 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4210 |
} |
| 4211 |
var def_customError = out; |
| 4212 |
out = $$outStack.pop(); |
| 4213 |
if ($inline) { |
| 4214 |
if ($rDef.errors) { |
| 4215 |
if ($rDef.errors != 'full') { |
| 4216 |
out += ' for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) { ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; } if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } '; |
| 4217 |
if (it.opts.verbose) { |
| 4218 |
out += ' ' + ($ruleErr) + '.schema = validate.schema' + ($schemaPath) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; '; |
| 4219 |
} |
| 4220 |
out += ' } '; |
| 4221 |
} |
| 4222 |
} else { |
| 4223 |
if ($rDef.errors === false) { |
| 4224 |
out += ' ' + (def_customError) + ' '; |
| 4225 |
} else { |
| 4226 |
out += ' if (' + ($errs) + ' == errors) { ' + (def_customError) + ' } else { for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) { ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; } if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } '; |
| 4227 |
if (it.opts.verbose) { |
| 4228 |
out += ' ' + ($ruleErr) + '.schema = validate.schema' + ($schemaPath) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; '; |
| 4229 |
} |
| 4230 |
out += ' } } '; |
| 4231 |
} |
| 4232 |
} |
| 4233 |
} else if ($macro) { |
| 4234 |
out += ' var err = '; /* istanbul ignore else */ |
| 4235 |
if (it.createErrors !== false) { |
| 4236 |
out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { keyword: \'' + ($rule.keyword) + '\' } '; |
| 4237 |
if (it.opts.messages !== false) { |
| 4238 |
out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' '; |
| 4239 |
} |
| 4240 |
if (it.opts.verbose) { |
| 4241 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4242 |
} |
| 4243 |
out += ' } '; |
| 4244 |
} else { |
| 4245 |
out += ' {} '; |
| 4246 |
} |
| 4247 |
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4248 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4249 |
if (it.async) { |
| 4250 |
out += ' throw new ValidationError(vErrors); '; |
| 4251 |
} else { |
| 4252 |
out += ' validate.errors = vErrors; return false '; |
| 4253 |
} |
| 4254 |
} |
| 4255 |
} else { |
| 4256 |
if ($rDef.errors === false) { |
| 4257 |
out += ' ' + (def_customError) + ' '; |
| 4258 |
} else { |
| 4259 |
out += ' if (Array.isArray(' + ($ruleErrs) + ')) { if (vErrors === null) vErrors = ' + ($ruleErrs) + '; else vErrors.concat(' + ($ruleErrs) + '); errors = vErrors.length; for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; '; |
| 4260 |
if (it.opts.verbose) { |
| 4261 |
out += ' ' + ($ruleErr) + '.schema = validate.schema' + ($schemaPath) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; '; |
| 4262 |
} |
| 4263 |
out += ' } } else { ' + (def_customError) + ' } '; |
| 4264 |
} |
| 4265 |
} |
| 4266 |
$errorKeyword = undefined; |
| 4267 |
out += ' } '; |
| 4268 |
if ($breakOnError) { |
| 4269 |
out += ' else { '; |
| 4270 |
} |
| 4271 |
} else { |
| 4272 |
out += ' ' + ($rule.code(it, $rule.keyword)) + ' '; |
| 4273 |
} |
| 4274 |
if ($breakOnError) { |
| 4275 |
$closingBraces1 += '}'; |
| 4276 |
} |
| 4277 |
} |
| 4278 |
} |
| 4279 |
} |
| 4280 |
if ($breakOnError) { |
| 4281 |
out += ' ' + ($closingBraces1) + ' '; |
| 4282 |
$closingBraces1 = ''; |
| 4283 |
} |
| 4284 |
if ($rulesGroup.type) { |
| 4285 |
out += ' } '; |
| 4286 |
if ($typeSchema && $typeSchema === $rulesGroup.type) { |
| 4287 |
var $typeChecked = true; |
| 4288 |
out += ' else { '; |
| 4289 |
var $schemaPath = it.schemaPath + '.type', |
| 4290 |
$errSchemaPath = it.errSchemaPath + '/type'; |
| 4291 |
var $$outStack = $$outStack || []; |
| 4292 |
$$outStack.push(out); |
| 4293 |
out = ''; /* istanbul ignore else */ |
| 4294 |
if (it.createErrors !== false) { |
| 4295 |
out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { type: \''; |
| 4296 |
if ($typeIsArray) { |
| 4297 |
out += '' + ($typeSchema.join(",")); |
| 4298 |
} else { |
| 4299 |
out += '' + ($typeSchema); |
| 4300 |
} |
| 4301 |
out += '\' } '; |
| 4302 |
if (it.opts.messages !== false) { |
| 4303 |
out += ' , message: \'should be '; |
| 4304 |
if ($typeIsArray) { |
| 4305 |
out += '' + ($typeSchema.join(",")); |
| 4306 |
} else { |
| 4307 |
out += '' + ($typeSchema); |
| 4308 |
} |
| 4309 |
out += '\' '; |
| 4310 |
} |
| 4311 |
if (it.opts.verbose) { |
| 4312 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4313 |
} |
| 4314 |
out += ' } '; |
| 4315 |
} else { |
| 4316 |
out += ' {} '; |
| 4317 |
} |
| 4318 |
var __err = out; |
| 4319 |
out = $$outStack.pop(); |
| 4320 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4321 |
if (it.async) { |
| 4322 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 4323 |
} else { |
| 4324 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 4325 |
} |
| 4326 |
} else { |
| 4327 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4328 |
} |
| 4329 |
out += ' } '; |
| 4330 |
} |
| 4331 |
} |
| 4332 |
if ($breakOnError) { |
| 4333 |
out += ' if (errors === '; |
| 4334 |
if ($top) { |
| 4335 |
out += '0'; |
| 4336 |
} else { |
| 4337 |
out += 'errs_' + ($lvl); |
| 4338 |
} |
| 4339 |
out += ') { '; |
| 4340 |
$closingBraces2 += '}'; |
| 4341 |
} |
| 4342 |
} |
| 4343 |
} |
| 4344 |
} |
| 4345 |
if ($typeSchema && !$typeChecked && !(it.opts.coerceTypes && $coerceToTypes)) { |
| 4346 |
var $schemaPath = it.schemaPath + '.type', |
| 4347 |
$errSchemaPath = it.errSchemaPath + '/type', |
| 4348 |
$method = $typeIsArray ? 'checkDataTypes' : 'checkDataType'; |
| 4349 |
out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { '; |
| 4350 |
var $$outStack = $$outStack || []; |
| 4351 |
$$outStack.push(out); |
| 4352 |
out = ''; /* istanbul ignore else */ |
| 4353 |
if (it.createErrors !== false) { |
| 4354 |
out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { type: \''; |
| 4355 |
if ($typeIsArray) { |
| 4356 |
out += '' + ($typeSchema.join(",")); |
| 4357 |
} else { |
| 4358 |
out += '' + ($typeSchema); |
| 4359 |
} |
| 4360 |
out += '\' } '; |
| 4361 |
if (it.opts.messages !== false) { |
| 4362 |
out += ' , message: \'should be '; |
| 4363 |
if ($typeIsArray) { |
| 4364 |
out += '' + ($typeSchema.join(",")); |
| 4365 |
} else { |
| 4366 |
out += '' + ($typeSchema); |
| 4367 |
} |
| 4368 |
out += '\' '; |
| 4369 |
} |
| 4370 |
if (it.opts.verbose) { |
| 4371 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 4372 |
} |
| 4373 |
out += ' } '; |
| 4374 |
} else { |
| 4375 |
out += ' {} '; |
| 4376 |
} |
| 4377 |
var __err = out; |
| 4378 |
out = $$outStack.pop(); |
| 4379 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 4380 |
if (it.async) { |
| 4381 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 4382 |
} else { |
| 4383 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 4384 |
} |
| 4385 |
} else { |
| 4386 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 4387 |
} |
| 4388 |
out += ' }'; |
| 4389 |
} |
| 4390 |
if ($breakOnError) { |
| 4391 |
out += ' ' + ($closingBraces2) + ' '; |
| 4392 |
} |
| 4393 |
if ($top) { |
| 4394 |
if ($async) { |
| 4395 |
out += ' if (errors === 0) return true; '; |
| 4396 |
out += ' else throw new ValidationError(vErrors); '; |
| 4397 |
} else { |
| 4398 |
out += ' validate.errors = vErrors; '; |
| 4399 |
out += ' return errors === 0; '; |
| 4400 |
} |
| 4401 |
out += ' });'; |
| 4402 |
} else { |
| 4403 |
out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';'; |
| 4404 |
} |
| 4405 |
out = it.util.cleanUpCode(out); |
| 4406 |
if ($top && $breakOnError) { |
| 4407 |
out = it.util.cleanUpVarErrors(out, $async); |
| 4408 |
} |
| 4409 |
|
| 4410 |
function $shouldUseGroup($rulesGroup) { |
| 4411 |
for (var i = 0; i < $rulesGroup.rules.length; i++) |
| 4412 |
if ($shouldUseRule($rulesGroup.rules[i])) return true; |
| 4413 |
} |
| 4414 |
|
| 4415 |
function $shouldUseRule($rule) { |
| 4416 |
return it.schema[$rule.keyword] !== undefined || ($rule.keyword == 'properties' && (it.schema.additionalProperties === false || typeof it.schema.additionalProperties == 'object' || (it.schema.patternProperties && Object.keys(it.schema.patternProperties).length) || (it.opts.v5 && it.schema.patternGroups && Object.keys(it.schema.patternGroups).length))); |
| 4417 |
} |
| 4418 |
return out; |
| 4419 |
} |
| 4420 |
|
| 4421 |
|
| 4422 |
/***/ }, |
| 4423 |
/* 19 */ |
| 4424 |
/***/ function(module, exports) { |
| 4425 |
|
| 4426 |
|
| 4427 |
/** |
| 4428 |
* slice() reference. |
| 4429 |
*/ |
| 4430 |
|
| 4431 |
var slice = Array.prototype.slice; |
| 4432 |
|
| 4433 |
/** |
| 4434 |
* Expose `co`. |
| 4435 |
*/ |
| 4436 |
|
| 4437 |
module.exports = co['default'] = co.co = co; |
| 4438 |
|
| 4439 |
/** |
| 4440 |
* Wrap the given generator `fn` into a |
| 4441 |
* function that returns a promise. |
| 4442 |
* This is a separate function so that |
| 4443 |
* every `co()` call doesn't create a new, |
| 4444 |
* unnecessary closure. |
| 4445 |
* |
| 4446 |
* @param {GeneratorFunction} fn |
| 4447 |
* @return {Function} |
| 4448 |
* @api public |
| 4449 |
*/ |
| 4450 |
|
| 4451 |
co.wrap = function (fn) { |
| 4452 |
createPromise.__generatorFunction__ = fn; |
| 4453 |
return createPromise; |
| 4454 |
function createPromise() { |
| 4455 |
return co.call(this, fn.apply(this, arguments)); |
| 4456 |
} |
| 4457 |
}; |
| 4458 |
|
| 4459 |
/** |
| 4460 |
* Execute the generator function or a generator |
| 4461 |
* and return a promise. |
| 4462 |
* |
| 4463 |
* @param {Function} fn |
| 4464 |
* @return {Promise} |
| 4465 |
* @api public |
| 4466 |
*/ |
| 4467 |
|
| 4468 |
function co(gen) { |
| 4469 |
var ctx = this; |
| 4470 |
var args = slice.call(arguments, 1) |
| 4471 |
|
| 4472 |
// we wrap everything in a promise to avoid promise chaining, |
| 4473 |
// which leads to memory leak errors. |
| 4474 |
// see https://github.com/tj/co/issues/180 |
| 4475 |
return new Promise(function(resolve, reject) { |
| 4476 |
if (typeof gen === 'function') gen = gen.apply(ctx, args); |
| 4477 |
if (!gen || typeof gen.next !== 'function') return resolve(gen); |
| 4478 |
|
| 4479 |
onFulfilled(); |
| 4480 |
|
| 4481 |
/** |
| 4482 |
* @param {Mixed} res |
| 4483 |
* @return {Promise} |
| 4484 |
* @api private |
| 4485 |
*/ |
| 4486 |
|
| 4487 |
function onFulfilled(res) { |
| 4488 |
var ret; |
| 4489 |
try { |
| 4490 |
ret = gen.next(res); |
| 4491 |
} catch (e) { |
| 4492 |
return reject(e); |
| 4493 |
} |
| 4494 |
next(ret); |
| 4495 |
} |
| 4496 |
|
| 4497 |
/** |
| 4498 |
* @param {Error} err |
| 4499 |
* @return {Promise} |
| 4500 |
* @api private |
| 4501 |
*/ |
| 4502 |
|
| 4503 |
function onRejected(err) { |
| 4504 |
var ret; |
| 4505 |
try { |
| 4506 |
ret = gen.throw(err); |
| 4507 |
} catch (e) { |
| 4508 |
return reject(e); |
| 4509 |
} |
| 4510 |
next(ret); |
| 4511 |
} |
| 4512 |
|
| 4513 |
/** |
| 4514 |
* Get the next value in the generator, |
| 4515 |
* return a promise. |
| 4516 |
* |
| 4517 |
* @param {Object} ret |
| 4518 |
* @return {Promise} |
| 4519 |
* @api private |
| 4520 |
*/ |
| 4521 |
|
| 4522 |
function next(ret) { |
| 4523 |
if (ret.done) return resolve(ret.value); |
| 4524 |
var value = toPromise.call(ctx, ret.value); |
| 4525 |
if (value && isPromise(value)) return value.then(onFulfilled, onRejected); |
| 4526 |
return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, ' |
| 4527 |
+ 'but the following object was passed: "' + String(ret.value) + '"')); |
| 4528 |
} |
| 4529 |
}); |
| 4530 |
} |
| 4531 |
|
| 4532 |
/** |
| 4533 |
* Convert a `yield`ed value into a promise. |
| 4534 |
* |
| 4535 |
* @param {Mixed} obj |
| 4536 |
* @return {Promise} |
| 4537 |
* @api private |
| 4538 |
*/ |
| 4539 |
|
| 4540 |
function toPromise(obj) { |
| 4541 |
if (!obj) return obj; |
| 4542 |
if (isPromise(obj)) return obj; |
| 4543 |
if (isGeneratorFunction(obj) || isGenerator(obj)) return co.call(this, obj); |
| 4544 |
if ('function' == typeof obj) return thunkToPromise.call(this, obj); |
| 4545 |
if (Array.isArray(obj)) return arrayToPromise.call(this, obj); |
| 4546 |
if (isObject(obj)) return objectToPromise.call(this, obj); |
| 4547 |
return obj; |
| 4548 |
} |
| 4549 |
|
| 4550 |
/** |
| 4551 |
* Convert a thunk to a promise. |
| 4552 |
* |
| 4553 |
* @param {Function} |
| 4554 |
* @return {Promise} |
| 4555 |
* @api private |
| 4556 |
*/ |
| 4557 |
|
| 4558 |
function thunkToPromise(fn) { |
| 4559 |
var ctx = this; |
| 4560 |
return new Promise(function (resolve, reject) { |
| 4561 |
fn.call(ctx, function (err, res) { |
| 4562 |
if (err) return reject(err); |
| 4563 |
if (arguments.length > 2) res = slice.call(arguments, 1); |
| 4564 |
resolve(res); |
| 4565 |
}); |
| 4566 |
}); |
| 4567 |
} |
| 4568 |
|
| 4569 |
/** |
| 4570 |
* Convert an array of "yieldables" to a promise. |
| 4571 |
* Uses `Promise.all()` internally. |
| 4572 |
* |
| 4573 |
* @param {Array} obj |
| 4574 |
* @return {Promise} |
| 4575 |
* @api private |
| 4576 |
*/ |
| 4577 |
|
| 4578 |
function arrayToPromise(obj) { |
| 4579 |
return Promise.all(obj.map(toPromise, this)); |
| 4580 |
} |
| 4581 |
|
| 4582 |
/** |
| 4583 |
* Convert an object of "yieldables" to a promise. |
| 4584 |
* Uses `Promise.all()` internally. |
| 4585 |
* |
| 4586 |
* @param {Object} obj |
| 4587 |
* @return {Promise} |
| 4588 |
* @api private |
| 4589 |
*/ |
| 4590 |
|
| 4591 |
function objectToPromise(obj){ |
| 4592 |
var results = new obj.constructor(); |
| 4593 |
var keys = Object.keys(obj); |
| 4594 |
var promises = []; |
| 4595 |
for (var i = 0; i < keys.length; i++) { |
| 4596 |
var key = keys[i]; |
| 4597 |
var promise = toPromise.call(this, obj[key]); |
| 4598 |
if (promise && isPromise(promise)) defer(promise, key); |
| 4599 |
else results[key] = obj[key]; |
| 4600 |
} |
| 4601 |
return Promise.all(promises).then(function () { |
| 4602 |
return results; |
| 4603 |
}); |
| 4604 |
|
| 4605 |
function defer(promise, key) { |
| 4606 |
// predefine the key in the result |
| 4607 |
results[key] = undefined; |
| 4608 |
promises.push(promise.then(function (res) { |
| 4609 |
results[key] = res; |
| 4610 |
})); |
| 4611 |
} |
| 4612 |
} |
| 4613 |
|
| 4614 |
/** |
| 4615 |
* Check if `obj` is a promise. |
| 4616 |
* |
| 4617 |
* @param {Object} obj |
| 4618 |
* @return {Boolean} |
| 4619 |
* @api private |
| 4620 |
*/ |
| 4621 |
|
| 4622 |
function isPromise(obj) { |
| 4623 |
return 'function' == typeof obj.then; |
| 4624 |
} |
| 4625 |
|
| 4626 |
/** |
| 4627 |
* Check if `obj` is a generator. |
| 4628 |
* |
| 4629 |
* @param {Mixed} obj |
| 4630 |
* @return {Boolean} |
| 4631 |
* @api private |
| 4632 |
*/ |
| 4633 |
|
| 4634 |
function isGenerator(obj) { |
| 4635 |
return 'function' == typeof obj.next && 'function' == typeof obj.throw; |
| 4636 |
} |
| 4637 |
|
| 4638 |
/** |
| 4639 |
* Check if `obj` is a generator function. |
| 4640 |
* |
| 4641 |
* @param {Mixed} obj |
| 4642 |
* @return {Boolean} |
| 4643 |
* @api private |
| 4644 |
*/ |
| 4645 |
function isGeneratorFunction(obj) { |
| 4646 |
var constructor = obj.constructor; |
| 4647 |
if (!constructor) return false; |
| 4648 |
if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true; |
| 4649 |
return isGenerator(constructor.prototype); |
| 4650 |
} |
| 4651 |
|
| 4652 |
/** |
| 4653 |
* Check for plain object. |
| 4654 |
* |
| 4655 |
* @param {Mixed} val |
| 4656 |
* @return {Boolean} |
| 4657 |
* @api private |
| 4658 |
*/ |
| 4659 |
|
| 4660 |
function isObject(val) { |
| 4661 |
return Object == val.constructor; |
| 4662 |
} |
| 4663 |
|
| 4664 |
|
| 4665 |
/***/ }, |
| 4666 |
/* 20 */ |
| 4667 |
/***/ function(module, exports) { |
| 4668 |
|
| 4669 |
'use strict'; |
| 4670 |
|
| 4671 |
module.exports = ValidationError; |
| 4672 |
|
| 4673 |
|
| 4674 |
function ValidationError(errors) { |
| 4675 |
this.message = 'validation failed'; |
| 4676 |
this.errors = errors; |
| 4677 |
this.ajv = this.validation = true; |
| 4678 |
} |
| 4679 |
|
| 4680 |
|
| 4681 |
ValidationError.prototype = Object.create(Error.prototype); |
| 4682 |
ValidationError.prototype.constructor = ValidationError; |
| 4683 |
|
| 4684 |
|
| 4685 |
/***/ }, |
| 4686 |
/* 21 */ |
| 4687 |
/***/ function(module, exports) { |
| 4688 |
|
| 4689 |
'use strict'; |
| 4690 |
|
| 4691 |
|
| 4692 |
var Cache = module.exports = function Cache() { |
| 4693 |
this._cache = {}; |
| 4694 |
}; |
| 4695 |
|
| 4696 |
|
| 4697 |
Cache.prototype.put = function Cache_put(key, value) { |
| 4698 |
this._cache[key] = value; |
| 4699 |
}; |
| 4700 |
|
| 4701 |
|
| 4702 |
Cache.prototype.get = function Cache_get(key) { |
| 4703 |
return this._cache[key]; |
| 4704 |
}; |
| 4705 |
|
| 4706 |
|
| 4707 |
Cache.prototype.del = function Cache_del(key) { |
| 4708 |
delete this._cache[key]; |
| 4709 |
}; |
| 4710 |
|
| 4711 |
|
| 4712 |
Cache.prototype.clear = function Cache_clear() { |
| 4713 |
this._cache = {}; |
| 4714 |
}; |
| 4715 |
|
| 4716 |
|
| 4717 |
/***/ }, |
| 4718 |
/* 22 */ |
| 4719 |
/***/ function(module, exports, __webpack_require__) { |
| 4720 |
|
| 4721 |
'use strict'; |
| 4722 |
|
| 4723 |
var util = __webpack_require__(11); |
| 4724 |
|
| 4725 |
var DATE = /^\d\d\d\d-(\d\d)-(\d\d)$/; |
| 4726 |
var DAYS = [0,31,29,31,30,31,30,31,31,30,31,30,31]; |
| 4727 |
var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i; |
| 4728 |
var HOSTNAME = /^[a-z](?:(?:[-0-9a-z]{0,61})?[0-9a-z])?(\.[a-z](?:(?:[-0-9a-z]{0,61})?[0-9a-z])?)*$/i; |
| 4729 |
var URI = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9a-f]{2})*)?(?:\#(?:[a-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9a-f]{2})*)?$/i; |
| 4730 |
var UUID = /^(?:urn\:uuid\:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i; |
| 4731 |
var JSON_POINTER = /^(?:\/(?:[^~\/]|~0|~1)+)*(?:\/)?$|^\#(?:\/(?:[a-z0-9_\-\.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)+)*(?:\/)?$/i; |
| 4732 |
var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:\#|(?:\/(?:[^~\/]|~0|~1)+)*(?:\/)?)$/; |
| 4733 |
|
| 4734 |
|
| 4735 |
module.exports = formats; |
| 4736 |
|
| 4737 |
function formats(mode) { |
| 4738 |
mode = mode == 'full' ? 'full' : 'fast'; |
| 4739 |
var formatDefs = util.copy(formats[mode]); |
| 4740 |
for (var fName in formats.compare) { |
| 4741 |
formatDefs[fName] = { |
| 4742 |
validate: formatDefs[fName], |
| 4743 |
compare: formats.compare[fName] |
| 4744 |
}; |
| 4745 |
} |
| 4746 |
return formatDefs; |
| 4747 |
} |
| 4748 |
|
| 4749 |
|
| 4750 |
formats.fast = { |
| 4751 |
// date: http://tools.ietf.org/html/rfc3339#section-5.6 |
| 4752 |
date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/, |
| 4753 |
// date-time: http://tools.ietf.org/html/rfc3339#section-5.6 |
| 4754 |
time: /^[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i, |
| 4755 |
'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s][0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i, |
| 4756 |
// uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js |
| 4757 |
uri: /^(?:[a-z][a-z0-9+-.]*)?(?:\:|\/)\/?[^\s]*$/i, |
| 4758 |
// email (sources from jsen validator): |
| 4759 |
// http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363 |
| 4760 |
// http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation') |
| 4761 |
email: /^[a-z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i, |
| 4762 |
hostname: HOSTNAME, |
| 4763 |
// optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html |
| 4764 |
ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, |
| 4765 |
// optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses |
| 4766 |
ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i, |
| 4767 |
regex: regex, |
| 4768 |
// uuid: http://tools.ietf.org/html/rfc4122 |
| 4769 |
uuid: UUID, |
| 4770 |
// JSON-pointer: https://tools.ietf.org/html/rfc6901 |
| 4771 |
// uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A |
| 4772 |
'json-pointer': JSON_POINTER, |
| 4773 |
// relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00 |
| 4774 |
'relative-json-pointer': RELATIVE_JSON_POINTER |
| 4775 |
}; |
| 4776 |
|
| 4777 |
|
| 4778 |
formats.full = { |
| 4779 |
date: date, |
| 4780 |
time: time, |
| 4781 |
'date-time': date_time, |
| 4782 |
uri: uri, |
| 4783 |
email: /^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&''*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i, |
| 4784 |
hostname: hostname, |
| 4785 |
ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/, |
| 4786 |
ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i, |
| 4787 |
regex: regex, |
| 4788 |
uuid: UUID, |
| 4789 |
'json-pointer': JSON_POINTER, |
| 4790 |
'relative-json-pointer': RELATIVE_JSON_POINTER |
| 4791 |
}; |
| 4792 |
|
| 4793 |
|
| 4794 |
formats.compare = { |
| 4795 |
date: compareDate, |
| 4796 |
time: compareTime, |
| 4797 |
'date-time': compareDateTime |
| 4798 |
}; |
| 4799 |
|
| 4800 |
|
| 4801 |
function date(str) { |
| 4802 |
// full-date from http://tools.ietf.org/html/rfc3339#section-5.6 |
| 4803 |
var matches = str.match(DATE); |
| 4804 |
if (!matches) return false; |
| 4805 |
|
| 4806 |
var month = +matches[1]; |
| 4807 |
var day = +matches[2]; |
| 4808 |
return month >= 1 && month <= 12 && day >= 1 && day <= DAYS[month]; |
| 4809 |
} |
| 4810 |
|
| 4811 |
|
| 4812 |
function time(str, full) { |
| 4813 |
var matches = str.match(TIME); |
| 4814 |
if (!matches) return false; |
| 4815 |
|
| 4816 |
var hour = matches[1]; |
| 4817 |
var minute = matches[2]; |
| 4818 |
var second = matches[3]; |
| 4819 |
var timeZone = matches[5]; |
| 4820 |
return hour <= 23 && minute <= 59 && second <= 59 && (!full || timeZone); |
| 4821 |
} |
| 4822 |
|
| 4823 |
|
| 4824 |
var DATE_TIME_SEPARATOR = /t|\s/i; |
| 4825 |
function date_time(str) { |
| 4826 |
// http://tools.ietf.org/html/rfc3339#section-5.6 |
| 4827 |
var dateTime = str.split(DATE_TIME_SEPARATOR); |
| 4828 |
return date(dateTime[0]) && time(dateTime[1], true); |
| 4829 |
} |
| 4830 |
|
| 4831 |
|
| 4832 |
function hostname(str) { |
| 4833 |
// http://tools.ietf.org/html/rfc1034#section-3.5 |
| 4834 |
return str.length <= 255 && HOSTNAME.test(str); |
| 4835 |
} |
| 4836 |
|
| 4837 |
|
| 4838 |
var NOT_URI_FRAGMENT = /\/|\:/; |
| 4839 |
function uri(str) { |
| 4840 |
// http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "." |
| 4841 |
return NOT_URI_FRAGMENT.test(str) && URI.test(str); |
| 4842 |
} |
| 4843 |
|
| 4844 |
|
| 4845 |
function regex(str) { |
| 4846 |
try { |
| 4847 |
new RegExp(str); |
| 4848 |
return true; |
| 4849 |
} catch(e) { |
| 4850 |
return false; |
| 4851 |
} |
| 4852 |
} |
| 4853 |
|
| 4854 |
|
| 4855 |
function compareDate(d1, d2) { |
| 4856 |
if (!(d1 && d2)) return; |
| 4857 |
if (d1 > d2) return 1; |
| 4858 |
if (d1 < d2) return -1; |
| 4859 |
if (d1 === d2) return 0; |
| 4860 |
} |
| 4861 |
|
| 4862 |
|
| 4863 |
function compareTime(t1, t2) { |
| 4864 |
if (!(t1 && t2)) return; |
| 4865 |
t1 = t1.match(TIME); |
| 4866 |
t2 = t2.match(TIME); |
| 4867 |
if (!(t1 && t2)) return; |
| 4868 |
t1 = t1[1] + t1[2] + t1[3] + (t1[4]||''); |
| 4869 |
t2 = t2[1] + t2[2] + t2[3] + (t2[4]||''); |
| 4870 |
if (t1 > t2) return 1; |
| 4871 |
if (t1 < t2) return -1; |
| 4872 |
if (t1 === t2) return 0; |
| 4873 |
} |
| 4874 |
|
| 4875 |
|
| 4876 |
function compareDateTime(dt1, dt2) { |
| 4877 |
if (!(dt1 && dt2)) return; |
| 4878 |
dt1 = dt1.split(DATE_TIME_SEPARATOR); |
| 4879 |
dt2 = dt2.split(DATE_TIME_SEPARATOR); |
| 4880 |
var res = compareDate(dt1[0], dt2[0]); |
| 4881 |
if (res === undefined) return; |
| 4882 |
return res || compareTime(dt1[1], dt2[1]); |
| 4883 |
} |
| 4884 |
|
| 4885 |
|
| 4886 |
/***/ }, |
| 4887 |
/* 23 */ |
| 4888 |
/***/ function(module, exports, __webpack_require__) { |
| 4889 |
|
| 4890 |
'use strict'; |
| 4891 |
|
| 4892 |
var ruleModules = __webpack_require__(24) |
| 4893 |
, util = __webpack_require__(11); |
| 4894 |
|
| 4895 |
module.exports = function rules() { |
| 4896 |
var RULES = [ |
| 4897 |
{ type: 'number', |
| 4898 |
rules: [ 'maximum', 'minimum', 'multipleOf'] }, |
| 4899 |
{ type: 'string', |
| 4900 |
rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] }, |
| 4901 |
{ type: 'array', |
| 4902 |
rules: [ 'maxItems', 'minItems', 'uniqueItems', 'items' ] }, |
| 4903 |
{ type: 'object', |
| 4904 |
rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'properties' ] }, |
| 4905 |
{ rules: [ '$ref', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] } |
| 4906 |
]; |
| 4907 |
|
| 4908 |
RULES.all = [ 'type', 'additionalProperties', 'patternProperties' ]; |
| 4909 |
RULES.keywords = [ 'additionalItems', '$schema', 'id', 'title', 'description', 'default' ]; |
| 4910 |
RULES.types = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ]; |
| 4911 |
|
| 4912 |
RULES.forEach(function (group) { |
| 4913 |
group.rules = group.rules.map(function (keyword) { |
| 4914 |
RULES.all.push(keyword); |
| 4915 |
return { |
| 4916 |
keyword: keyword, |
| 4917 |
code: ruleModules[keyword] |
| 4918 |
}; |
| 4919 |
}); |
| 4920 |
}); |
| 4921 |
|
| 4922 |
RULES.keywords = util.toHash(RULES.all.concat(RULES.keywords)); |
| 4923 |
RULES.all = util.toHash(RULES.all); |
| 4924 |
RULES.types = util.toHash(RULES.types); |
| 4925 |
|
| 4926 |
return RULES; |
| 4927 |
}; |
| 4928 |
|
| 4929 |
|
| 4930 |
/***/ }, |
| 4931 |
/* 24 */ |
| 4932 |
/***/ function(module, exports, __webpack_require__) { |
| 4933 |
|
| 4934 |
'use strict'; |
| 4935 |
|
| 4936 |
//all requires must be explicit because browserify won't work with dynamic requires |
| 4937 |
module.exports = { |
| 4938 |
'$ref': __webpack_require__(25), |
| 4939 |
allOf: __webpack_require__(26), |
| 4940 |
anyOf: __webpack_require__(27), |
| 4941 |
dependencies: __webpack_require__(28), |
| 4942 |
enum: __webpack_require__(29), |
| 4943 |
format: __webpack_require__(30), |
| 4944 |
items: __webpack_require__(31), |
| 4945 |
maximum: __webpack_require__(32), |
| 4946 |
minimum: __webpack_require__(32), |
| 4947 |
maxItems: __webpack_require__(33), |
| 4948 |
minItems: __webpack_require__(33), |
| 4949 |
maxLength: __webpack_require__(34), |
| 4950 |
minLength: __webpack_require__(34), |
| 4951 |
maxProperties: __webpack_require__(35), |
| 4952 |
minProperties: __webpack_require__(35), |
| 4953 |
multipleOf: __webpack_require__(36), |
| 4954 |
not: __webpack_require__(37), |
| 4955 |
oneOf: __webpack_require__(38), |
| 4956 |
pattern: __webpack_require__(39), |
| 4957 |
properties: __webpack_require__(40), |
| 4958 |
required: __webpack_require__(41), |
| 4959 |
uniqueItems: __webpack_require__(42), |
| 4960 |
validate: __webpack_require__(18) |
| 4961 |
}; |
| 4962 |
|
| 4963 |
|
| 4964 |
/***/ }, |
| 4965 |
/* 25 */ |
| 4966 |
/***/ function(module, exports) { |
| 4967 |
|
| 4968 |
'use strict'; |
| 4969 |
module.exports = function generate_ref(it, $keyword) { |
| 4970 |
var out = ' '; |
| 4971 |
var $lvl = it.level; |
| 4972 |
var $dataLvl = it.dataLevel; |
| 4973 |
var $schema = it.schema[$keyword]; |
| 4974 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 4975 |
var $breakOnError = !it.opts.allErrors; |
| 4976 |
var $errorKeyword; |
| 4977 |
var $data = 'data' + ($dataLvl || ''); |
| 4978 |
var $valid = 'valid' + $lvl; |
| 4979 |
var $async, $refCode; |
| 4980 |
if ($schema == '#' || $schema == '#/') { |
| 4981 |
if (it.isRoot) { |
| 4982 |
$async = it.async; |
| 4983 |
$refCode = 'validate'; |
| 4984 |
} else { |
| 4985 |
$async = it.root.schema.$async === true; |
| 4986 |
$refCode = 'root.refVal[0]'; |
| 4987 |
} |
| 4988 |
} else { |
| 4989 |
var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot); |
| 4990 |
if ($refVal === undefined) { |
| 4991 |
var $message = 'can\'t resolve reference ' + $schema + ' from id ' + it.baseId; |
| 4992 |
if (it.opts.missingRefs == 'fail') { |
| 4993 |
console.log($message); |
| 4994 |
var $$outStack = $$outStack || []; |
| 4995 |
$$outStack.push(out); |
| 4996 |
out = ''; /* istanbul ignore else */ |
| 4997 |
if (it.createErrors !== false) { |
| 4998 |
out += ' { keyword: \'' + ($errorKeyword || '$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } '; |
| 4999 |
if (it.opts.messages !== false) { |
| 5000 |
out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' '; |
| 5001 |
} |
| 5002 |
if (it.opts.verbose) { |
| 5003 |
out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5004 |
} |
| 5005 |
out += ' } '; |
| 5006 |
} else { |
| 5007 |
out += ' {} '; |
| 5008 |
} |
| 5009 |
var __err = out; |
| 5010 |
out = $$outStack.pop(); |
| 5011 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 5012 |
if (it.async) { |
| 5013 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 5014 |
} else { |
| 5015 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 5016 |
} |
| 5017 |
} else { |
| 5018 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 5019 |
} |
| 5020 |
if ($breakOnError) { |
| 5021 |
out += ' if (false) { '; |
| 5022 |
} |
| 5023 |
} else if (it.opts.missingRefs == 'ignore') { |
| 5024 |
console.log($message); |
| 5025 |
if ($breakOnError) { |
| 5026 |
out += ' if (true) { '; |
| 5027 |
} |
| 5028 |
} else { |
| 5029 |
var $error = new Error($message); |
| 5030 |
$error.missingRef = it.resolve.url(it.baseId, $schema); |
| 5031 |
$error.missingSchema = it.resolve.normalizeId(it.resolve.fullPath($error.missingRef)); |
| 5032 |
throw $error; |
| 5033 |
} |
| 5034 |
} else if ($refVal.inline) { |
| 5035 |
var $it = it.util.copy(it); |
| 5036 |
$it.level++; |
| 5037 |
$it.schema = $refVal.schema; |
| 5038 |
$it.schemaPath = ''; |
| 5039 |
$it.errSchemaPath = $schema; |
| 5040 |
var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code); |
| 5041 |
out += ' ' + ($code) + ' '; |
| 5042 |
if ($breakOnError) { |
| 5043 |
out += ' if (valid' + ($it.level) + ') { '; |
| 5044 |
} |
| 5045 |
} else { |
| 5046 |
$async = $refVal.async; |
| 5047 |
$refCode = $refVal.code; |
| 5048 |
} |
| 5049 |
} |
| 5050 |
if ($refCode) { |
| 5051 |
var $$outStack = $$outStack || []; |
| 5052 |
$$outStack.push(out); |
| 5053 |
out = ''; |
| 5054 |
if (it.opts.passContext) { |
| 5055 |
out += ' ' + ($refCode) + '.call(this, '; |
| 5056 |
} else { |
| 5057 |
out += ' ' + ($refCode) + '( '; |
| 5058 |
} |
| 5059 |
out += ' ' + ($data) + ', (dataPath || \'\')'; |
| 5060 |
if (it.errorPath != '""') { |
| 5061 |
out += ' + ' + (it.errorPath); |
| 5062 |
} |
| 5063 |
if ($dataLvl) { |
| 5064 |
out += ' , data' + (($dataLvl - 1) || '') + ' , ' + (it.dataPathArr[$dataLvl]) + ' '; |
| 5065 |
} else { |
| 5066 |
out += ' , parentData , parentDataProperty '; |
| 5067 |
} |
| 5068 |
out += ') '; |
| 5069 |
var __callValidate = out; |
| 5070 |
out = $$outStack.pop(); |
| 5071 |
if ($async) { |
| 5072 |
if (!it.async) throw new Error('async schema referenced by sync schema'); |
| 5073 |
out += ' try { '; |
| 5074 |
if ($breakOnError) { |
| 5075 |
out += 'var ' + ($valid) + ' ='; |
| 5076 |
} |
| 5077 |
out += ' ' + (it.yieldAwait) + ' ' + (__callValidate) + '; } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; } '; |
| 5078 |
if ($breakOnError) { |
| 5079 |
out += ' if (' + ($valid) + ') { '; |
| 5080 |
} |
| 5081 |
} else { |
| 5082 |
out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } '; |
| 5083 |
if ($breakOnError) { |
| 5084 |
out += ' else { '; |
| 5085 |
} |
| 5086 |
} |
| 5087 |
} |
| 5088 |
return out; |
| 5089 |
} |
| 5090 |
|
| 5091 |
|
| 5092 |
/***/ }, |
| 5093 |
/* 26 */ |
| 5094 |
/***/ function(module, exports) { |
| 5095 |
|
| 5096 |
'use strict'; |
| 5097 |
module.exports = function generate_allOf(it, $keyword) { |
| 5098 |
var out = ' '; |
| 5099 |
var $schema = it.schema[$keyword]; |
| 5100 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5101 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5102 |
var $breakOnError = !it.opts.allErrors; |
| 5103 |
var $it = it.util.copy(it); |
| 5104 |
var $closingBraces = ''; |
| 5105 |
$it.level++; |
| 5106 |
var arr1 = $schema; |
| 5107 |
if (arr1) { |
| 5108 |
var $sch, $i = -1, |
| 5109 |
l1 = arr1.length - 1; |
| 5110 |
while ($i < l1) { |
| 5111 |
$sch = arr1[$i += 1]; |
| 5112 |
if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 5113 |
$it.schema = $sch; |
| 5114 |
$it.schemaPath = $schemaPath + '[' + $i + ']'; |
| 5115 |
$it.errSchemaPath = $errSchemaPath + '/' + $i; |
| 5116 |
out += ' ' + (it.validate($it)) + ' '; |
| 5117 |
if ($breakOnError) { |
| 5118 |
out += ' if (valid' + ($it.level) + ') { '; |
| 5119 |
$closingBraces += '}'; |
| 5120 |
} |
| 5121 |
} |
| 5122 |
} |
| 5123 |
} |
| 5124 |
if ($breakOnError) { |
| 5125 |
out += ' ' + ($closingBraces.slice(0, -1)); |
| 5126 |
} |
| 5127 |
out = it.util.cleanUpCode(out); |
| 5128 |
return out; |
| 5129 |
} |
| 5130 |
|
| 5131 |
|
| 5132 |
/***/ }, |
| 5133 |
/* 27 */ |
| 5134 |
/***/ function(module, exports) { |
| 5135 |
|
| 5136 |
'use strict'; |
| 5137 |
module.exports = function generate_anyOf(it, $keyword) { |
| 5138 |
var out = ' '; |
| 5139 |
var $lvl = it.level; |
| 5140 |
var $dataLvl = it.dataLevel; |
| 5141 |
var $schema = it.schema[$keyword]; |
| 5142 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5143 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5144 |
var $breakOnError = !it.opts.allErrors; |
| 5145 |
var $errorKeyword; |
| 5146 |
var $data = 'data' + ($dataLvl || ''); |
| 5147 |
var $valid = 'valid' + $lvl; |
| 5148 |
var $errs = 'errs__' + $lvl; |
| 5149 |
var $it = it.util.copy(it); |
| 5150 |
var $closingBraces = ''; |
| 5151 |
$it.level++; |
| 5152 |
var $noEmptySchema = $schema.every(function($sch) { |
| 5153 |
return it.util.schemaHasRules($sch, it.RULES.all); |
| 5154 |
}); |
| 5155 |
if ($noEmptySchema) { |
| 5156 |
out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; '; |
| 5157 |
var $wasComposite = it.compositeRule; |
| 5158 |
it.compositeRule = $it.compositeRule = true; |
| 5159 |
var arr1 = $schema; |
| 5160 |
if (arr1) { |
| 5161 |
var $sch, $i = -1, |
| 5162 |
l1 = arr1.length - 1; |
| 5163 |
while ($i < l1) { |
| 5164 |
$sch = arr1[$i += 1]; |
| 5165 |
$it.schema = $sch; |
| 5166 |
$it.schemaPath = $schemaPath + '[' + $i + ']'; |
| 5167 |
$it.errSchemaPath = $errSchemaPath + '/' + $i; |
| 5168 |
out += ' ' + (it.validate($it)) + ' ' + ($valid) + ' = ' + ($valid) + ' || valid' + ($it.level) + '; if (!' + ($valid) + ') { '; |
| 5169 |
$closingBraces += '}'; |
| 5170 |
} |
| 5171 |
} |
| 5172 |
it.compositeRule = $it.compositeRule = $wasComposite; |
| 5173 |
out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */ |
| 5174 |
if (it.createErrors !== false) { |
| 5175 |
out += ' { keyword: \'' + ($errorKeyword || 'anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} '; |
| 5176 |
if (it.opts.messages !== false) { |
| 5177 |
out += ' , message: \'should match some schema in anyOf\' '; |
| 5178 |
} |
| 5179 |
if (it.opts.verbose) { |
| 5180 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5181 |
} |
| 5182 |
out += ' } '; |
| 5183 |
} else { |
| 5184 |
out += ' {} '; |
| 5185 |
} |
| 5186 |
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } '; |
| 5187 |
if (it.opts.allErrors) { |
| 5188 |
out += ' } '; |
| 5189 |
} |
| 5190 |
out = it.util.cleanUpCode(out); |
| 5191 |
} else { |
| 5192 |
if ($breakOnError) { |
| 5193 |
out += ' if (true) { '; |
| 5194 |
} |
| 5195 |
} |
| 5196 |
return out; |
| 5197 |
} |
| 5198 |
|
| 5199 |
|
| 5200 |
/***/ }, |
| 5201 |
/* 28 */ |
| 5202 |
/***/ function(module, exports) { |
| 5203 |
|
| 5204 |
'use strict'; |
| 5205 |
module.exports = function generate_dependencies(it, $keyword) { |
| 5206 |
var out = ' '; |
| 5207 |
var $lvl = it.level; |
| 5208 |
var $dataLvl = it.dataLevel; |
| 5209 |
var $schema = it.schema[$keyword]; |
| 5210 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5211 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5212 |
var $breakOnError = !it.opts.allErrors; |
| 5213 |
var $errorKeyword; |
| 5214 |
var $data = 'data' + ($dataLvl || ''); |
| 5215 |
var $errs = 'errs__' + $lvl; |
| 5216 |
var $it = it.util.copy(it); |
| 5217 |
var $closingBraces = ''; |
| 5218 |
$it.level++; |
| 5219 |
var $schemaDeps = {}, |
| 5220 |
$propertyDeps = {}; |
| 5221 |
for ($property in $schema) { |
| 5222 |
var $sch = $schema[$property]; |
| 5223 |
var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps; |
| 5224 |
$deps[$property] = $sch; |
| 5225 |
} |
| 5226 |
out += 'var ' + ($errs) + ' = errors;'; |
| 5227 |
var $currentErrorPath = it.errorPath; |
| 5228 |
out += 'var missing' + ($lvl) + ';'; |
| 5229 |
for (var $property in $propertyDeps) { |
| 5230 |
$deps = $propertyDeps[$property]; |
| 5231 |
out += ' if (' + ($data) + (it.util.getProperty($property)) + ' !== undefined && ( '; |
| 5232 |
var arr1 = $deps; |
| 5233 |
if (arr1) { |
| 5234 |
var _$property, $i = -1, |
| 5235 |
l1 = arr1.length - 1; |
| 5236 |
while ($i < l1) { |
| 5237 |
_$property = arr1[$i += 1]; |
| 5238 |
if ($i) { |
| 5239 |
out += ' || '; |
| 5240 |
} |
| 5241 |
var $prop = it.util.getProperty(_$property); |
| 5242 |
out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) '; |
| 5243 |
} |
| 5244 |
} |
| 5245 |
out += ')) { '; |
| 5246 |
var $propertyPath = 'missing' + $lvl, |
| 5247 |
$missingProperty = '\' + ' + $propertyPath + ' + \''; |
| 5248 |
if (it.opts._errorDataPathProperty) { |
| 5249 |
it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath; |
| 5250 |
} |
| 5251 |
var $$outStack = $$outStack || []; |
| 5252 |
$$outStack.push(out); |
| 5253 |
out = ''; /* istanbul ignore else */ |
| 5254 |
if (it.createErrors !== false) { |
| 5255 |
out += ' { keyword: \'' + ($errorKeyword || 'dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } '; |
| 5256 |
if (it.opts.messages !== false) { |
| 5257 |
out += ' , message: \'should have '; |
| 5258 |
if ($deps.length == 1) { |
| 5259 |
out += 'property ' + (it.util.escapeQuotes($deps[0])); |
| 5260 |
} else { |
| 5261 |
out += 'properties ' + (it.util.escapeQuotes($deps.join(", "))); |
| 5262 |
} |
| 5263 |
out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' '; |
| 5264 |
} |
| 5265 |
if (it.opts.verbose) { |
| 5266 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5267 |
} |
| 5268 |
out += ' } '; |
| 5269 |
} else { |
| 5270 |
out += ' {} '; |
| 5271 |
} |
| 5272 |
var __err = out; |
| 5273 |
out = $$outStack.pop(); |
| 5274 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 5275 |
if (it.async) { |
| 5276 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 5277 |
} else { |
| 5278 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 5279 |
} |
| 5280 |
} else { |
| 5281 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 5282 |
} |
| 5283 |
out += ' } '; |
| 5284 |
if ($breakOnError) { |
| 5285 |
$closingBraces += '}'; |
| 5286 |
out += ' else { '; |
| 5287 |
} |
| 5288 |
} |
| 5289 |
it.errorPath = $currentErrorPath; |
| 5290 |
for (var $property in $schemaDeps) { |
| 5291 |
var $sch = $schemaDeps[$property]; |
| 5292 |
if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 5293 |
out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '[\'' + ($property) + '\'] !== undefined) { '; |
| 5294 |
$it.schema = $sch; |
| 5295 |
$it.schemaPath = $schemaPath + it.util.getProperty($property); |
| 5296 |
$it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property); |
| 5297 |
out += ' ' + (it.validate($it)) + ' } '; |
| 5298 |
if ($breakOnError) { |
| 5299 |
out += ' if (valid' + ($it.level) + ') { '; |
| 5300 |
$closingBraces += '}'; |
| 5301 |
} |
| 5302 |
} |
| 5303 |
} |
| 5304 |
if ($breakOnError) { |
| 5305 |
out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {'; |
| 5306 |
} |
| 5307 |
out = it.util.cleanUpCode(out); |
| 5308 |
return out; |
| 5309 |
} |
| 5310 |
|
| 5311 |
|
| 5312 |
/***/ }, |
| 5313 |
/* 29 */ |
| 5314 |
/***/ function(module, exports) { |
| 5315 |
|
| 5316 |
'use strict'; |
| 5317 |
module.exports = function generate_enum(it, $keyword) { |
| 5318 |
var out = ' '; |
| 5319 |
var $lvl = it.level; |
| 5320 |
var $dataLvl = it.dataLevel; |
| 5321 |
var $schema = it.schema[$keyword]; |
| 5322 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5323 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5324 |
var $breakOnError = !it.opts.allErrors; |
| 5325 |
var $errorKeyword; |
| 5326 |
var $data = 'data' + ($dataLvl || ''); |
| 5327 |
var $valid = 'valid' + $lvl; |
| 5328 |
var $isData = it.opts.v5 && $schema.$data; |
| 5329 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 5330 |
if ($isData) { |
| 5331 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 5332 |
$schemaValue = 'schema' + $lvl; |
| 5333 |
} |
| 5334 |
var $i = 'i' + $lvl; |
| 5335 |
if (!$isData) { |
| 5336 |
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';'; |
| 5337 |
} |
| 5338 |
out += 'var ' + ($valid) + ';'; |
| 5339 |
if ($isData) { |
| 5340 |
out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {'; |
| 5341 |
} |
| 5342 |
out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<schema' + ($lvl) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', schema' + ($lvl) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }'; |
| 5343 |
if ($isData) { |
| 5344 |
out += ' } '; |
| 5345 |
} |
| 5346 |
out += ' if (!' + ($valid) + ') { '; |
| 5347 |
var $$outStack = $$outStack || []; |
| 5348 |
$$outStack.push(out); |
| 5349 |
out = ''; /* istanbul ignore else */ |
| 5350 |
if (it.createErrors !== false) { |
| 5351 |
out += ' { keyword: \'' + ($errorKeyword || 'enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} '; |
| 5352 |
if (it.opts.messages !== false) { |
| 5353 |
out += ' , message: \'should be equal to one of the allowed values\' '; |
| 5354 |
} |
| 5355 |
if (it.opts.verbose) { |
| 5356 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5357 |
} |
| 5358 |
out += ' } '; |
| 5359 |
} else { |
| 5360 |
out += ' {} '; |
| 5361 |
} |
| 5362 |
var __err = out; |
| 5363 |
out = $$outStack.pop(); |
| 5364 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 5365 |
if (it.async) { |
| 5366 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 5367 |
} else { |
| 5368 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 5369 |
} |
| 5370 |
} else { |
| 5371 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 5372 |
} |
| 5373 |
out += ' }'; |
| 5374 |
if ($breakOnError) { |
| 5375 |
out += ' else { '; |
| 5376 |
} |
| 5377 |
return out; |
| 5378 |
} |
| 5379 |
|
| 5380 |
|
| 5381 |
/***/ }, |
| 5382 |
/* 30 */ |
| 5383 |
/***/ function(module, exports) { |
| 5384 |
|
| 5385 |
'use strict'; |
| 5386 |
module.exports = function generate_format(it, $keyword) { |
| 5387 |
var out = ' '; |
| 5388 |
var $lvl = it.level; |
| 5389 |
var $dataLvl = it.dataLevel; |
| 5390 |
var $schema = it.schema[$keyword]; |
| 5391 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5392 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5393 |
var $breakOnError = !it.opts.allErrors; |
| 5394 |
var $errorKeyword; |
| 5395 |
var $data = 'data' + ($dataLvl || ''); |
| 5396 |
if (it.opts.format === false) { |
| 5397 |
if ($breakOnError) { |
| 5398 |
out += ' if (true) { '; |
| 5399 |
} |
| 5400 |
return out; |
| 5401 |
} |
| 5402 |
var $isData = it.opts.v5 && $schema.$data; |
| 5403 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 5404 |
if ($isData) { |
| 5405 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 5406 |
$schemaValue = 'schema' + $lvl; |
| 5407 |
} |
| 5408 |
if ($isData) { |
| 5409 |
var $format = 'format' + $lvl; |
| 5410 |
out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var isObject' + ($lvl) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; if (isObject' + ($lvl) + ') { var async' + ($lvl) + ' = ' + ($format) + '.async; ' + ($format) + ' = ' + ($format) + '.validate; } if ( '; |
| 5411 |
if ($isData) { |
| 5412 |
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || '; |
| 5413 |
} |
| 5414 |
out += ' (' + ($format) + ' && !(typeof ' + ($format) + ' == \'function\' ? '; |
| 5415 |
if (it.async) { |
| 5416 |
out += ' (async' + ($lvl) + ' ? ' + (it.yieldAwait) + ' ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) '; |
| 5417 |
} else { |
| 5418 |
out += ' ' + ($format) + '(' + ($data) + ') '; |
| 5419 |
} |
| 5420 |
out += ' : ' + ($format) + '.test(' + ($data) + ')))) {'; |
| 5421 |
} else { |
| 5422 |
var $format = it.formats[$schema]; |
| 5423 |
if (!$format) { |
| 5424 |
if ($breakOnError) { |
| 5425 |
out += ' if (true) { '; |
| 5426 |
} |
| 5427 |
return out; |
| 5428 |
} |
| 5429 |
var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate; |
| 5430 |
if ($isObject) { |
| 5431 |
var $async = $format.async === true; |
| 5432 |
$format = $format.validate; |
| 5433 |
} |
| 5434 |
if ($async) { |
| 5435 |
if (!it.async) throw new Error('async format in sync schema'); |
| 5436 |
var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate'; |
| 5437 |
out += ' if (!(' + (it.yieldAwait) + ' ' + ($formatRef) + '(' + ($data) + '))) { '; |
| 5438 |
} else { |
| 5439 |
out += ' if (! '; |
| 5440 |
var $formatRef = 'formats' + it.util.getProperty($schema); |
| 5441 |
if ($isObject) $formatRef += '.validate'; |
| 5442 |
if (typeof $format == 'function') { |
| 5443 |
out += ' ' + ($formatRef) + '(' + ($data) + ') '; |
| 5444 |
} else { |
| 5445 |
out += ' ' + ($formatRef) + '.test(' + ($data) + ') '; |
| 5446 |
} |
| 5447 |
out += ') { '; |
| 5448 |
} |
| 5449 |
} |
| 5450 |
var $$outStack = $$outStack || []; |
| 5451 |
$$outStack.push(out); |
| 5452 |
out = ''; /* istanbul ignore else */ |
| 5453 |
if (it.createErrors !== false) { |
| 5454 |
out += ' { keyword: \'' + ($errorKeyword || 'format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { format: '; |
| 5455 |
if ($isData) { |
| 5456 |
out += '' + ($schemaValue); |
| 5457 |
} else { |
| 5458 |
out += '' + (it.util.toQuotedString($schema)); |
| 5459 |
} |
| 5460 |
out += ' } '; |
| 5461 |
if (it.opts.messages !== false) { |
| 5462 |
out += ' , message: \'should match format "'; |
| 5463 |
if ($isData) { |
| 5464 |
out += '\' + ' + ($schemaValue) + ' + \''; |
| 5465 |
} else { |
| 5466 |
out += '' + (it.util.escapeQuotes($schema)); |
| 5467 |
} |
| 5468 |
out += '"\' '; |
| 5469 |
} |
| 5470 |
if (it.opts.verbose) { |
| 5471 |
out += ' , schema: '; |
| 5472 |
if ($isData) { |
| 5473 |
out += 'validate.schema' + ($schemaPath); |
| 5474 |
} else { |
| 5475 |
out += '' + (it.util.toQuotedString($schema)); |
| 5476 |
} |
| 5477 |
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5478 |
} |
| 5479 |
out += ' } '; |
| 5480 |
} else { |
| 5481 |
out += ' {} '; |
| 5482 |
} |
| 5483 |
var __err = out; |
| 5484 |
out = $$outStack.pop(); |
| 5485 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 5486 |
if (it.async) { |
| 5487 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 5488 |
} else { |
| 5489 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 5490 |
} |
| 5491 |
} else { |
| 5492 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 5493 |
} |
| 5494 |
out += ' } '; |
| 5495 |
if ($breakOnError) { |
| 5496 |
out += ' else { '; |
| 5497 |
} |
| 5498 |
return out; |
| 5499 |
} |
| 5500 |
|
| 5501 |
|
| 5502 |
/***/ }, |
| 5503 |
/* 31 */ |
| 5504 |
/***/ function(module, exports) { |
| 5505 |
|
| 5506 |
'use strict'; |
| 5507 |
module.exports = function generate_items(it, $keyword) { |
| 5508 |
var out = ' '; |
| 5509 |
var $lvl = it.level; |
| 5510 |
var $dataLvl = it.dataLevel; |
| 5511 |
var $schema = it.schema[$keyword]; |
| 5512 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5513 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5514 |
var $breakOnError = !it.opts.allErrors; |
| 5515 |
var $errorKeyword; |
| 5516 |
var $data = 'data' + ($dataLvl || ''); |
| 5517 |
var $valid = 'valid' + $lvl; |
| 5518 |
var $errs = 'errs__' + $lvl; |
| 5519 |
var $it = it.util.copy(it); |
| 5520 |
var $closingBraces = ''; |
| 5521 |
$it.level++; |
| 5522 |
var $dataNxt = $it.dataLevel = it.dataLevel + 1, |
| 5523 |
$nextData = 'data' + $dataNxt; |
| 5524 |
out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';'; |
| 5525 |
if (Array.isArray($schema)) { |
| 5526 |
var $additionalItems = it.schema.additionalItems; |
| 5527 |
if ($additionalItems === false) { |
| 5528 |
out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; '; |
| 5529 |
var $currErrSchemaPath = $errSchemaPath; |
| 5530 |
$errSchemaPath = it.errSchemaPath + '/additionalItems'; |
| 5531 |
out += ' if (!' + ($valid) + ') { '; |
| 5532 |
var $$outStack = $$outStack || []; |
| 5533 |
$$outStack.push(out); |
| 5534 |
out = ''; /* istanbul ignore else */ |
| 5535 |
if (it.createErrors !== false) { |
| 5536 |
out += ' { keyword: \'' + ($errorKeyword || 'additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schema.length) + ' } '; |
| 5537 |
if (it.opts.messages !== false) { |
| 5538 |
out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' '; |
| 5539 |
} |
| 5540 |
if (it.opts.verbose) { |
| 5541 |
out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5542 |
} |
| 5543 |
out += ' } '; |
| 5544 |
} else { |
| 5545 |
out += ' {} '; |
| 5546 |
} |
| 5547 |
var __err = out; |
| 5548 |
out = $$outStack.pop(); |
| 5549 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 5550 |
if (it.async) { |
| 5551 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 5552 |
} else { |
| 5553 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 5554 |
} |
| 5555 |
} else { |
| 5556 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 5557 |
} |
| 5558 |
out += ' } '; |
| 5559 |
$errSchemaPath = $currErrSchemaPath; |
| 5560 |
if ($breakOnError) { |
| 5561 |
$closingBraces += '}'; |
| 5562 |
out += ' else { '; |
| 5563 |
} |
| 5564 |
} |
| 5565 |
var arr1 = $schema; |
| 5566 |
if (arr1) { |
| 5567 |
var $sch, $i = -1, |
| 5568 |
l1 = arr1.length - 1; |
| 5569 |
while ($i < l1) { |
| 5570 |
$sch = arr1[$i += 1]; |
| 5571 |
if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 5572 |
out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { '; |
| 5573 |
var $passData = $data + '[' + $i + ']'; |
| 5574 |
$it.schema = $sch; |
| 5575 |
$it.schemaPath = $schemaPath + '[' + $i + ']'; |
| 5576 |
$it.errSchemaPath = $errSchemaPath + '/' + $i; |
| 5577 |
$it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true); |
| 5578 |
$it.dataPathArr[$dataNxt] = $i; |
| 5579 |
var $code = it.validate($it); |
| 5580 |
if (it.util.varOccurences($code, $nextData) < 2) { |
| 5581 |
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 5582 |
} else { |
| 5583 |
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 5584 |
} |
| 5585 |
out += ' } '; |
| 5586 |
if ($breakOnError) { |
| 5587 |
out += ' if (valid' + ($it.level) + ') { '; |
| 5588 |
$closingBraces += '}'; |
| 5589 |
} |
| 5590 |
} |
| 5591 |
} |
| 5592 |
} |
| 5593 |
if (typeof $additionalItems == 'object' && it.util.schemaHasRules($additionalItems, it.RULES.all)) { |
| 5594 |
$it.schema = $additionalItems; |
| 5595 |
$it.schemaPath = it.schemaPath + '.additionalItems'; |
| 5596 |
$it.errSchemaPath = it.errSchemaPath + '/additionalItems'; |
| 5597 |
out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var i' + ($lvl) + ' = ' + ($schema.length) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { '; |
| 5598 |
$it.errorPath = it.util.getPathExpr(it.errorPath, 'i' + $lvl, it.opts.jsonPointers, true); |
| 5599 |
var $passData = $data + '[i' + $lvl + ']'; |
| 5600 |
$it.dataPathArr[$dataNxt] = 'i' + $lvl; |
| 5601 |
var $code = it.validate($it); |
| 5602 |
if (it.util.varOccurences($code, $nextData) < 2) { |
| 5603 |
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 5604 |
} else { |
| 5605 |
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 5606 |
} |
| 5607 |
if ($breakOnError) { |
| 5608 |
out += ' if (!valid' + ($it.level) + ') break; '; |
| 5609 |
} |
| 5610 |
out += ' } } '; |
| 5611 |
if ($breakOnError) { |
| 5612 |
out += ' if (valid' + ($it.level) + ') { '; |
| 5613 |
$closingBraces += '}'; |
| 5614 |
} |
| 5615 |
} |
| 5616 |
} else if (it.util.schemaHasRules($schema, it.RULES.all)) { |
| 5617 |
$it.schema = $schema; |
| 5618 |
$it.schemaPath = $schemaPath; |
| 5619 |
$it.errSchemaPath = $errSchemaPath; |
| 5620 |
out += ' for (var i' + ($lvl) + ' = ' + (0) + '; i' + ($lvl) + ' < ' + ($data) + '.length; i' + ($lvl) + '++) { '; |
| 5621 |
$it.errorPath = it.util.getPathExpr(it.errorPath, 'i' + $lvl, it.opts.jsonPointers, true); |
| 5622 |
var $passData = $data + '[i' + $lvl + ']'; |
| 5623 |
$it.dataPathArr[$dataNxt] = 'i' + $lvl; |
| 5624 |
var $code = it.validate($it); |
| 5625 |
if (it.util.varOccurences($code, $nextData) < 2) { |
| 5626 |
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 5627 |
} else { |
| 5628 |
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 5629 |
} |
| 5630 |
if ($breakOnError) { |
| 5631 |
out += ' if (!valid' + ($it.level) + ') break; '; |
| 5632 |
} |
| 5633 |
out += ' } '; |
| 5634 |
if ($breakOnError) { |
| 5635 |
out += ' if (valid' + ($it.level) + ') { '; |
| 5636 |
$closingBraces += '}'; |
| 5637 |
} |
| 5638 |
} |
| 5639 |
if ($breakOnError) { |
| 5640 |
out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {'; |
| 5641 |
} |
| 5642 |
out = it.util.cleanUpCode(out); |
| 5643 |
return out; |
| 5644 |
} |
| 5645 |
|
| 5646 |
|
| 5647 |
/***/ }, |
| 5648 |
/* 32 */ |
| 5649 |
/***/ function(module, exports) { |
| 5650 |
|
| 5651 |
'use strict'; |
| 5652 |
module.exports = function generate__limit(it, $keyword) { |
| 5653 |
var out = ' '; |
| 5654 |
var $lvl = it.level; |
| 5655 |
var $dataLvl = it.dataLevel; |
| 5656 |
var $schema = it.schema[$keyword]; |
| 5657 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5658 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5659 |
var $breakOnError = !it.opts.allErrors; |
| 5660 |
var $errorKeyword; |
| 5661 |
var $data = 'data' + ($dataLvl || ''); |
| 5662 |
var $isData = it.opts.v5 && $schema.$data; |
| 5663 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 5664 |
if ($isData) { |
| 5665 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 5666 |
$schemaValue = 'schema' + $lvl; |
| 5667 |
} |
| 5668 |
var $isMax = $keyword == 'maximum', |
| 5669 |
$exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum', |
| 5670 |
$schemaExcl = it.schema[$exclusiveKeyword], |
| 5671 |
$isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data, |
| 5672 |
$op = $isMax ? '<' : '>', |
| 5673 |
$notOp = $isMax ? '>' : '<'; |
| 5674 |
if ($isDataExcl) { |
| 5675 |
var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr), |
| 5676 |
$exclusive = 'exclusive' + $lvl, |
| 5677 |
$opExpr = 'op' + $lvl, |
| 5678 |
$opStr = '\' + ' + $opExpr + ' + \''; |
| 5679 |
out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; '; |
| 5680 |
$schemaValueExcl = 'schemaExcl' + $lvl; |
| 5681 |
out += ' var exclusive' + ($lvl) + '; if (typeof ' + ($schemaValueExcl) + ' != \'boolean\' && typeof ' + ($schemaValueExcl) + ' != \'undefined\') { '; |
| 5682 |
var $errorKeyword = $exclusiveKeyword; |
| 5683 |
var $$outStack = $$outStack || []; |
| 5684 |
$$outStack.push(out); |
| 5685 |
out = ''; /* istanbul ignore else */ |
| 5686 |
if (it.createErrors !== false) { |
| 5687 |
out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} '; |
| 5688 |
if (it.opts.messages !== false) { |
| 5689 |
out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' '; |
| 5690 |
} |
| 5691 |
if (it.opts.verbose) { |
| 5692 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5693 |
} |
| 5694 |
out += ' } '; |
| 5695 |
} else { |
| 5696 |
out += ' {} '; |
| 5697 |
} |
| 5698 |
var __err = out; |
| 5699 |
out = $$outStack.pop(); |
| 5700 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 5701 |
if (it.async) { |
| 5702 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 5703 |
} else { |
| 5704 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 5705 |
} |
| 5706 |
} else { |
| 5707 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 5708 |
} |
| 5709 |
out += ' } else if( '; |
| 5710 |
if ($isData) { |
| 5711 |
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 5712 |
} |
| 5713 |
out += ' ((exclusive' + ($lvl) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ')) { var op' + ($lvl) + ' = exclusive' + ($lvl) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';'; |
| 5714 |
} else { |
| 5715 |
var $exclusive = $schemaExcl === true, |
| 5716 |
$opStr = $op; |
| 5717 |
if (!$exclusive) $opStr += '='; |
| 5718 |
var $opExpr = '\'' + $opStr + '\''; |
| 5719 |
out += ' if ( '; |
| 5720 |
if ($isData) { |
| 5721 |
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 5722 |
} |
| 5723 |
out += ' ' + ($data) + ' ' + ($notOp); |
| 5724 |
if ($exclusive) { |
| 5725 |
out += '='; |
| 5726 |
} |
| 5727 |
out += ' ' + ($schemaValue) + ') {'; |
| 5728 |
} |
| 5729 |
var $errorKeyword = $keyword; |
| 5730 |
var $$outStack = $$outStack || []; |
| 5731 |
$$outStack.push(out); |
| 5732 |
out = ''; /* istanbul ignore else */ |
| 5733 |
if (it.createErrors !== false) { |
| 5734 |
out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } '; |
| 5735 |
if (it.opts.messages !== false) { |
| 5736 |
out += ' , message: \'should be ' + ($opStr) + ' '; |
| 5737 |
if ($isData) { |
| 5738 |
out += '\' + ' + ($schemaValue); |
| 5739 |
} else { |
| 5740 |
out += '' + ($schema) + '\''; |
| 5741 |
} |
| 5742 |
} |
| 5743 |
if (it.opts.verbose) { |
| 5744 |
out += ' , schema: '; |
| 5745 |
if ($isData) { |
| 5746 |
out += 'validate.schema' + ($schemaPath); |
| 5747 |
} else { |
| 5748 |
out += '' + ($schema); |
| 5749 |
} |
| 5750 |
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5751 |
} |
| 5752 |
out += ' } '; |
| 5753 |
} else { |
| 5754 |
out += ' {} '; |
| 5755 |
} |
| 5756 |
var __err = out; |
| 5757 |
out = $$outStack.pop(); |
| 5758 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 5759 |
if (it.async) { |
| 5760 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 5761 |
} else { |
| 5762 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 5763 |
} |
| 5764 |
} else { |
| 5765 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 5766 |
} |
| 5767 |
out += ' } '; |
| 5768 |
if ($breakOnError) { |
| 5769 |
out += ' else { '; |
| 5770 |
} |
| 5771 |
return out; |
| 5772 |
} |
| 5773 |
|
| 5774 |
|
| 5775 |
/***/ }, |
| 5776 |
/* 33 */ |
| 5777 |
/***/ function(module, exports) { |
| 5778 |
|
| 5779 |
'use strict'; |
| 5780 |
module.exports = function generate__limitItems(it, $keyword) { |
| 5781 |
var out = ' '; |
| 5782 |
var $lvl = it.level; |
| 5783 |
var $dataLvl = it.dataLevel; |
| 5784 |
var $schema = it.schema[$keyword]; |
| 5785 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5786 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5787 |
var $breakOnError = !it.opts.allErrors; |
| 5788 |
var $errorKeyword; |
| 5789 |
var $data = 'data' + ($dataLvl || ''); |
| 5790 |
var $isData = it.opts.v5 && $schema.$data; |
| 5791 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 5792 |
if ($isData) { |
| 5793 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 5794 |
$schemaValue = 'schema' + $lvl; |
| 5795 |
} |
| 5796 |
var $op = $keyword == 'maxItems' ? '>' : '<'; |
| 5797 |
out += 'if ( '; |
| 5798 |
if ($isData) { |
| 5799 |
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 5800 |
} |
| 5801 |
out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { '; |
| 5802 |
var $errorKeyword = $keyword; |
| 5803 |
var $$outStack = $$outStack || []; |
| 5804 |
$$outStack.push(out); |
| 5805 |
out = ''; /* istanbul ignore else */ |
| 5806 |
if (it.createErrors !== false) { |
| 5807 |
out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schemaValue) + ' } '; |
| 5808 |
if (it.opts.messages !== false) { |
| 5809 |
out += ' , message: \'should NOT have '; |
| 5810 |
if ($keyword == 'maxItems') { |
| 5811 |
out += 'more'; |
| 5812 |
} else { |
| 5813 |
out += 'less'; |
| 5814 |
} |
| 5815 |
out += ' than '; |
| 5816 |
if ($isData) { |
| 5817 |
out += '\' + ' + ($schemaValue) + ' + \''; |
| 5818 |
} else { |
| 5819 |
out += '' + ($schema); |
| 5820 |
} |
| 5821 |
out += ' items\' '; |
| 5822 |
} |
| 5823 |
if (it.opts.verbose) { |
| 5824 |
out += ' , schema: '; |
| 5825 |
if ($isData) { |
| 5826 |
out += 'validate.schema' + ($schemaPath); |
| 5827 |
} else { |
| 5828 |
out += '' + ($schema); |
| 5829 |
} |
| 5830 |
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5831 |
} |
| 5832 |
out += ' } '; |
| 5833 |
} else { |
| 5834 |
out += ' {} '; |
| 5835 |
} |
| 5836 |
var __err = out; |
| 5837 |
out = $$outStack.pop(); |
| 5838 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 5839 |
if (it.async) { |
| 5840 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 5841 |
} else { |
| 5842 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 5843 |
} |
| 5844 |
} else { |
| 5845 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 5846 |
} |
| 5847 |
out += '} '; |
| 5848 |
if ($breakOnError) { |
| 5849 |
out += ' else { '; |
| 5850 |
} |
| 5851 |
return out; |
| 5852 |
} |
| 5853 |
|
| 5854 |
|
| 5855 |
/***/ }, |
| 5856 |
/* 34 */ |
| 5857 |
/***/ function(module, exports) { |
| 5858 |
|
| 5859 |
'use strict'; |
| 5860 |
module.exports = function generate__limitLength(it, $keyword) { |
| 5861 |
var out = ' '; |
| 5862 |
var $lvl = it.level; |
| 5863 |
var $dataLvl = it.dataLevel; |
| 5864 |
var $schema = it.schema[$keyword]; |
| 5865 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5866 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5867 |
var $breakOnError = !it.opts.allErrors; |
| 5868 |
var $errorKeyword; |
| 5869 |
var $data = 'data' + ($dataLvl || ''); |
| 5870 |
var $isData = it.opts.v5 && $schema.$data; |
| 5871 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 5872 |
if ($isData) { |
| 5873 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 5874 |
$schemaValue = 'schema' + $lvl; |
| 5875 |
} |
| 5876 |
var $op = $keyword == 'maxLength' ? '>' : '<'; |
| 5877 |
out += 'if ( '; |
| 5878 |
if ($isData) { |
| 5879 |
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 5880 |
} |
| 5881 |
if (it.opts.unicode === false) { |
| 5882 |
out += ' ' + ($data) + '.length '; |
| 5883 |
} else { |
| 5884 |
out += ' ucs2length(' + ($data) + ') '; |
| 5885 |
} |
| 5886 |
out += ' ' + ($op) + ' ' + ($schemaValue) + ') { '; |
| 5887 |
var $errorKeyword = $keyword; |
| 5888 |
var $$outStack = $$outStack || []; |
| 5889 |
$$outStack.push(out); |
| 5890 |
out = ''; /* istanbul ignore else */ |
| 5891 |
if (it.createErrors !== false) { |
| 5892 |
out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schemaValue) + ' } '; |
| 5893 |
if (it.opts.messages !== false) { |
| 5894 |
out += ' , message: \'should NOT be '; |
| 5895 |
if ($keyword == 'maxLength') { |
| 5896 |
out += 'longer'; |
| 5897 |
} else { |
| 5898 |
out += 'shorter'; |
| 5899 |
} |
| 5900 |
out += ' than '; |
| 5901 |
if ($isData) { |
| 5902 |
out += '\' + ' + ($schemaValue) + ' + \''; |
| 5903 |
} else { |
| 5904 |
out += '' + ($schema); |
| 5905 |
} |
| 5906 |
out += ' characters\' '; |
| 5907 |
} |
| 5908 |
if (it.opts.verbose) { |
| 5909 |
out += ' , schema: '; |
| 5910 |
if ($isData) { |
| 5911 |
out += 'validate.schema' + ($schemaPath); |
| 5912 |
} else { |
| 5913 |
out += '' + ($schema); |
| 5914 |
} |
| 5915 |
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5916 |
} |
| 5917 |
out += ' } '; |
| 5918 |
} else { |
| 5919 |
out += ' {} '; |
| 5920 |
} |
| 5921 |
var __err = out; |
| 5922 |
out = $$outStack.pop(); |
| 5923 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 5924 |
if (it.async) { |
| 5925 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 5926 |
} else { |
| 5927 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 5928 |
} |
| 5929 |
} else { |
| 5930 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 5931 |
} |
| 5932 |
out += '} '; |
| 5933 |
if ($breakOnError) { |
| 5934 |
out += ' else { '; |
| 5935 |
} |
| 5936 |
return out; |
| 5937 |
} |
| 5938 |
|
| 5939 |
|
| 5940 |
/***/ }, |
| 5941 |
/* 35 */ |
| 5942 |
/***/ function(module, exports) { |
| 5943 |
|
| 5944 |
'use strict'; |
| 5945 |
module.exports = function generate__limitProperties(it, $keyword) { |
| 5946 |
var out = ' '; |
| 5947 |
var $lvl = it.level; |
| 5948 |
var $dataLvl = it.dataLevel; |
| 5949 |
var $schema = it.schema[$keyword]; |
| 5950 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 5951 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 5952 |
var $breakOnError = !it.opts.allErrors; |
| 5953 |
var $errorKeyword; |
| 5954 |
var $data = 'data' + ($dataLvl || ''); |
| 5955 |
var $isData = it.opts.v5 && $schema.$data; |
| 5956 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 5957 |
if ($isData) { |
| 5958 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 5959 |
$schemaValue = 'schema' + $lvl; |
| 5960 |
} |
| 5961 |
var $op = $keyword == 'maxProperties' ? '>' : '<'; |
| 5962 |
out += 'if ( '; |
| 5963 |
if ($isData) { |
| 5964 |
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; |
| 5965 |
} |
| 5966 |
out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { '; |
| 5967 |
var $errorKeyword = $keyword; |
| 5968 |
var $$outStack = $$outStack || []; |
| 5969 |
$$outStack.push(out); |
| 5970 |
out = ''; /* istanbul ignore else */ |
| 5971 |
if (it.createErrors !== false) { |
| 5972 |
out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: ' + ($schemaValue) + ' } '; |
| 5973 |
if (it.opts.messages !== false) { |
| 5974 |
out += ' , message: \'should NOT have '; |
| 5975 |
if ($keyword == 'maxProperties') { |
| 5976 |
out += 'more'; |
| 5977 |
} else { |
| 5978 |
out += 'less'; |
| 5979 |
} |
| 5980 |
out += ' than '; |
| 5981 |
if ($isData) { |
| 5982 |
out += '\' + ' + ($schemaValue) + ' + \''; |
| 5983 |
} else { |
| 5984 |
out += '' + ($schema); |
| 5985 |
} |
| 5986 |
out += ' properties\' '; |
| 5987 |
} |
| 5988 |
if (it.opts.verbose) { |
| 5989 |
out += ' , schema: '; |
| 5990 |
if ($isData) { |
| 5991 |
out += 'validate.schema' + ($schemaPath); |
| 5992 |
} else { |
| 5993 |
out += '' + ($schema); |
| 5994 |
} |
| 5995 |
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 5996 |
} |
| 5997 |
out += ' } '; |
| 5998 |
} else { |
| 5999 |
out += ' {} '; |
| 6000 |
} |
| 6001 |
var __err = out; |
| 6002 |
out = $$outStack.pop(); |
| 6003 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6004 |
if (it.async) { |
| 6005 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6006 |
} else { |
| 6007 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6008 |
} |
| 6009 |
} else { |
| 6010 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6011 |
} |
| 6012 |
out += '} '; |
| 6013 |
if ($breakOnError) { |
| 6014 |
out += ' else { '; |
| 6015 |
} |
| 6016 |
return out; |
| 6017 |
} |
| 6018 |
|
| 6019 |
|
| 6020 |
/***/ }, |
| 6021 |
/* 36 */ |
| 6022 |
/***/ function(module, exports) { |
| 6023 |
|
| 6024 |
'use strict'; |
| 6025 |
module.exports = function generate_multipleOf(it, $keyword) { |
| 6026 |
var out = ' '; |
| 6027 |
var $lvl = it.level; |
| 6028 |
var $dataLvl = it.dataLevel; |
| 6029 |
var $schema = it.schema[$keyword]; |
| 6030 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 6031 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 6032 |
var $breakOnError = !it.opts.allErrors; |
| 6033 |
var $errorKeyword; |
| 6034 |
var $data = 'data' + ($dataLvl || ''); |
| 6035 |
var $isData = it.opts.v5 && $schema.$data; |
| 6036 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 6037 |
if ($isData) { |
| 6038 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 6039 |
$schemaValue = 'schema' + $lvl; |
| 6040 |
} |
| 6041 |
out += 'var division' + ($lvl) + ';if ('; |
| 6042 |
if ($isData) { |
| 6043 |
out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || '; |
| 6044 |
} |
| 6045 |
out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', '; |
| 6046 |
if (it.opts.multipleOfPrecision) { |
| 6047 |
out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' '; |
| 6048 |
} else { |
| 6049 |
out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') '; |
| 6050 |
} |
| 6051 |
out += ' ) '; |
| 6052 |
if ($isData) { |
| 6053 |
out += ' ) '; |
| 6054 |
} |
| 6055 |
out += ' ) { '; |
| 6056 |
var $$outStack = $$outStack || []; |
| 6057 |
$$outStack.push(out); |
| 6058 |
out = ''; /* istanbul ignore else */ |
| 6059 |
if (it.createErrors !== false) { |
| 6060 |
out += ' { keyword: \'' + ($errorKeyword || 'multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { multipleOf: ' + ($schemaValue) + ' } '; |
| 6061 |
if (it.opts.messages !== false) { |
| 6062 |
out += ' , message: \'should be multiple of '; |
| 6063 |
if ($isData) { |
| 6064 |
out += '\' + ' + ($schemaValue); |
| 6065 |
} else { |
| 6066 |
out += '' + ($schema) + '\''; |
| 6067 |
} |
| 6068 |
} |
| 6069 |
if (it.opts.verbose) { |
| 6070 |
out += ' , schema: '; |
| 6071 |
if ($isData) { |
| 6072 |
out += 'validate.schema' + ($schemaPath); |
| 6073 |
} else { |
| 6074 |
out += '' + ($schema); |
| 6075 |
} |
| 6076 |
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6077 |
} |
| 6078 |
out += ' } '; |
| 6079 |
} else { |
| 6080 |
out += ' {} '; |
| 6081 |
} |
| 6082 |
var __err = out; |
| 6083 |
out = $$outStack.pop(); |
| 6084 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6085 |
if (it.async) { |
| 6086 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6087 |
} else { |
| 6088 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6089 |
} |
| 6090 |
} else { |
| 6091 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6092 |
} |
| 6093 |
out += '} '; |
| 6094 |
if ($breakOnError) { |
| 6095 |
out += ' else { '; |
| 6096 |
} |
| 6097 |
return out; |
| 6098 |
} |
| 6099 |
|
| 6100 |
|
| 6101 |
/***/ }, |
| 6102 |
/* 37 */ |
| 6103 |
/***/ function(module, exports) { |
| 6104 |
|
| 6105 |
'use strict'; |
| 6106 |
module.exports = function generate_not(it, $keyword) { |
| 6107 |
var out = ' '; |
| 6108 |
var $lvl = it.level; |
| 6109 |
var $dataLvl = it.dataLevel; |
| 6110 |
var $schema = it.schema[$keyword]; |
| 6111 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 6112 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 6113 |
var $breakOnError = !it.opts.allErrors; |
| 6114 |
var $errorKeyword; |
| 6115 |
var $data = 'data' + ($dataLvl || ''); |
| 6116 |
var $errs = 'errs__' + $lvl; |
| 6117 |
var $it = it.util.copy(it); |
| 6118 |
$it.level++; |
| 6119 |
if (it.util.schemaHasRules($schema, it.RULES.all)) { |
| 6120 |
$it.schema = $schema; |
| 6121 |
$it.schemaPath = $schemaPath; |
| 6122 |
$it.errSchemaPath = $errSchemaPath; |
| 6123 |
out += ' var ' + ($errs) + ' = errors; '; |
| 6124 |
var $wasComposite = it.compositeRule; |
| 6125 |
it.compositeRule = $it.compositeRule = true; |
| 6126 |
$it.createErrors = false; |
| 6127 |
var $allErrorsOption; |
| 6128 |
if ($it.opts.allErrors) { |
| 6129 |
$allErrorsOption = $it.opts.allErrors; |
| 6130 |
$it.opts.allErrors = false; |
| 6131 |
} |
| 6132 |
out += ' ' + (it.validate($it)) + ' '; |
| 6133 |
$it.createErrors = true; |
| 6134 |
if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption; |
| 6135 |
it.compositeRule = $it.compositeRule = $wasComposite; |
| 6136 |
out += ' if (valid' + ($it.level) + ') { '; |
| 6137 |
var $$outStack = $$outStack || []; |
| 6138 |
$$outStack.push(out); |
| 6139 |
out = ''; /* istanbul ignore else */ |
| 6140 |
if (it.createErrors !== false) { |
| 6141 |
out += ' { keyword: \'' + ($errorKeyword || 'not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} '; |
| 6142 |
if (it.opts.messages !== false) { |
| 6143 |
out += ' , message: \'should NOT be valid\' '; |
| 6144 |
} |
| 6145 |
if (it.opts.verbose) { |
| 6146 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6147 |
} |
| 6148 |
out += ' } '; |
| 6149 |
} else { |
| 6150 |
out += ' {} '; |
| 6151 |
} |
| 6152 |
var __err = out; |
| 6153 |
out = $$outStack.pop(); |
| 6154 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6155 |
if (it.async) { |
| 6156 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6157 |
} else { |
| 6158 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6159 |
} |
| 6160 |
} else { |
| 6161 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6162 |
} |
| 6163 |
out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } '; |
| 6164 |
if (it.opts.allErrors) { |
| 6165 |
out += ' } '; |
| 6166 |
} |
| 6167 |
} else { |
| 6168 |
out += ' var err = '; /* istanbul ignore else */ |
| 6169 |
if (it.createErrors !== false) { |
| 6170 |
out += ' { keyword: \'' + ($errorKeyword || 'not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} '; |
| 6171 |
if (it.opts.messages !== false) { |
| 6172 |
out += ' , message: \'should NOT be valid\' '; |
| 6173 |
} |
| 6174 |
if (it.opts.verbose) { |
| 6175 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6176 |
} |
| 6177 |
out += ' } '; |
| 6178 |
} else { |
| 6179 |
out += ' {} '; |
| 6180 |
} |
| 6181 |
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6182 |
if ($breakOnError) { |
| 6183 |
out += ' if (false) { '; |
| 6184 |
} |
| 6185 |
} |
| 6186 |
return out; |
| 6187 |
} |
| 6188 |
|
| 6189 |
|
| 6190 |
/***/ }, |
| 6191 |
/* 38 */ |
| 6192 |
/***/ function(module, exports) { |
| 6193 |
|
| 6194 |
'use strict'; |
| 6195 |
module.exports = function generate_oneOf(it, $keyword) { |
| 6196 |
var out = ' '; |
| 6197 |
var $lvl = it.level; |
| 6198 |
var $dataLvl = it.dataLevel; |
| 6199 |
var $schema = it.schema[$keyword]; |
| 6200 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 6201 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 6202 |
var $breakOnError = !it.opts.allErrors; |
| 6203 |
var $errorKeyword; |
| 6204 |
var $data = 'data' + ($dataLvl || ''); |
| 6205 |
var $valid = 'valid' + $lvl; |
| 6206 |
var $errs = 'errs__' + $lvl; |
| 6207 |
var $it = it.util.copy(it); |
| 6208 |
var $closingBraces = ''; |
| 6209 |
$it.level++; |
| 6210 |
out += 'var ' + ($errs) + ' = errors;var prevValid' + ($lvl) + ' = false;var ' + ($valid) + ' = false; '; |
| 6211 |
var $wasComposite = it.compositeRule; |
| 6212 |
it.compositeRule = $it.compositeRule = true; |
| 6213 |
var arr1 = $schema; |
| 6214 |
if (arr1) { |
| 6215 |
var $sch, $i = -1, |
| 6216 |
l1 = arr1.length - 1; |
| 6217 |
while ($i < l1) { |
| 6218 |
$sch = arr1[$i += 1]; |
| 6219 |
if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 6220 |
$it.schema = $sch; |
| 6221 |
$it.schemaPath = $schemaPath + '[' + $i + ']'; |
| 6222 |
$it.errSchemaPath = $errSchemaPath + '/' + $i; |
| 6223 |
out += ' ' + (it.validate($it)) + ' '; |
| 6224 |
} else { |
| 6225 |
out += ' var valid' + ($it.level) + ' = true; '; |
| 6226 |
} |
| 6227 |
if ($i) { |
| 6228 |
out += ' if (valid' + ($it.level) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { '; |
| 6229 |
$closingBraces += '}'; |
| 6230 |
} |
| 6231 |
out += ' if (valid' + ($it.level) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;'; |
| 6232 |
} |
| 6233 |
} |
| 6234 |
it.compositeRule = $it.compositeRule = $wasComposite; |
| 6235 |
out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { '; |
| 6236 |
var $$outStack = $$outStack || []; |
| 6237 |
$$outStack.push(out); |
| 6238 |
out = ''; /* istanbul ignore else */ |
| 6239 |
if (it.createErrors !== false) { |
| 6240 |
out += ' { keyword: \'' + ($errorKeyword || 'oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} '; |
| 6241 |
if (it.opts.messages !== false) { |
| 6242 |
out += ' , message: \'should match exactly one schema in oneOf\' '; |
| 6243 |
} |
| 6244 |
if (it.opts.verbose) { |
| 6245 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6246 |
} |
| 6247 |
out += ' } '; |
| 6248 |
} else { |
| 6249 |
out += ' {} '; |
| 6250 |
} |
| 6251 |
var __err = out; |
| 6252 |
out = $$outStack.pop(); |
| 6253 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6254 |
if (it.async) { |
| 6255 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6256 |
} else { |
| 6257 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6258 |
} |
| 6259 |
} else { |
| 6260 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6261 |
} |
| 6262 |
out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }'; |
| 6263 |
if (it.opts.allErrors) { |
| 6264 |
out += ' } '; |
| 6265 |
} |
| 6266 |
return out; |
| 6267 |
} |
| 6268 |
|
| 6269 |
|
| 6270 |
/***/ }, |
| 6271 |
/* 39 */ |
| 6272 |
/***/ function(module, exports) { |
| 6273 |
|
| 6274 |
'use strict'; |
| 6275 |
module.exports = function generate_pattern(it, $keyword) { |
| 6276 |
var out = ' '; |
| 6277 |
var $lvl = it.level; |
| 6278 |
var $dataLvl = it.dataLevel; |
| 6279 |
var $schema = it.schema[$keyword]; |
| 6280 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 6281 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 6282 |
var $breakOnError = !it.opts.allErrors; |
| 6283 |
var $errorKeyword; |
| 6284 |
var $data = 'data' + ($dataLvl || ''); |
| 6285 |
var $isData = it.opts.v5 && $schema.$data; |
| 6286 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 6287 |
if ($isData) { |
| 6288 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 6289 |
$schemaValue = 'schema' + $lvl; |
| 6290 |
} |
| 6291 |
var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema); |
| 6292 |
out += 'if ( '; |
| 6293 |
if ($isData) { |
| 6294 |
out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || '; |
| 6295 |
} |
| 6296 |
out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { '; |
| 6297 |
var $$outStack = $$outStack || []; |
| 6298 |
$$outStack.push(out); |
| 6299 |
out = ''; /* istanbul ignore else */ |
| 6300 |
if (it.createErrors !== false) { |
| 6301 |
out += ' { keyword: \'' + ($errorKeyword || 'pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { pattern: '; |
| 6302 |
if ($isData) { |
| 6303 |
out += '' + ($schemaValue); |
| 6304 |
} else { |
| 6305 |
out += '' + (it.util.toQuotedString($schema)); |
| 6306 |
} |
| 6307 |
out += ' } '; |
| 6308 |
if (it.opts.messages !== false) { |
| 6309 |
out += ' , message: \'should match pattern "'; |
| 6310 |
if ($isData) { |
| 6311 |
out += '\' + ' + ($schemaValue) + ' + \''; |
| 6312 |
} else { |
| 6313 |
out += '' + (it.util.escapeQuotes($schema)); |
| 6314 |
} |
| 6315 |
out += '"\' '; |
| 6316 |
} |
| 6317 |
if (it.opts.verbose) { |
| 6318 |
out += ' , schema: '; |
| 6319 |
if ($isData) { |
| 6320 |
out += 'validate.schema' + ($schemaPath); |
| 6321 |
} else { |
| 6322 |
out += '' + (it.util.toQuotedString($schema)); |
| 6323 |
} |
| 6324 |
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6325 |
} |
| 6326 |
out += ' } '; |
| 6327 |
} else { |
| 6328 |
out += ' {} '; |
| 6329 |
} |
| 6330 |
var __err = out; |
| 6331 |
out = $$outStack.pop(); |
| 6332 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6333 |
if (it.async) { |
| 6334 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6335 |
} else { |
| 6336 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6337 |
} |
| 6338 |
} else { |
| 6339 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6340 |
} |
| 6341 |
out += '} '; |
| 6342 |
if ($breakOnError) { |
| 6343 |
out += ' else { '; |
| 6344 |
} |
| 6345 |
return out; |
| 6346 |
} |
| 6347 |
|
| 6348 |
|
| 6349 |
/***/ }, |
| 6350 |
/* 40 */ |
| 6351 |
/***/ function(module, exports) { |
| 6352 |
|
| 6353 |
'use strict'; |
| 6354 |
module.exports = function generate_properties(it, $keyword) { |
| 6355 |
var out = ' '; |
| 6356 |
var $lvl = it.level; |
| 6357 |
var $dataLvl = it.dataLevel; |
| 6358 |
var $schema = it.schema[$keyword]; |
| 6359 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 6360 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 6361 |
var $breakOnError = !it.opts.allErrors; |
| 6362 |
var $errorKeyword; |
| 6363 |
var $data = 'data' + ($dataLvl || ''); |
| 6364 |
var $valid = 'valid' + $lvl; |
| 6365 |
var $errs = 'errs__' + $lvl; |
| 6366 |
var $it = it.util.copy(it); |
| 6367 |
var $closingBraces = ''; |
| 6368 |
$it.level++; |
| 6369 |
var $dataNxt = $it.dataLevel = it.dataLevel + 1, |
| 6370 |
$nextData = 'data' + $dataNxt; |
| 6371 |
var $schemaKeys = Object.keys($schema || {}), |
| 6372 |
$pProperties = it.schema.patternProperties || {}, |
| 6373 |
$pPropertyKeys = Object.keys($pProperties), |
| 6374 |
$aProperties = it.schema.additionalProperties, |
| 6375 |
$someProperties = $schemaKeys.length || $pPropertyKeys.length, |
| 6376 |
$noAdditional = $aProperties === false, |
| 6377 |
$additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length, |
| 6378 |
$removeAdditional = it.opts.removeAdditional, |
| 6379 |
$checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional; |
| 6380 |
var $required = it.schema.required; |
| 6381 |
if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired) var $requiredHash = it.util.toHash($required); |
| 6382 |
if (it.opts.v5) { |
| 6383 |
var $pgProperties = it.schema.patternGroups || {}, |
| 6384 |
$pgPropertyKeys = Object.keys($pgProperties); |
| 6385 |
} |
| 6386 |
out += 'var ' + ($errs) + ' = errors;var valid' + ($it.level) + ' = true;'; |
| 6387 |
if ($checkAdditional) { |
| 6388 |
out += ' for (var key' + ($lvl) + ' in ' + ($data) + ') { '; |
| 6389 |
if ($someProperties) { |
| 6390 |
out += ' var isAdditional' + ($lvl) + ' = !(false '; |
| 6391 |
if ($schemaKeys.length) { |
| 6392 |
if ($schemaKeys.length > 5) { |
| 6393 |
out += ' || validate.schema' + ($schemaPath) + '[key' + ($lvl) + '] '; |
| 6394 |
} else { |
| 6395 |
var arr1 = $schemaKeys; |
| 6396 |
if (arr1) { |
| 6397 |
var $propertyKey, i1 = -1, |
| 6398 |
l1 = arr1.length - 1; |
| 6399 |
while (i1 < l1) { |
| 6400 |
$propertyKey = arr1[i1 += 1]; |
| 6401 |
out += ' || key' + ($lvl) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' '; |
| 6402 |
} |
| 6403 |
} |
| 6404 |
} |
| 6405 |
} |
| 6406 |
if ($pPropertyKeys.length) { |
| 6407 |
var arr2 = $pPropertyKeys; |
| 6408 |
if (arr2) { |
| 6409 |
var $pProperty, $i = -1, |
| 6410 |
l2 = arr2.length - 1; |
| 6411 |
while ($i < l2) { |
| 6412 |
$pProperty = arr2[$i += 1]; |
| 6413 |
out += ' || ' + (it.usePattern($pProperty)) + '.test(key' + ($lvl) + ') '; |
| 6414 |
} |
| 6415 |
} |
| 6416 |
} |
| 6417 |
if (it.opts.v5 && $pgPropertyKeys && $pgPropertyKeys.length) { |
| 6418 |
var arr3 = $pgPropertyKeys; |
| 6419 |
if (arr3) { |
| 6420 |
var $pgProperty, $i = -1, |
| 6421 |
l3 = arr3.length - 1; |
| 6422 |
while ($i < l3) { |
| 6423 |
$pgProperty = arr3[$i += 1]; |
| 6424 |
out += ' || ' + (it.usePattern($pgProperty)) + '.test(key' + ($lvl) + ') '; |
| 6425 |
} |
| 6426 |
} |
| 6427 |
} |
| 6428 |
out += ' ); if (isAdditional' + ($lvl) + ') { '; |
| 6429 |
} |
| 6430 |
if ($removeAdditional == 'all') { |
| 6431 |
out += ' delete ' + ($data) + '[key' + ($lvl) + ']; '; |
| 6432 |
} else { |
| 6433 |
var $currentErrorPath = it.errorPath; |
| 6434 |
var $additionalProperty = '\' + key' + $lvl + ' + \''; |
| 6435 |
if (it.opts._errorDataPathProperty) { |
| 6436 |
it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers); |
| 6437 |
} |
| 6438 |
if ($noAdditional) { |
| 6439 |
if ($removeAdditional) { |
| 6440 |
out += ' delete ' + ($data) + '[key' + ($lvl) + ']; '; |
| 6441 |
} else { |
| 6442 |
out += ' valid' + ($it.level) + ' = false; '; |
| 6443 |
var $currErrSchemaPath = $errSchemaPath; |
| 6444 |
$errSchemaPath = it.errSchemaPath + '/additionalProperties'; |
| 6445 |
var $$outStack = $$outStack || []; |
| 6446 |
$$outStack.push(out); |
| 6447 |
out = ''; /* istanbul ignore else */ |
| 6448 |
if (it.createErrors !== false) { |
| 6449 |
out += ' { keyword: \'' + ($errorKeyword || 'additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { additionalProperty: \'' + ($additionalProperty) + '\' } '; |
| 6450 |
if (it.opts.messages !== false) { |
| 6451 |
out += ' , message: \'should NOT have additional properties\' '; |
| 6452 |
} |
| 6453 |
if (it.opts.verbose) { |
| 6454 |
out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6455 |
} |
| 6456 |
out += ' } '; |
| 6457 |
} else { |
| 6458 |
out += ' {} '; |
| 6459 |
} |
| 6460 |
var __err = out; |
| 6461 |
out = $$outStack.pop(); |
| 6462 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6463 |
if (it.async) { |
| 6464 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6465 |
} else { |
| 6466 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6467 |
} |
| 6468 |
} else { |
| 6469 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6470 |
} |
| 6471 |
$errSchemaPath = $currErrSchemaPath; |
| 6472 |
if ($breakOnError) { |
| 6473 |
out += ' break; '; |
| 6474 |
} |
| 6475 |
} |
| 6476 |
} else if ($additionalIsSchema) { |
| 6477 |
if ($removeAdditional == 'failing') { |
| 6478 |
out += ' var ' + ($errs) + ' = errors; '; |
| 6479 |
var $wasComposite = it.compositeRule; |
| 6480 |
it.compositeRule = $it.compositeRule = true; |
| 6481 |
$it.schema = $aProperties; |
| 6482 |
$it.schemaPath = it.schemaPath + '.additionalProperties'; |
| 6483 |
$it.errSchemaPath = it.errSchemaPath + '/additionalProperties'; |
| 6484 |
$it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers); |
| 6485 |
var $passData = $data + '[key' + $lvl + ']'; |
| 6486 |
$it.dataPathArr[$dataNxt] = 'key' + $lvl; |
| 6487 |
var $code = it.validate($it); |
| 6488 |
if (it.util.varOccurences($code, $nextData) < 2) { |
| 6489 |
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 6490 |
} else { |
| 6491 |
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 6492 |
} |
| 6493 |
out += ' if (!valid' + ($it.level) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[key' + ($lvl) + ']; } '; |
| 6494 |
it.compositeRule = $it.compositeRule = $wasComposite; |
| 6495 |
} else { |
| 6496 |
$it.schema = $aProperties; |
| 6497 |
$it.schemaPath = it.schemaPath + '.additionalProperties'; |
| 6498 |
$it.errSchemaPath = it.errSchemaPath + '/additionalProperties'; |
| 6499 |
$it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers); |
| 6500 |
var $passData = $data + '[key' + $lvl + ']'; |
| 6501 |
$it.dataPathArr[$dataNxt] = 'key' + $lvl; |
| 6502 |
var $code = it.validate($it); |
| 6503 |
if (it.util.varOccurences($code, $nextData) < 2) { |
| 6504 |
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 6505 |
} else { |
| 6506 |
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 6507 |
} |
| 6508 |
if ($breakOnError) { |
| 6509 |
out += ' if (!valid' + ($it.level) + ') break; '; |
| 6510 |
} |
| 6511 |
} |
| 6512 |
} |
| 6513 |
it.errorPath = $currentErrorPath; |
| 6514 |
} |
| 6515 |
if ($someProperties) { |
| 6516 |
out += ' } '; |
| 6517 |
} |
| 6518 |
out += ' } '; |
| 6519 |
if ($breakOnError) { |
| 6520 |
out += ' if (valid' + ($it.level) + ') { '; |
| 6521 |
$closingBraces += '}'; |
| 6522 |
} |
| 6523 |
} |
| 6524 |
var $useDefaults = it.opts.useDefaults && !it.compositeRule; |
| 6525 |
if ($schemaKeys.length) { |
| 6526 |
var arr4 = $schemaKeys; |
| 6527 |
if (arr4) { |
| 6528 |
var $propertyKey, i4 = -1, |
| 6529 |
l4 = arr4.length - 1; |
| 6530 |
while (i4 < l4) { |
| 6531 |
$propertyKey = arr4[i4 += 1]; |
| 6532 |
var $sch = $schema[$propertyKey]; |
| 6533 |
if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 6534 |
var $prop = it.util.getProperty($propertyKey), |
| 6535 |
$passData = $data + $prop, |
| 6536 |
$hasDefault = $useDefaults && $sch.default !== undefined; |
| 6537 |
$it.schema = $sch; |
| 6538 |
$it.schemaPath = $schemaPath + $prop; |
| 6539 |
$it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey); |
| 6540 |
$it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers); |
| 6541 |
$it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey); |
| 6542 |
var $code = it.validate($it); |
| 6543 |
if (it.util.varOccurences($code, $nextData) < 2) { |
| 6544 |
$code = it.util.varReplace($code, $nextData, $passData); |
| 6545 |
var $useData = $passData; |
| 6546 |
} else { |
| 6547 |
var $useData = $nextData; |
| 6548 |
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; '; |
| 6549 |
} |
| 6550 |
if ($hasDefault) { |
| 6551 |
out += ' ' + ($code) + ' '; |
| 6552 |
} else { |
| 6553 |
if ($requiredHash && $requiredHash[$propertyKey]) { |
| 6554 |
out += ' if (' + ($useData) + ' === undefined) { valid' + ($it.level) + ' = false; '; |
| 6555 |
var $currentErrorPath = it.errorPath, |
| 6556 |
$currErrSchemaPath = $errSchemaPath, |
| 6557 |
$missingProperty = it.util.escapeQuotes($propertyKey); |
| 6558 |
if (it.opts._errorDataPathProperty) { |
| 6559 |
it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers); |
| 6560 |
} |
| 6561 |
$errSchemaPath = it.errSchemaPath + '/required'; |
| 6562 |
var $$outStack = $$outStack || []; |
| 6563 |
$$outStack.push(out); |
| 6564 |
out = ''; /* istanbul ignore else */ |
| 6565 |
if (it.createErrors !== false) { |
| 6566 |
out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 6567 |
if (it.opts.messages !== false) { |
| 6568 |
out += ' , message: \''; |
| 6569 |
if (it.opts._errorDataPathProperty) { |
| 6570 |
out += 'is a required property'; |
| 6571 |
} else { |
| 6572 |
out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 6573 |
} |
| 6574 |
out += '\' '; |
| 6575 |
} |
| 6576 |
if (it.opts.verbose) { |
| 6577 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6578 |
} |
| 6579 |
out += ' } '; |
| 6580 |
} else { |
| 6581 |
out += ' {} '; |
| 6582 |
} |
| 6583 |
var __err = out; |
| 6584 |
out = $$outStack.pop(); |
| 6585 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6586 |
if (it.async) { |
| 6587 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6588 |
} else { |
| 6589 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6590 |
} |
| 6591 |
} else { |
| 6592 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6593 |
} |
| 6594 |
$errSchemaPath = $currErrSchemaPath; |
| 6595 |
it.errorPath = $currentErrorPath; |
| 6596 |
out += ' } else { '; |
| 6597 |
} else { |
| 6598 |
if ($breakOnError) { |
| 6599 |
out += ' if (' + ($useData) + ' === undefined) { valid' + ($it.level) + ' = true; } else { '; |
| 6600 |
} else { |
| 6601 |
out += ' if (' + ($useData) + ' !== undefined) { '; |
| 6602 |
} |
| 6603 |
} |
| 6604 |
out += ' ' + ($code) + ' } '; |
| 6605 |
} |
| 6606 |
} |
| 6607 |
if ($breakOnError) { |
| 6608 |
out += ' if (valid' + ($it.level) + ') { '; |
| 6609 |
$closingBraces += '}'; |
| 6610 |
} |
| 6611 |
} |
| 6612 |
} |
| 6613 |
} |
| 6614 |
var arr5 = $pPropertyKeys; |
| 6615 |
if (arr5) { |
| 6616 |
var $pProperty, i5 = -1, |
| 6617 |
l5 = arr5.length - 1; |
| 6618 |
while (i5 < l5) { |
| 6619 |
$pProperty = arr5[i5 += 1]; |
| 6620 |
var $sch = $pProperties[$pProperty]; |
| 6621 |
if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 6622 |
$it.schema = $sch; |
| 6623 |
$it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty); |
| 6624 |
$it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty); |
| 6625 |
out += ' for (var key' + ($lvl) + ' in ' + ($data) + ') { if (' + (it.usePattern($pProperty)) + '.test(key' + ($lvl) + ')) { '; |
| 6626 |
$it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers); |
| 6627 |
var $passData = $data + '[key' + $lvl + ']'; |
| 6628 |
$it.dataPathArr[$dataNxt] = 'key' + $lvl; |
| 6629 |
var $code = it.validate($it); |
| 6630 |
if (it.util.varOccurences($code, $nextData) < 2) { |
| 6631 |
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 6632 |
} else { |
| 6633 |
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 6634 |
} |
| 6635 |
if ($breakOnError) { |
| 6636 |
out += ' if (!valid' + ($it.level) + ') break; '; |
| 6637 |
} |
| 6638 |
out += ' } '; |
| 6639 |
if ($breakOnError) { |
| 6640 |
out += ' else valid' + ($it.level) + ' = true; '; |
| 6641 |
} |
| 6642 |
out += ' } '; |
| 6643 |
if ($breakOnError) { |
| 6644 |
out += ' if (valid' + ($it.level) + ') { '; |
| 6645 |
$closingBraces += '}'; |
| 6646 |
} |
| 6647 |
} |
| 6648 |
} |
| 6649 |
} |
| 6650 |
if (it.opts.v5) { |
| 6651 |
var arr6 = $pgPropertyKeys; |
| 6652 |
if (arr6) { |
| 6653 |
var $pgProperty, i6 = -1, |
| 6654 |
l6 = arr6.length - 1; |
| 6655 |
while (i6 < l6) { |
| 6656 |
$pgProperty = arr6[i6 += 1]; |
| 6657 |
var $pgSchema = $pgProperties[$pgProperty], |
| 6658 |
$sch = $pgSchema.schema; |
| 6659 |
if (it.util.schemaHasRules($sch, it.RULES.all)) { |
| 6660 |
$it.schema = $sch; |
| 6661 |
$it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema'; |
| 6662 |
$it.errSchemaPath = it.errSchemaPath + '/patternGroups/' + it.util.escapeFragment($pgProperty) + '/schema'; |
| 6663 |
out += ' var pgPropCount' + ($lvl) + ' = 0; for (var key' + ($lvl) + ' in ' + ($data) + ') { if (' + (it.usePattern($pgProperty)) + '.test(key' + ($lvl) + ')) { pgPropCount' + ($lvl) + '++; '; |
| 6664 |
$it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers); |
| 6665 |
var $passData = $data + '[key' + $lvl + ']'; |
| 6666 |
$it.dataPathArr[$dataNxt] = 'key' + $lvl; |
| 6667 |
var $code = it.validate($it); |
| 6668 |
if (it.util.varOccurences($code, $nextData) < 2) { |
| 6669 |
out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' '; |
| 6670 |
} else { |
| 6671 |
out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' '; |
| 6672 |
} |
| 6673 |
if ($breakOnError) { |
| 6674 |
out += ' if (!valid' + ($it.level) + ') break; '; |
| 6675 |
} |
| 6676 |
out += ' } '; |
| 6677 |
if ($breakOnError) { |
| 6678 |
out += ' else valid' + ($it.level) + ' = true; '; |
| 6679 |
} |
| 6680 |
out += ' } '; |
| 6681 |
if ($breakOnError) { |
| 6682 |
out += ' if (valid' + ($it.level) + ') { '; |
| 6683 |
$closingBraces += '}'; |
| 6684 |
} |
| 6685 |
var $pgMin = $pgSchema.minimum, |
| 6686 |
$pgMax = $pgSchema.maximum; |
| 6687 |
if ($pgMin !== undefined || $pgMax !== undefined) { |
| 6688 |
out += ' var ' + ($valid) + ' = true; '; |
| 6689 |
var $currErrSchemaPath = $errSchemaPath; |
| 6690 |
if ($pgMin !== undefined) { |
| 6691 |
var $limit = $pgMin, |
| 6692 |
$reason = 'minimum', |
| 6693 |
$moreOrLess = 'less'; |
| 6694 |
out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' >= ' + ($pgMin) + '; '; |
| 6695 |
$errSchemaPath = it.errSchemaPath + '/patternGroups/minimum'; |
| 6696 |
out += ' if (!' + ($valid) + ') { '; |
| 6697 |
var $$outStack = $$outStack || []; |
| 6698 |
$$outStack.push(out); |
| 6699 |
out = ''; /* istanbul ignore else */ |
| 6700 |
if (it.createErrors !== false) { |
| 6701 |
out += ' { keyword: \'' + ($errorKeyword || 'patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } '; |
| 6702 |
if (it.opts.messages !== false) { |
| 6703 |
out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' '; |
| 6704 |
} |
| 6705 |
if (it.opts.verbose) { |
| 6706 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6707 |
} |
| 6708 |
out += ' } '; |
| 6709 |
} else { |
| 6710 |
out += ' {} '; |
| 6711 |
} |
| 6712 |
var __err = out; |
| 6713 |
out = $$outStack.pop(); |
| 6714 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6715 |
if (it.async) { |
| 6716 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6717 |
} else { |
| 6718 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6719 |
} |
| 6720 |
} else { |
| 6721 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6722 |
} |
| 6723 |
out += ' } '; |
| 6724 |
if ($pgMax !== undefined) { |
| 6725 |
out += ' else '; |
| 6726 |
} |
| 6727 |
} |
| 6728 |
if ($pgMax !== undefined) { |
| 6729 |
var $limit = $pgMax, |
| 6730 |
$reason = 'maximum', |
| 6731 |
$moreOrLess = 'more'; |
| 6732 |
out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' <= ' + ($pgMax) + '; '; |
| 6733 |
$errSchemaPath = it.errSchemaPath + '/patternGroups/maximum'; |
| 6734 |
out += ' if (!' + ($valid) + ') { '; |
| 6735 |
var $$outStack = $$outStack || []; |
| 6736 |
$$outStack.push(out); |
| 6737 |
out = ''; /* istanbul ignore else */ |
| 6738 |
if (it.createErrors !== false) { |
| 6739 |
out += ' { keyword: \'' + ($errorKeyword || 'patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } '; |
| 6740 |
if (it.opts.messages !== false) { |
| 6741 |
out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' '; |
| 6742 |
} |
| 6743 |
if (it.opts.verbose) { |
| 6744 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6745 |
} |
| 6746 |
out += ' } '; |
| 6747 |
} else { |
| 6748 |
out += ' {} '; |
| 6749 |
} |
| 6750 |
var __err = out; |
| 6751 |
out = $$outStack.pop(); |
| 6752 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6753 |
if (it.async) { |
| 6754 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6755 |
} else { |
| 6756 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6757 |
} |
| 6758 |
} else { |
| 6759 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6760 |
} |
| 6761 |
out += ' } '; |
| 6762 |
} |
| 6763 |
$errSchemaPath = $currErrSchemaPath; |
| 6764 |
if ($breakOnError) { |
| 6765 |
out += ' if (' + ($valid) + ') { '; |
| 6766 |
$closingBraces += '}'; |
| 6767 |
} |
| 6768 |
} |
| 6769 |
} |
| 6770 |
} |
| 6771 |
} |
| 6772 |
} |
| 6773 |
if ($breakOnError) { |
| 6774 |
out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {'; |
| 6775 |
} |
| 6776 |
out = it.util.cleanUpCode(out); |
| 6777 |
return out; |
| 6778 |
} |
| 6779 |
|
| 6780 |
|
| 6781 |
/***/ }, |
| 6782 |
/* 41 */ |
| 6783 |
/***/ function(module, exports) { |
| 6784 |
|
| 6785 |
'use strict'; |
| 6786 |
module.exports = function generate_required(it, $keyword) { |
| 6787 |
var out = ' '; |
| 6788 |
var $lvl = it.level; |
| 6789 |
var $dataLvl = it.dataLevel; |
| 6790 |
var $schema = it.schema[$keyword]; |
| 6791 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 6792 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 6793 |
var $breakOnError = !it.opts.allErrors; |
| 6794 |
var $errorKeyword; |
| 6795 |
var $data = 'data' + ($dataLvl || ''); |
| 6796 |
var $valid = 'valid' + $lvl; |
| 6797 |
var $isData = it.opts.v5 && $schema.$data; |
| 6798 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 6799 |
if ($isData) { |
| 6800 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 6801 |
$schemaValue = 'schema' + $lvl; |
| 6802 |
} |
| 6803 |
if (!$isData) { |
| 6804 |
if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) { |
| 6805 |
var $required = []; |
| 6806 |
var arr1 = $schema; |
| 6807 |
if (arr1) { |
| 6808 |
var $property, i1 = -1, |
| 6809 |
l1 = arr1.length - 1; |
| 6810 |
while (i1 < l1) { |
| 6811 |
$property = arr1[i1 += 1]; |
| 6812 |
var $propertySch = it.schema.properties[$property]; |
| 6813 |
if (!($propertySch && it.util.schemaHasRules($propertySch, it.RULES.all))) { |
| 6814 |
$required[$required.length] = $property; |
| 6815 |
} |
| 6816 |
} |
| 6817 |
} |
| 6818 |
} else { |
| 6819 |
var $required = $schema; |
| 6820 |
} |
| 6821 |
} |
| 6822 |
if ($isData || $required.length) { |
| 6823 |
var $currentErrorPath = it.errorPath, |
| 6824 |
$loopRequired = $isData || $required.length >= it.opts.loopRequired; |
| 6825 |
if ($breakOnError) { |
| 6826 |
out += ' var missing' + ($lvl) + '; '; |
| 6827 |
if ($loopRequired) { |
| 6828 |
if (!$isData) { |
| 6829 |
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; '; |
| 6830 |
} |
| 6831 |
var $i = 'i' + $lvl, |
| 6832 |
$propertyPath = 'schema' + $lvl + '[' + $i + ']', |
| 6833 |
$missingProperty = '\' + ' + $propertyPath + ' + \''; |
| 6834 |
if (it.opts._errorDataPathProperty) { |
| 6835 |
it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers); |
| 6836 |
} |
| 6837 |
out += ' var ' + ($valid) + ' = true; '; |
| 6838 |
if ($isData) { |
| 6839 |
out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {'; |
| 6840 |
} |
| 6841 |
out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] !== undefined; if (!' + ($valid) + ') break; } '; |
| 6842 |
if ($isData) { |
| 6843 |
out += ' } '; |
| 6844 |
} |
| 6845 |
out += ' if (!' + ($valid) + ') { '; |
| 6846 |
var $$outStack = $$outStack || []; |
| 6847 |
$$outStack.push(out); |
| 6848 |
out = ''; /* istanbul ignore else */ |
| 6849 |
if (it.createErrors !== false) { |
| 6850 |
out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 6851 |
if (it.opts.messages !== false) { |
| 6852 |
out += ' , message: \''; |
| 6853 |
if (it.opts._errorDataPathProperty) { |
| 6854 |
out += 'is a required property'; |
| 6855 |
} else { |
| 6856 |
out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 6857 |
} |
| 6858 |
out += '\' '; |
| 6859 |
} |
| 6860 |
if (it.opts.verbose) { |
| 6861 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6862 |
} |
| 6863 |
out += ' } '; |
| 6864 |
} else { |
| 6865 |
out += ' {} '; |
| 6866 |
} |
| 6867 |
var __err = out; |
| 6868 |
out = $$outStack.pop(); |
| 6869 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6870 |
if (it.async) { |
| 6871 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6872 |
} else { |
| 6873 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6874 |
} |
| 6875 |
} else { |
| 6876 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6877 |
} |
| 6878 |
out += ' } else { '; |
| 6879 |
} else { |
| 6880 |
out += ' if ( '; |
| 6881 |
var arr2 = $required; |
| 6882 |
if (arr2) { |
| 6883 |
var _$property, $i = -1, |
| 6884 |
l2 = arr2.length - 1; |
| 6885 |
while ($i < l2) { |
| 6886 |
_$property = arr2[$i += 1]; |
| 6887 |
if ($i) { |
| 6888 |
out += ' || '; |
| 6889 |
} |
| 6890 |
var $prop = it.util.getProperty(_$property); |
| 6891 |
out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) '; |
| 6892 |
} |
| 6893 |
} |
| 6894 |
out += ') { '; |
| 6895 |
var $propertyPath = 'missing' + $lvl, |
| 6896 |
$missingProperty = '\' + ' + $propertyPath + ' + \''; |
| 6897 |
if (it.opts._errorDataPathProperty) { |
| 6898 |
it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath; |
| 6899 |
} |
| 6900 |
var $$outStack = $$outStack || []; |
| 6901 |
$$outStack.push(out); |
| 6902 |
out = ''; /* istanbul ignore else */ |
| 6903 |
if (it.createErrors !== false) { |
| 6904 |
out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 6905 |
if (it.opts.messages !== false) { |
| 6906 |
out += ' , message: \''; |
| 6907 |
if (it.opts._errorDataPathProperty) { |
| 6908 |
out += 'is a required property'; |
| 6909 |
} else { |
| 6910 |
out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 6911 |
} |
| 6912 |
out += '\' '; |
| 6913 |
} |
| 6914 |
if (it.opts.verbose) { |
| 6915 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6916 |
} |
| 6917 |
out += ' } '; |
| 6918 |
} else { |
| 6919 |
out += ' {} '; |
| 6920 |
} |
| 6921 |
var __err = out; |
| 6922 |
out = $$outStack.pop(); |
| 6923 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 6924 |
if (it.async) { |
| 6925 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 6926 |
} else { |
| 6927 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 6928 |
} |
| 6929 |
} else { |
| 6930 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 6931 |
} |
| 6932 |
out += ' } else { '; |
| 6933 |
} |
| 6934 |
} else { |
| 6935 |
if ($loopRequired) { |
| 6936 |
if (!$isData) { |
| 6937 |
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + '; '; |
| 6938 |
} |
| 6939 |
var $i = 'i' + $lvl, |
| 6940 |
$propertyPath = 'schema' + $lvl + '[' + $i + ']', |
| 6941 |
$missingProperty = '\' + ' + $propertyPath + ' + \''; |
| 6942 |
if (it.opts._errorDataPathProperty) { |
| 6943 |
it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers); |
| 6944 |
} |
| 6945 |
if ($isData) { |
| 6946 |
out += ' if (schema' + ($lvl) + ' && !Array.isArray(schema' + ($lvl) + ')) { var err = '; /* istanbul ignore else */ |
| 6947 |
if (it.createErrors !== false) { |
| 6948 |
out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 6949 |
if (it.opts.messages !== false) { |
| 6950 |
out += ' , message: \''; |
| 6951 |
if (it.opts._errorDataPathProperty) { |
| 6952 |
out += 'is a required property'; |
| 6953 |
} else { |
| 6954 |
out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 6955 |
} |
| 6956 |
out += '\' '; |
| 6957 |
} |
| 6958 |
if (it.opts.verbose) { |
| 6959 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6960 |
} |
| 6961 |
out += ' } '; |
| 6962 |
} else { |
| 6963 |
out += ' {} '; |
| 6964 |
} |
| 6965 |
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (schema' + ($lvl) + ' !== undefined) { '; |
| 6966 |
} |
| 6967 |
out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < schema' + ($lvl) + '.length; ' + ($i) + '++) { if (' + ($data) + '[schema' + ($lvl) + '[' + ($i) + ']] === undefined) { var err = '; /* istanbul ignore else */ |
| 6968 |
if (it.createErrors !== false) { |
| 6969 |
out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 6970 |
if (it.opts.messages !== false) { |
| 6971 |
out += ' , message: \''; |
| 6972 |
if (it.opts._errorDataPathProperty) { |
| 6973 |
out += 'is a required property'; |
| 6974 |
} else { |
| 6975 |
out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 6976 |
} |
| 6977 |
out += '\' '; |
| 6978 |
} |
| 6979 |
if (it.opts.verbose) { |
| 6980 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 6981 |
} |
| 6982 |
out += ' } '; |
| 6983 |
} else { |
| 6984 |
out += ' {} '; |
| 6985 |
} |
| 6986 |
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } '; |
| 6987 |
if ($isData) { |
| 6988 |
out += ' } '; |
| 6989 |
} |
| 6990 |
} else { |
| 6991 |
var arr3 = $required; |
| 6992 |
if (arr3) { |
| 6993 |
var $property, $i = -1, |
| 6994 |
l3 = arr3.length - 1; |
| 6995 |
while ($i < l3) { |
| 6996 |
$property = arr3[$i += 1]; |
| 6997 |
var $prop = it.util.getProperty($property), |
| 6998 |
$missingProperty = it.util.escapeQuotes($property); |
| 6999 |
if (it.opts._errorDataPathProperty) { |
| 7000 |
it.errorPath = it.util.getPath($currentErrorPath, $property, it.opts.jsonPointers); |
| 7001 |
} |
| 7002 |
out += ' if (' + ($data) + ($prop) + ' === undefined) { var err = '; /* istanbul ignore else */ |
| 7003 |
if (it.createErrors !== false) { |
| 7004 |
out += ' { keyword: \'' + ($errorKeyword || 'required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingProperty: \'' + ($missingProperty) + '\' } '; |
| 7005 |
if (it.opts.messages !== false) { |
| 7006 |
out += ' , message: \''; |
| 7007 |
if (it.opts._errorDataPathProperty) { |
| 7008 |
out += 'is a required property'; |
| 7009 |
} else { |
| 7010 |
out += 'should have required property \\\'' + ($missingProperty) + '\\\''; |
| 7011 |
} |
| 7012 |
out += '\' '; |
| 7013 |
} |
| 7014 |
if (it.opts.verbose) { |
| 7015 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 7016 |
} |
| 7017 |
out += ' } '; |
| 7018 |
} else { |
| 7019 |
out += ' {} '; |
| 7020 |
} |
| 7021 |
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } '; |
| 7022 |
} |
| 7023 |
} |
| 7024 |
} |
| 7025 |
} |
| 7026 |
it.errorPath = $currentErrorPath; |
| 7027 |
} else if ($breakOnError) { |
| 7028 |
out += ' if (true) {'; |
| 7029 |
} |
| 7030 |
return out; |
| 7031 |
} |
| 7032 |
|
| 7033 |
|
| 7034 |
/***/ }, |
| 7035 |
/* 42 */ |
| 7036 |
/***/ function(module, exports) { |
| 7037 |
|
| 7038 |
'use strict'; |
| 7039 |
module.exports = function generate_uniqueItems(it, $keyword) { |
| 7040 |
var out = ' '; |
| 7041 |
var $lvl = it.level; |
| 7042 |
var $dataLvl = it.dataLevel; |
| 7043 |
var $schema = it.schema[$keyword]; |
| 7044 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 7045 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 7046 |
var $breakOnError = !it.opts.allErrors; |
| 7047 |
var $errorKeyword; |
| 7048 |
var $data = 'data' + ($dataLvl || ''); |
| 7049 |
var $valid = 'valid' + $lvl; |
| 7050 |
var $isData = it.opts.v5 && $schema.$data; |
| 7051 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 7052 |
if ($isData) { |
| 7053 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 7054 |
$schemaValue = 'schema' + $lvl; |
| 7055 |
} |
| 7056 |
if (($schema || $isData) && it.opts.uniqueItems !== false) { |
| 7057 |
if ($isData) { |
| 7058 |
out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { '; |
| 7059 |
} |
| 7060 |
out += ' var ' + ($valid) + ' = true; if (' + ($data) + '.length > 1) { var i = ' + ($data) + '.length, j; outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } } '; |
| 7061 |
if ($isData) { |
| 7062 |
out += ' } '; |
| 7063 |
} |
| 7064 |
out += ' if (!' + ($valid) + ') { '; |
| 7065 |
var $$outStack = $$outStack || []; |
| 7066 |
$$outStack.push(out); |
| 7067 |
out = ''; /* istanbul ignore else */ |
| 7068 |
if (it.createErrors !== false) { |
| 7069 |
out += ' { keyword: \'' + ($errorKeyword || 'uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { i: i, j: j } '; |
| 7070 |
if (it.opts.messages !== false) { |
| 7071 |
out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' '; |
| 7072 |
} |
| 7073 |
if (it.opts.verbose) { |
| 7074 |
out += ' , schema: '; |
| 7075 |
if ($isData) { |
| 7076 |
out += 'validate.schema' + ($schemaPath); |
| 7077 |
} else { |
| 7078 |
out += '' + ($schema); |
| 7079 |
} |
| 7080 |
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 7081 |
} |
| 7082 |
out += ' } '; |
| 7083 |
} else { |
| 7084 |
out += ' {} '; |
| 7085 |
} |
| 7086 |
var __err = out; |
| 7087 |
out = $$outStack.pop(); |
| 7088 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 7089 |
if (it.async) { |
| 7090 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 7091 |
} else { |
| 7092 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 7093 |
} |
| 7094 |
} else { |
| 7095 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 7096 |
} |
| 7097 |
out += ' } '; |
| 7098 |
if ($breakOnError) { |
| 7099 |
out += ' else { '; |
| 7100 |
} |
| 7101 |
} else { |
| 7102 |
if ($breakOnError) { |
| 7103 |
out += ' if (true) { '; |
| 7104 |
} |
| 7105 |
} |
| 7106 |
return out; |
| 7107 |
} |
| 7108 |
|
| 7109 |
|
| 7110 |
/***/ }, |
| 7111 |
/* 43 */ |
| 7112 |
/***/ function(module, exports, __webpack_require__) { |
| 7113 |
|
| 7114 |
'use strict'; |
| 7115 |
|
| 7116 |
var META_SCHEMA_ID = 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json'; |
| 7117 |
|
| 7118 |
module.exports = { |
| 7119 |
enable: enableV5, |
| 7120 |
META_SCHEMA_ID: META_SCHEMA_ID |
| 7121 |
}; |
| 7122 |
|
| 7123 |
|
| 7124 |
function enableV5(ajv) { |
| 7125 |
var inlineFunctions = { |
| 7126 |
'switch': __webpack_require__(44), |
| 7127 |
'constant': __webpack_require__(45), |
| 7128 |
'_formatLimit': __webpack_require__(46), |
| 7129 |
'patternRequired': __webpack_require__(47) |
| 7130 |
}; |
| 7131 |
|
| 7132 |
if (ajv._opts.meta !== false) { |
| 7133 |
var metaSchema = __webpack_require__(48); |
| 7134 |
ajv.addMetaSchema(metaSchema, META_SCHEMA_ID); |
| 7135 |
} |
| 7136 |
_addKeyword('constant'); |
| 7137 |
ajv.addKeyword('contains', { type: 'array', macro: containsMacro }); |
| 7138 |
|
| 7139 |
_addKeyword('formatMaximum', 'string', inlineFunctions._formatLimit); |
| 7140 |
_addKeyword('formatMinimum', 'string', inlineFunctions._formatLimit); |
| 7141 |
ajv.addKeyword('exclusiveFormatMaximum'); |
| 7142 |
ajv.addKeyword('exclusiveFormatMinimum'); |
| 7143 |
|
| 7144 |
ajv.addKeyword('patternGroups'); // implemented in properties.jst |
| 7145 |
_addKeyword('patternRequired', 'object'); |
| 7146 |
_addKeyword('switch'); |
| 7147 |
|
| 7148 |
|
| 7149 |
function _addKeyword(keyword, types, inlineFunc) { |
| 7150 |
var definition = { |
| 7151 |
inline: inlineFunc || inlineFunctions[keyword], |
| 7152 |
statements: true, |
| 7153 |
errors: 'full' |
| 7154 |
}; |
| 7155 |
if (types) definition.type = types; |
| 7156 |
ajv.addKeyword(keyword, definition); |
| 7157 |
} |
| 7158 |
} |
| 7159 |
|
| 7160 |
|
| 7161 |
function containsMacro(schema) { |
| 7162 |
return { |
| 7163 |
not: { items: { not: schema } } |
| 7164 |
}; |
| 7165 |
} |
| 7166 |
|
| 7167 |
|
| 7168 |
/***/ }, |
| 7169 |
/* 44 */ |
| 7170 |
/***/ function(module, exports) { |
| 7171 |
|
| 7172 |
'use strict'; |
| 7173 |
module.exports = function generate_switch(it, $keyword) { |
| 7174 |
var out = ' '; |
| 7175 |
var $lvl = it.level; |
| 7176 |
var $dataLvl = it.dataLevel; |
| 7177 |
var $schema = it.schema[$keyword]; |
| 7178 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 7179 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 7180 |
var $breakOnError = !it.opts.allErrors; |
| 7181 |
var $errorKeyword; |
| 7182 |
var $data = 'data' + ($dataLvl || ''); |
| 7183 |
var $valid = 'valid' + $lvl; |
| 7184 |
var $errs = 'errs__' + $lvl; |
| 7185 |
var $it = it.util.copy(it); |
| 7186 |
var $closingBraces = ''; |
| 7187 |
$it.level++; |
| 7188 |
var $ifPassed = 'ifPassed' + it.level, |
| 7189 |
$shouldContinue; |
| 7190 |
out += 'var ' + ($ifPassed) + ';'; |
| 7191 |
var arr1 = $schema; |
| 7192 |
if (arr1) { |
| 7193 |
var $sch, $caseIndex = -1, |
| 7194 |
l1 = arr1.length - 1; |
| 7195 |
while ($caseIndex < l1) { |
| 7196 |
$sch = arr1[$caseIndex += 1]; |
| 7197 |
if ($caseIndex && !$shouldContinue) { |
| 7198 |
out += ' if (!' + ($ifPassed) + ') { '; |
| 7199 |
$closingBraces += '}'; |
| 7200 |
} |
| 7201 |
if ($sch.if && it.util.schemaHasRules($sch.if, it.RULES.all)) { |
| 7202 |
out += ' var ' + ($errs) + ' = errors; '; |
| 7203 |
var $wasComposite = it.compositeRule; |
| 7204 |
it.compositeRule = $it.compositeRule = true; |
| 7205 |
$it.createErrors = false; |
| 7206 |
$it.schema = $sch.if; |
| 7207 |
$it.schemaPath = $schemaPath + '[' + $caseIndex + '].if'; |
| 7208 |
$it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/if'; |
| 7209 |
out += ' ' + (it.validate($it)) + ' '; |
| 7210 |
$it.createErrors = true; |
| 7211 |
it.compositeRule = $it.compositeRule = $wasComposite; |
| 7212 |
out += ' ' + ($ifPassed) + ' = valid' + ($it.level) + '; if (' + ($ifPassed) + ') { '; |
| 7213 |
if (typeof $sch.then == 'boolean') { |
| 7214 |
if ($sch.then === false) { |
| 7215 |
var $$outStack = $$outStack || []; |
| 7216 |
$$outStack.push(out); |
| 7217 |
out = ''; /* istanbul ignore else */ |
| 7218 |
if (it.createErrors !== false) { |
| 7219 |
out += ' { keyword: \'' + ($errorKeyword || 'switch') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { caseIndex: ' + ($caseIndex) + ' } '; |
| 7220 |
if (it.opts.messages !== false) { |
| 7221 |
out += ' , message: \'should pass "switch" keyword validation\' '; |
| 7222 |
} |
| 7223 |
if (it.opts.verbose) { |
| 7224 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 7225 |
} |
| 7226 |
out += ' } '; |
| 7227 |
} else { |
| 7228 |
out += ' {} '; |
| 7229 |
} |
| 7230 |
var __err = out; |
| 7231 |
out = $$outStack.pop(); |
| 7232 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 7233 |
if (it.async) { |
| 7234 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 7235 |
} else { |
| 7236 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 7237 |
} |
| 7238 |
} else { |
| 7239 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 7240 |
} |
| 7241 |
} |
| 7242 |
out += ' var valid' + ($it.level) + ' = ' + ($sch.then) + '; '; |
| 7243 |
} else { |
| 7244 |
$it.schema = $sch.then; |
| 7245 |
$it.schemaPath = $schemaPath + '[' + $caseIndex + '].then'; |
| 7246 |
$it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/then'; |
| 7247 |
out += ' ' + (it.validate($it)) + ' '; |
| 7248 |
} |
| 7249 |
out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } } '; |
| 7250 |
} else { |
| 7251 |
out += ' ' + ($ifPassed) + ' = true; '; |
| 7252 |
if (typeof $sch.then == 'boolean') { |
| 7253 |
if ($sch.then === false) { |
| 7254 |
var $$outStack = $$outStack || []; |
| 7255 |
$$outStack.push(out); |
| 7256 |
out = ''; /* istanbul ignore else */ |
| 7257 |
if (it.createErrors !== false) { |
| 7258 |
out += ' { keyword: \'' + ($errorKeyword || 'switch') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { caseIndex: ' + ($caseIndex) + ' } '; |
| 7259 |
if (it.opts.messages !== false) { |
| 7260 |
out += ' , message: \'should pass "switch" keyword validation\' '; |
| 7261 |
} |
| 7262 |
if (it.opts.verbose) { |
| 7263 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 7264 |
} |
| 7265 |
out += ' } '; |
| 7266 |
} else { |
| 7267 |
out += ' {} '; |
| 7268 |
} |
| 7269 |
var __err = out; |
| 7270 |
out = $$outStack.pop(); |
| 7271 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 7272 |
if (it.async) { |
| 7273 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 7274 |
} else { |
| 7275 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 7276 |
} |
| 7277 |
} else { |
| 7278 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 7279 |
} |
| 7280 |
} |
| 7281 |
out += ' var valid' + ($it.level) + ' = ' + ($sch.then) + '; '; |
| 7282 |
} else { |
| 7283 |
$it.schema = $sch.then; |
| 7284 |
$it.schemaPath = $schemaPath + '[' + $caseIndex + '].then'; |
| 7285 |
$it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/then'; |
| 7286 |
out += ' ' + (it.validate($it)) + ' '; |
| 7287 |
} |
| 7288 |
} |
| 7289 |
$shouldContinue = $sch.continue |
| 7290 |
} |
| 7291 |
} |
| 7292 |
out += '' + ($closingBraces) + 'var ' + ($valid) + ' = valid' + ($it.level) + '; '; |
| 7293 |
out = it.util.cleanUpCode(out); |
| 7294 |
return out; |
| 7295 |
} |
| 7296 |
|
| 7297 |
|
| 7298 |
/***/ }, |
| 7299 |
/* 45 */ |
| 7300 |
/***/ function(module, exports) { |
| 7301 |
|
| 7302 |
'use strict'; |
| 7303 |
module.exports = function generate_constant(it, $keyword) { |
| 7304 |
var out = ' '; |
| 7305 |
var $lvl = it.level; |
| 7306 |
var $dataLvl = it.dataLevel; |
| 7307 |
var $schema = it.schema[$keyword]; |
| 7308 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 7309 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 7310 |
var $breakOnError = !it.opts.allErrors; |
| 7311 |
var $errorKeyword; |
| 7312 |
var $data = 'data' + ($dataLvl || ''); |
| 7313 |
var $valid = 'valid' + $lvl; |
| 7314 |
var $isData = it.opts.v5 && $schema.$data; |
| 7315 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 7316 |
if ($isData) { |
| 7317 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 7318 |
$schemaValue = 'schema' + $lvl; |
| 7319 |
} |
| 7320 |
if (!$isData) { |
| 7321 |
out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';'; |
| 7322 |
} |
| 7323 |
out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { '; |
| 7324 |
var $$outStack = $$outStack || []; |
| 7325 |
$$outStack.push(out); |
| 7326 |
out = ''; /* istanbul ignore else */ |
| 7327 |
if (it.createErrors !== false) { |
| 7328 |
out += ' { keyword: \'' + ($errorKeyword || 'constant') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} '; |
| 7329 |
if (it.opts.messages !== false) { |
| 7330 |
out += ' , message: \'should be equal to constant\' '; |
| 7331 |
} |
| 7332 |
if (it.opts.verbose) { |
| 7333 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 7334 |
} |
| 7335 |
out += ' } '; |
| 7336 |
} else { |
| 7337 |
out += ' {} '; |
| 7338 |
} |
| 7339 |
var __err = out; |
| 7340 |
out = $$outStack.pop(); |
| 7341 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 7342 |
if (it.async) { |
| 7343 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 7344 |
} else { |
| 7345 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 7346 |
} |
| 7347 |
} else { |
| 7348 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 7349 |
} |
| 7350 |
out += ' }'; |
| 7351 |
return out; |
| 7352 |
} |
| 7353 |
|
| 7354 |
|
| 7355 |
/***/ }, |
| 7356 |
/* 46 */ |
| 7357 |
/***/ function(module, exports) { |
| 7358 |
|
| 7359 |
'use strict'; |
| 7360 |
module.exports = function generate__formatLimit(it, $keyword) { |
| 7361 |
var out = ' '; |
| 7362 |
var $lvl = it.level; |
| 7363 |
var $dataLvl = it.dataLevel; |
| 7364 |
var $schema = it.schema[$keyword]; |
| 7365 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 7366 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 7367 |
var $breakOnError = !it.opts.allErrors; |
| 7368 |
var $errorKeyword; |
| 7369 |
var $data = 'data' + ($dataLvl || ''); |
| 7370 |
var $valid = 'valid' + $lvl; |
| 7371 |
out += 'var ' + ($valid) + ' = undefined;'; |
| 7372 |
if (it.opts.format === false) { |
| 7373 |
out += ' ' + ($valid) + ' = true; '; |
| 7374 |
return out; |
| 7375 |
} |
| 7376 |
var $schemaFormat = it.schema.format, |
| 7377 |
$isDataFormat = it.opts.v5 && $schemaFormat.$data, |
| 7378 |
$closingBraces = ''; |
| 7379 |
if ($isDataFormat) { |
| 7380 |
var $schemaValueFormat = it.util.getData($schemaFormat.$data, $dataLvl, it.dataPathArr), |
| 7381 |
$format = 'format' + $lvl, |
| 7382 |
$compare = 'compare' + $lvl; |
| 7383 |
out += ' var ' + ($format) + ' = formats[' + ($schemaValueFormat) + '] , ' + ($compare) + ' = ' + ($format) + ' && ' + ($format) + '.compare;'; |
| 7384 |
} else { |
| 7385 |
var $format = it.formats[$schemaFormat]; |
| 7386 |
if (!($format && $format.compare)) { |
| 7387 |
out += ' ' + ($valid) + ' = true; '; |
| 7388 |
return out; |
| 7389 |
} |
| 7390 |
var $compare = 'formats' + it.util.getProperty($schemaFormat) + '.compare'; |
| 7391 |
} |
| 7392 |
var $isMax = $keyword == 'formatMaximum', |
| 7393 |
$exclusiveKeyword = 'exclusiveFormat' + ($isMax ? 'Maximum' : 'Minimum'), |
| 7394 |
$schemaExcl = it.schema[$exclusiveKeyword], |
| 7395 |
$isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data, |
| 7396 |
$op = $isMax ? '<' : '>', |
| 7397 |
$result = 'result' + $lvl; |
| 7398 |
var $isData = it.opts.v5 && $schema.$data; |
| 7399 |
var $schemaValue = $isData ? it.util.getData($schema.$data, $dataLvl, it.dataPathArr) : $schema; |
| 7400 |
if ($isData) { |
| 7401 |
out += ' var schema' + ($lvl) + ' = ' + ($schemaValue) + '; '; |
| 7402 |
$schemaValue = 'schema' + $lvl; |
| 7403 |
} |
| 7404 |
if ($isDataExcl) { |
| 7405 |
var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr), |
| 7406 |
$exclusive = 'exclusive' + $lvl, |
| 7407 |
$opExpr = 'op' + $lvl, |
| 7408 |
$opStr = '\' + ' + $opExpr + ' + \''; |
| 7409 |
out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; '; |
| 7410 |
$schemaValueExcl = 'schemaExcl' + $lvl; |
| 7411 |
out += ' if (typeof ' + ($schemaValueExcl) + ' != \'boolean\' && ' + ($schemaValueExcl) + ' !== undefined) { ' + ($valid) + ' = false; '; |
| 7412 |
var $errorKeyword = $exclusiveKeyword; |
| 7413 |
var $$outStack = $$outStack || []; |
| 7414 |
$$outStack.push(out); |
| 7415 |
out = ''; /* istanbul ignore else */ |
| 7416 |
if (it.createErrors !== false) { |
| 7417 |
out += ' { keyword: \'' + ($errorKeyword || '_exclusiveFormatLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: {} '; |
| 7418 |
if (it.opts.messages !== false) { |
| 7419 |
out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' '; |
| 7420 |
} |
| 7421 |
if (it.opts.verbose) { |
| 7422 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 7423 |
} |
| 7424 |
out += ' } '; |
| 7425 |
} else { |
| 7426 |
out += ' {} '; |
| 7427 |
} |
| 7428 |
var __err = out; |
| 7429 |
out = $$outStack.pop(); |
| 7430 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 7431 |
if (it.async) { |
| 7432 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 7433 |
} else { |
| 7434 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 7435 |
} |
| 7436 |
} else { |
| 7437 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 7438 |
} |
| 7439 |
out += ' } '; |
| 7440 |
if ($breakOnError) { |
| 7441 |
$closingBraces += '}'; |
| 7442 |
out += ' else { '; |
| 7443 |
} |
| 7444 |
if ($isData) { |
| 7445 |
out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { '; |
| 7446 |
$closingBraces += '}'; |
| 7447 |
} |
| 7448 |
if ($isDataFormat) { |
| 7449 |
out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { '; |
| 7450 |
$closingBraces += '}'; |
| 7451 |
} |
| 7452 |
out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ', '; |
| 7453 |
if ($isData) { |
| 7454 |
out += '' + ($schemaValue); |
| 7455 |
} else { |
| 7456 |
out += '' + (it.util.toQuotedString($schema)); |
| 7457 |
} |
| 7458 |
out += ' ); if (' + ($result) + ' === undefined) ' + ($valid) + ' = false; var exclusive' + ($lvl) + ' = ' + ($schemaValueExcl) + ' === true; if (' + ($valid) + ' === undefined) { ' + ($valid) + ' = exclusive' + ($lvl) + ' ? ' + ($result) + ' ' + ($op) + ' 0 : ' + ($result) + ' ' + ($op) + '= 0; } if (!' + ($valid) + ') var op' + ($lvl) + ' = exclusive' + ($lvl) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';'; |
| 7459 |
} else { |
| 7460 |
var $exclusive = $schemaExcl === true, |
| 7461 |
$opStr = $op; |
| 7462 |
if (!$exclusive) $opStr += '='; |
| 7463 |
var $opExpr = '\'' + $opStr + '\''; |
| 7464 |
if ($isData) { |
| 7465 |
out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { '; |
| 7466 |
$closingBraces += '}'; |
| 7467 |
} |
| 7468 |
if ($isDataFormat) { |
| 7469 |
out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { '; |
| 7470 |
$closingBraces += '}'; |
| 7471 |
} |
| 7472 |
out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ', '; |
| 7473 |
if ($isData) { |
| 7474 |
out += '' + ($schemaValue); |
| 7475 |
} else { |
| 7476 |
out += '' + (it.util.toQuotedString($schema)); |
| 7477 |
} |
| 7478 |
out += ' ); if (' + ($result) + ' === undefined) ' + ($valid) + ' = false; if (' + ($valid) + ' === undefined) ' + ($valid) + ' = ' + ($result) + ' ' + ($op); |
| 7479 |
if (!$exclusive) { |
| 7480 |
out += '='; |
| 7481 |
} |
| 7482 |
out += ' 0;'; |
| 7483 |
} |
| 7484 |
out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { '; |
| 7485 |
var $errorKeyword = $keyword; |
| 7486 |
var $$outStack = $$outStack || []; |
| 7487 |
$$outStack.push(out); |
| 7488 |
out = ''; /* istanbul ignore else */ |
| 7489 |
if (it.createErrors !== false) { |
| 7490 |
out += ' { keyword: \'' + ($errorKeyword || '_formatLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { limit: '; |
| 7491 |
if ($isData) { |
| 7492 |
out += '' + ($schemaValue); |
| 7493 |
} else { |
| 7494 |
out += '' + (it.util.toQuotedString($schema)); |
| 7495 |
} |
| 7496 |
out += ' } '; |
| 7497 |
if (it.opts.messages !== false) { |
| 7498 |
out += ' , message: \'should be ' + ($opStr) + ' "'; |
| 7499 |
if ($isData) { |
| 7500 |
out += '\' + ' + ($schemaValue) + ' + \''; |
| 7501 |
} else { |
| 7502 |
out += '' + (it.util.escapeQuotes($schema)); |
| 7503 |
} |
| 7504 |
out += '"\' '; |
| 7505 |
} |
| 7506 |
if (it.opts.verbose) { |
| 7507 |
out += ' , schema: '; |
| 7508 |
if ($isData) { |
| 7509 |
out += 'validate.schema' + ($schemaPath); |
| 7510 |
} else { |
| 7511 |
out += '' + (it.util.toQuotedString($schema)); |
| 7512 |
} |
| 7513 |
out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 7514 |
} |
| 7515 |
out += ' } '; |
| 7516 |
} else { |
| 7517 |
out += ' {} '; |
| 7518 |
} |
| 7519 |
var __err = out; |
| 7520 |
out = $$outStack.pop(); |
| 7521 |
if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ |
| 7522 |
if (it.async) { |
| 7523 |
out += ' throw new ValidationError([' + (__err) + ']); '; |
| 7524 |
} else { |
| 7525 |
out += ' validate.errors = [' + (__err) + ']; return false; '; |
| 7526 |
} |
| 7527 |
} else { |
| 7528 |
out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; |
| 7529 |
} |
| 7530 |
out += '}'; |
| 7531 |
return out; |
| 7532 |
} |
| 7533 |
|
| 7534 |
|
| 7535 |
/***/ }, |
| 7536 |
/* 47 */ |
| 7537 |
/***/ function(module, exports) { |
| 7538 |
|
| 7539 |
'use strict'; |
| 7540 |
module.exports = function generate_patternRequired(it, $keyword) { |
| 7541 |
var out = ' '; |
| 7542 |
var $lvl = it.level; |
| 7543 |
var $dataLvl = it.dataLevel; |
| 7544 |
var $schema = it.schema[$keyword]; |
| 7545 |
var $schemaPath = it.schemaPath + '.' + $keyword; |
| 7546 |
var $errSchemaPath = it.errSchemaPath + '/' + $keyword; |
| 7547 |
var $breakOnError = !it.opts.allErrors; |
| 7548 |
var $errorKeyword; |
| 7549 |
var $data = 'data' + ($dataLvl || ''); |
| 7550 |
var $valid = 'valid' + $lvl; |
| 7551 |
var $key = 'key' + $lvl, |
| 7552 |
$matched = 'patternMatched' + $lvl, |
| 7553 |
$closingBraces = ''; |
| 7554 |
out += 'var ' + ($valid) + ' = true;'; |
| 7555 |
var arr1 = $schema; |
| 7556 |
if (arr1) { |
| 7557 |
var $pProperty, i1 = -1, |
| 7558 |
l1 = arr1.length - 1; |
| 7559 |
while (i1 < l1) { |
| 7560 |
$pProperty = arr1[i1 += 1]; |
| 7561 |
out += ' var ' + ($matched) + ' = false; for (var ' + ($key) + ' in ' + ($data) + ') { ' + ($matched) + ' = ' + (it.usePattern($pProperty)) + '.test(' + ($key) + '); if (' + ($matched) + ') break; } '; |
| 7562 |
var $missingPattern = it.util.escapeQuotes($pProperty); |
| 7563 |
out += ' if (!' + ($matched) + ') { ' + ($valid) + ' = false; var err = '; /* istanbul ignore else */ |
| 7564 |
if (it.createErrors !== false) { |
| 7565 |
out += ' { keyword: \'' + ($errorKeyword || 'patternRequired') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: "' + ($errSchemaPath) + '" , params: { missingPattern: \'' + ($missingPattern) + '\' } '; |
| 7566 |
if (it.opts.messages !== false) { |
| 7567 |
out += ' , message: \'should have property matching pattern \\\'' + ($missingPattern) + '\\\'\' '; |
| 7568 |
} |
| 7569 |
if (it.opts.verbose) { |
| 7570 |
out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; |
| 7571 |
} |
| 7572 |
out += ' } '; |
| 7573 |
} else { |
| 7574 |
out += ' {} '; |
| 7575 |
} |
| 7576 |
out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } '; |
| 7577 |
if ($breakOnError) { |
| 7578 |
$closingBraces += '}'; |
| 7579 |
out += ' else { '; |
| 7580 |
} |
| 7581 |
} |
| 7582 |
} |
| 7583 |
out += '' + ($closingBraces); |
| 7584 |
return out; |
| 7585 |
} |
| 7586 |
|
| 7587 |
|
| 7588 |
/***/ }, |
| 7589 |
/* 48 */ |
| 7590 |
/***/ function(module, exports) { |
| 7591 |
|
| 7592 |
module.exports = { |
| 7593 |
"id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#", |
| 7594 |
"$schema": "http://json-schema.org/draft-04/schema#", |
| 7595 |
"description": "Core schema meta-schema (v5 proposals)", |
| 7596 |
"definitions": { |
| 7597 |
"schemaArray": { |
| 7598 |
"type": "array", |
| 7599 |
"minItems": 1, |
| 7600 |
"items": { |
| 7601 |
"$ref": "#" |
| 7602 |
} |
| 7603 |
}, |
| 7604 |
"positiveInteger": { |
| 7605 |
"type": "integer", |
| 7606 |
"minimum": 0 |
| 7607 |
}, |
| 7608 |
"positiveIntegerDefault0": { |
| 7609 |
"allOf": [ |
| 7610 |
{ |
| 7611 |
"$ref": "#/definitions/positiveInteger" |
| 7612 |
}, |
| 7613 |
{ |
| 7614 |
"default": 0 |
| 7615 |
} |
| 7616 |
] |
| 7617 |
}, |
| 7618 |
"simpleTypes": { |
| 7619 |
"enum": [ |
| 7620 |
"array", |
| 7621 |
"boolean", |
| 7622 |
"integer", |
| 7623 |
"null", |
| 7624 |
"number", |
| 7625 |
"object", |
| 7626 |
"string" |
| 7627 |
] |
| 7628 |
}, |
| 7629 |
"stringArray": { |
| 7630 |
"type": "array", |
| 7631 |
"items": { |
| 7632 |
"type": "string" |
| 7633 |
}, |
| 7634 |
"minItems": 1, |
| 7635 |
"uniqueItems": true |
| 7636 |
}, |
| 7637 |
"$data": { |
| 7638 |
"type": "object", |
| 7639 |
"required": [ |
| 7640 |
"$data" |
| 7641 |
], |
| 7642 |
"properties": { |
| 7643 |
"$data": { |
| 7644 |
"type": "string", |
| 7645 |
"format": "relative-json-pointer" |
| 7646 |
} |
| 7647 |
}, |
| 7648 |
"additionalProperties": false |
| 7649 |
} |
| 7650 |
}, |
| 7651 |
"type": "object", |
| 7652 |
"properties": { |
| 7653 |
"id": { |
| 7654 |
"type": "string", |
| 7655 |
"format": "uri" |
| 7656 |
}, |
| 7657 |
"$schema": { |
| 7658 |
"type": "string", |
| 7659 |
"format": "uri" |
| 7660 |
}, |
| 7661 |
"title": { |
| 7662 |
"type": "string" |
| 7663 |
}, |
| 7664 |
"description": { |
| 7665 |
"type": "string" |
| 7666 |
}, |
| 7667 |
"default": {}, |
| 7668 |
"multipleOf": { |
| 7669 |
"anyOf": [ |
| 7670 |
{ |
| 7671 |
"type": "number", |
| 7672 |
"minimum": 0, |
| 7673 |
"exclusiveMinimum": true |
| 7674 |
}, |
| 7675 |
{ |
| 7676 |
"$ref": "#/definitions/$data" |
| 7677 |
} |
| 7678 |
] |
| 7679 |
}, |
| 7680 |
"maximum": { |
| 7681 |
"anyOf": [ |
| 7682 |
{ |
| 7683 |
"type": "number" |
| 7684 |
}, |
| 7685 |
{ |
| 7686 |
"$ref": "#/definitions/$data" |
| 7687 |
} |
| 7688 |
] |
| 7689 |
}, |
| 7690 |
"exclusiveMaximum": { |
| 7691 |
"anyOf": [ |
| 7692 |
{ |
| 7693 |
"type": "boolean", |
| 7694 |
"default": false |
| 7695 |
}, |
| 7696 |
{ |
| 7697 |
"$ref": "#/definitions/$data" |
| 7698 |
} |
| 7699 |
] |
| 7700 |
}, |
| 7701 |
"minimum": { |
| 7702 |
"anyOf": [ |
| 7703 |
{ |
| 7704 |
"type": "number" |
| 7705 |
}, |
| 7706 |
{ |
| 7707 |
"$ref": "#/definitions/$data" |
| 7708 |
} |
| 7709 |
] |
| 7710 |
}, |
| 7711 |
"exclusiveMinimum": { |
| 7712 |
"anyOf": [ |
| 7713 |
{ |
| 7714 |
"type": "boolean", |
| 7715 |
"default": false |
| 7716 |
}, |
| 7717 |
{ |
| 7718 |
"$ref": "#/definitions/$data" |
| 7719 |
} |
| 7720 |
] |
| 7721 |
}, |
| 7722 |
"maxLength": { |
| 7723 |
"anyOf": [ |
| 7724 |
{ |
| 7725 |
"$ref": "#/definitions/positiveInteger" |
| 7726 |
}, |
| 7727 |
{ |
| 7728 |
"$ref": "#/definitions/$data" |
| 7729 |
} |
| 7730 |
] |
| 7731 |
}, |
| 7732 |
"minLength": { |
| 7733 |
"anyOf": [ |
| 7734 |
{ |
| 7735 |
"$ref": "#/definitions/positiveIntegerDefault0" |
| 7736 |
}, |
| 7737 |
{ |
| 7738 |
"$ref": "#/definitions/$data" |
| 7739 |
} |
| 7740 |
] |
| 7741 |
}, |
| 7742 |
"pattern": { |
| 7743 |
"anyOf": [ |
| 7744 |
{ |
| 7745 |
"type": "string", |
| 7746 |
"format": "regex" |
| 7747 |
}, |
| 7748 |
{ |
| 7749 |
"$ref": "#/definitions/$data" |
| 7750 |
} |
| 7751 |
] |
| 7752 |
}, |
| 7753 |
"additionalItems": { |
| 7754 |
"anyOf": [ |
| 7755 |
{ |
| 7756 |
"type": "boolean" |
| 7757 |
}, |
| 7758 |
{ |
| 7759 |
"$ref": "#" |
| 7760 |
}, |
| 7761 |
{ |
| 7762 |
"$ref": "#/definitions/$data" |
| 7763 |
} |
| 7764 |
], |
| 7765 |
"default": {} |
| 7766 |
}, |
| 7767 |
"items": { |
| 7768 |
"anyOf": [ |
| 7769 |
{ |
| 7770 |
"$ref": "#" |
| 7771 |
}, |
| 7772 |
{ |
| 7773 |
"$ref": "#/definitions/schemaArray" |
| 7774 |
} |
| 7775 |
], |
| 7776 |
"default": {} |
| 7777 |
}, |
| 7778 |
"maxItems": { |
| 7779 |
"anyOf": [ |
| 7780 |
{ |
| 7781 |
"$ref": "#/definitions/positiveInteger" |
| 7782 |
}, |
| 7783 |
{ |
| 7784 |
"$ref": "#/definitions/$data" |
| 7785 |
} |
| 7786 |
] |
| 7787 |
}, |
| 7788 |
"minItems": { |
| 7789 |
"anyOf": [ |
| 7790 |
{ |
| 7791 |
"$ref": "#/definitions/positiveIntegerDefault0" |
| 7792 |
}, |
| 7793 |
{ |
| 7794 |
"$ref": "#/definitions/$data" |
| 7795 |
} |
| 7796 |
] |
| 7797 |
}, |
| 7798 |
"uniqueItems": { |
| 7799 |
"anyOf": [ |
| 7800 |
{ |
| 7801 |
"type": "boolean", |
| 7802 |
"default": false |
| 7803 |
}, |
| 7804 |
{ |
| 7805 |
"$ref": "#/definitions/$data" |
| 7806 |
} |
| 7807 |
] |
| 7808 |
}, |
| 7809 |
"maxProperties": { |
| 7810 |
"anyOf": [ |
| 7811 |
{ |
| 7812 |
"$ref": "#/definitions/positiveInteger" |
| 7813 |
}, |
| 7814 |
{ |
| 7815 |
"$ref": "#/definitions/$data" |
| 7816 |
} |
| 7817 |
] |
| 7818 |
}, |
| 7819 |
"minProperties": { |
| 7820 |
"anyOf": [ |
| 7821 |
{ |
| 7822 |
"$ref": "#/definitions/positiveIntegerDefault0" |
| 7823 |
}, |
| 7824 |
{ |
| 7825 |
"$ref": "#/definitions/$data" |
| 7826 |
} |
| 7827 |
] |
| 7828 |
}, |
| 7829 |
"required": { |
| 7830 |
"anyOf": [ |
| 7831 |
{ |
| 7832 |
"$ref": "#/definitions/stringArray" |
| 7833 |
}, |
| 7834 |
{ |
| 7835 |
"$ref": "#/definitions/$data" |
| 7836 |
} |
| 7837 |
] |
| 7838 |
}, |
| 7839 |
"additionalProperties": { |
| 7840 |
"anyOf": [ |
| 7841 |
{ |
| 7842 |
"type": "boolean" |
| 7843 |
}, |
| 7844 |
{ |
| 7845 |
"$ref": "#" |
| 7846 |
}, |
| 7847 |
{ |
| 7848 |
"$ref": "#/definitions/$data" |
| 7849 |
} |
| 7850 |
], |
| 7851 |
"default": {} |
| 7852 |
}, |
| 7853 |
"definitions": { |
| 7854 |
"type": "object", |
| 7855 |
"additionalProperties": { |
| 7856 |
"$ref": "#" |
| 7857 |
}, |
| 7858 |
"default": {} |
| 7859 |
}, |
| 7860 |
"properties": { |
| 7861 |
"type": "object", |
| 7862 |
"additionalProperties": { |
| 7863 |
"$ref": "#" |
| 7864 |
}, |
| 7865 |
"default": {} |
| 7866 |
}, |
| 7867 |
"patternProperties": { |
| 7868 |
"type": "object", |
| 7869 |
"additionalProperties": { |
| 7870 |
"$ref": "#" |
| 7871 |
}, |
| 7872 |
"default": {} |
| 7873 |
}, |
| 7874 |
"dependencies": { |
| 7875 |
"type": "object", |
| 7876 |
"additionalProperties": { |
| 7877 |
"anyOf": [ |
| 7878 |
{ |
| 7879 |
"$ref": "#" |
| 7880 |
}, |
| 7881 |
{ |
| 7882 |
"$ref": "#/definitions/stringArray" |
| 7883 |
} |
| 7884 |
] |
| 7885 |
} |
| 7886 |
}, |
| 7887 |
"enum": { |
| 7888 |
"anyOf": [ |
| 7889 |
{ |
| 7890 |
"type": "array", |
| 7891 |
"minItems": 1, |
| 7892 |
"uniqueItems": true |
| 7893 |
}, |
| 7894 |
{ |
| 7895 |
"$ref": "#/definitions/$data" |
| 7896 |
} |
| 7897 |
] |
| 7898 |
}, |
| 7899 |
"type": { |
| 7900 |
"anyOf": [ |
| 7901 |
{ |
| 7902 |
"$ref": "#/definitions/simpleTypes" |
| 7903 |
}, |
| 7904 |
{ |
| 7905 |
"type": "array", |
| 7906 |
"items": { |
| 7907 |
"$ref": "#/definitions/simpleTypes" |
| 7908 |
}, |
| 7909 |
"minItems": 1, |
| 7910 |
"uniqueItems": true |
| 7911 |
} |
| 7912 |
] |
| 7913 |
}, |
| 7914 |
"allOf": { |
| 7915 |
"$ref": "#/definitions/schemaArray" |
| 7916 |
}, |
| 7917 |
"anyOf": { |
| 7918 |
"$ref": "#/definitions/schemaArray" |
| 7919 |
}, |
| 7920 |
"oneOf": { |
| 7921 |
"$ref": "#/definitions/schemaArray" |
| 7922 |
}, |
| 7923 |
"not": { |
| 7924 |
"$ref": "#" |
| 7925 |
}, |
| 7926 |
"format": { |
| 7927 |
"anyOf": [ |
| 7928 |
{ |
| 7929 |
"type": "string" |
| 7930 |
}, |
| 7931 |
{ |
| 7932 |
"$ref": "#/definitions/$data" |
| 7933 |
} |
| 7934 |
] |
| 7935 |
}, |
| 7936 |
"formatMaximum": { |
| 7937 |
"anyOf": [ |
| 7938 |
{ |
| 7939 |
"type": "string" |
| 7940 |
}, |
| 7941 |
{ |
| 7942 |
"$ref": "#/definitions/$data" |
| 7943 |
} |
| 7944 |
] |
| 7945 |
}, |
| 7946 |
"formatMinimum": { |
| 7947 |
"anyOf": [ |
| 7948 |
{ |
| 7949 |
"type": "string" |
| 7950 |
}, |
| 7951 |
{ |
| 7952 |
"$ref": "#/definitions/$data" |
| 7953 |
} |
| 7954 |
] |
| 7955 |
}, |
| 7956 |
"exclusiveFormatMaximum": { |
| 7957 |
"anyOf": [ |
| 7958 |
{ |
| 7959 |
"type": "boolean", |
| 7960 |
"default": false |
| 7961 |
}, |
| 7962 |
{ |
| 7963 |
"$ref": "#/definitions/$data" |
| 7964 |
} |
| 7965 |
] |
| 7966 |
}, |
| 7967 |
"exclusiveFormatMinimum": { |
| 7968 |
"anyOf": [ |
| 7969 |
{ |
| 7970 |
"type": "boolean", |
| 7971 |
"default": false |
| 7972 |
}, |
| 7973 |
{ |
| 7974 |
"$ref": "#/definitions/$data" |
| 7975 |
} |
| 7976 |
] |
| 7977 |
}, |
| 7978 |
"constant": { |
| 7979 |
"anyOf": [ |
| 7980 |
{}, |
| 7981 |
{ |
| 7982 |
"$ref": "#/definitions/$data" |
| 7983 |
} |
| 7984 |
] |
| 7985 |
}, |
| 7986 |
"contains": { |
| 7987 |
"$ref": "#" |
| 7988 |
}, |
| 7989 |
"patternGroups": { |
| 7990 |
"type": "object", |
| 7991 |
"additionalProperties": { |
| 7992 |
"type": "object", |
| 7993 |
"required": [ |
| 7994 |
"schema" |
| 7995 |
], |
| 7996 |
"properties": { |
| 7997 |
"maximum": { |
| 7998 |
"anyOf": [ |
| 7999 |
{ |
| 8000 |
"$ref": "#/definitions/positiveInteger" |
| 8001 |
}, |
| 8002 |
{ |
| 8003 |
"$ref": "#/definitions/$data" |
| 8004 |
} |
| 8005 |
] |
| 8006 |
}, |
| 8007 |
"minimum": { |
| 8008 |
"anyOf": [ |
| 8009 |
{ |
| 8010 |
"$ref": "#/definitions/positiveIntegerDefault0" |
| 8011 |
}, |
| 8012 |
{ |
| 8013 |
"$ref": "#/definitions/$data" |
| 8014 |
} |
| 8015 |
] |
| 8016 |
}, |
| 8017 |
"schema": { |
| 8018 |
"$ref": "#" |
| 8019 |
} |
| 8020 |
}, |
| 8021 |
"additionalProperties": false |
| 8022 |
}, |
| 8023 |
"default": {} |
| 8024 |
}, |
| 8025 |
"switch": { |
| 8026 |
"type": "array", |
| 8027 |
"items": { |
| 8028 |
"required": [ |
| 8029 |
"then" |
| 8030 |
], |
| 8031 |
"properties": { |
| 8032 |
"if": { |
| 8033 |
"$ref": "#" |
| 8034 |
}, |
| 8035 |
"then": { |
| 8036 |
"anyOf": [ |
| 8037 |
{ |
| 8038 |
"type": "boolean" |
| 8039 |
}, |
| 8040 |
{ |
| 8041 |
"$ref": "#" |
| 8042 |
} |
| 8043 |
] |
| 8044 |
}, |
| 8045 |
"continue": { |
| 8046 |
"type": "boolean" |
| 8047 |
} |
| 8048 |
}, |
| 8049 |
"additionalProperties": false, |
| 8050 |
"dependencies": { |
| 8051 |
"continue": [ |
| 8052 |
"if" |
| 8053 |
] |
| 8054 |
} |
| 8055 |
} |
| 8056 |
} |
| 8057 |
}, |
| 8058 |
"dependencies": { |
| 8059 |
"exclusiveMaximum": [ |
| 8060 |
"maximum" |
| 8061 |
], |
| 8062 |
"exclusiveMinimum": [ |
| 8063 |
"minimum" |
| 8064 |
], |
| 8065 |
"formatMaximum": [ |
| 8066 |
"format" |
| 8067 |
], |
| 8068 |
"formatMinimum": [ |
| 8069 |
"format" |
| 8070 |
], |
| 8071 |
"exclusiveFormatMaximum": [ |
| 8072 |
"formatMaximum" |
| 8073 |
], |
| 8074 |
"exclusiveFormatMinimum": [ |
| 8075 |
"formatMinimum" |
| 8076 |
] |
| 8077 |
}, |
| 8078 |
"default": {} |
| 8079 |
}; |
| 8080 |
|
| 8081 |
/***/ }, |
| 8082 |
/* 49 */ |
| 8083 |
/***/ function(module, exports) { |
| 8084 |
|
| 8085 |
'use strict'; |
| 8086 |
|
| 8087 |
var IDENTIFIER = /^[a-z_$][a-z0-9_$]*$/i; |
| 8088 |
|
| 8089 |
/** |
| 8090 |
* Define custom keyword |
| 8091 |
* @this Ajv |
| 8092 |
* @param {String} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords. |
| 8093 |
* @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`. |
| 8094 |
*/ |
| 8095 |
module.exports = function addKeyword(keyword, definition) { |
| 8096 |
/* eslint no-shadow: 0 */ |
| 8097 |
var self = this; |
| 8098 |
if (this.RULES.keywords[keyword]) |
| 8099 |
throw new Error('Keyword ' + keyword + ' is already defined'); |
| 8100 |
|
| 8101 |
if (!IDENTIFIER.test(keyword)) |
| 8102 |
throw new Error('Keyword ' + keyword + ' is not a valid identifier'); |
| 8103 |
|
| 8104 |
if (definition) { |
| 8105 |
var dataType = definition.type; |
| 8106 |
if (Array.isArray(dataType)) { |
| 8107 |
var i, len = dataType.length; |
| 8108 |
for (i=0; i<len; i++) checkDataType(dataType[i]); |
| 8109 |
for (i=0; i<len; i++) _addRule(keyword, dataType[i], definition); |
| 8110 |
} else { |
| 8111 |
if (dataType) checkDataType(dataType); |
| 8112 |
_addRule(keyword, dataType, definition); |
| 8113 |
} |
| 8114 |
} |
| 8115 |
|
| 8116 |
this.RULES.keywords[keyword] = true; |
| 8117 |
this.RULES.all[keyword] = true; |
| 8118 |
|
| 8119 |
|
| 8120 |
function _addRule(keyword, dataType, definition) { |
| 8121 |
var ruleGroup; |
| 8122 |
for (var i=0; i<self.RULES.length; i++) { |
| 8123 |
var rg = self.RULES[i]; |
| 8124 |
if (rg.type == dataType) { |
| 8125 |
ruleGroup = rg; |
| 8126 |
break; |
| 8127 |
} |
| 8128 |
} |
| 8129 |
|
| 8130 |
if (!ruleGroup) { |
| 8131 |
ruleGroup = { type: dataType, rules: [] }; |
| 8132 |
self.RULES.push(ruleGroup); |
| 8133 |
} |
| 8134 |
|
| 8135 |
var rule = { keyword: keyword, definition: definition, custom: true }; |
| 8136 |
ruleGroup.rules.push(rule); |
| 8137 |
} |
| 8138 |
|
| 8139 |
|
| 8140 |
function checkDataType(dataType) { |
| 8141 |
if (!self.RULES.types[dataType]) throw new Error('Unknown type ' + dataType); |
| 8142 |
} |
| 8143 |
}; |
| 8144 |
|
| 8145 |
|
| 8146 |
/***/ }, |
| 8147 |
/* 50 */ |
| 8148 |
/***/ function(module, exports) { |
| 8149 |
|
| 8150 |
module.exports = { |
| 8151 |
"id": "http://json-schema.org/draft-04/schema#", |
| 8152 |
"$schema": "http://json-schema.org/draft-04/schema#", |
| 8153 |
"description": "Core schema meta-schema", |
| 8154 |
"definitions": { |
| 8155 |
"schemaArray": { |
| 8156 |
"type": "array", |
| 8157 |
"minItems": 1, |
| 8158 |
"items": { |
| 8159 |
"$ref": "#" |
| 8160 |
} |
| 8161 |
}, |
| 8162 |
"positiveInteger": { |
| 8163 |
"type": "integer", |
| 8164 |
"minimum": 0 |
| 8165 |
}, |
| 8166 |
"positiveIntegerDefault0": { |
| 8167 |
"allOf": [ |
| 8168 |
{ |
| 8169 |
"$ref": "#/definitions/positiveInteger" |
| 8170 |
}, |
| 8171 |
{ |
| 8172 |
"default": 0 |
| 8173 |
} |
| 8174 |
] |
| 8175 |
}, |
| 8176 |
"simpleTypes": { |
| 8177 |
"enum": [ |
| 8178 |
"array", |
| 8179 |
"boolean", |
| 8180 |
"integer", |
| 8181 |
"null", |
| 8182 |
"number", |
| 8183 |
"object", |
| 8184 |
"string" |
| 8185 |
] |
| 8186 |
}, |
| 8187 |
"stringArray": { |
| 8188 |
"type": "array", |
| 8189 |
"items": { |
| 8190 |
"type": "string" |
| 8191 |
}, |
| 8192 |
"minItems": 1, |
| 8193 |
"uniqueItems": true |
| 8194 |
} |
| 8195 |
}, |
| 8196 |
"type": "object", |
| 8197 |
"properties": { |
| 8198 |
"id": { |
| 8199 |
"type": "string", |
| 8200 |
"format": "uri" |
| 8201 |
}, |
| 8202 |
"$schema": { |
| 8203 |
"type": "string", |
| 8204 |
"format": "uri" |
| 8205 |
}, |
| 8206 |
"title": { |
| 8207 |
"type": "string" |
| 8208 |
}, |
| 8209 |
"description": { |
| 8210 |
"type": "string" |
| 8211 |
}, |
| 8212 |
"default": {}, |
| 8213 |
"multipleOf": { |
| 8214 |
"type": "number", |
| 8215 |
"minimum": 0, |
| 8216 |
"exclusiveMinimum": true |
| 8217 |
}, |
| 8218 |
"maximum": { |
| 8219 |
"type": "number" |
| 8220 |
}, |
| 8221 |
"exclusiveMaximum": { |
| 8222 |
"type": "boolean", |
| 8223 |
"default": false |
| 8224 |
}, |
| 8225 |
"minimum": { |
| 8226 |
"type": "number" |
| 8227 |
}, |
| 8228 |
"exclusiveMinimum": { |
| 8229 |
"type": "boolean", |
| 8230 |
"default": false |
| 8231 |
}, |
| 8232 |
"maxLength": { |
| 8233 |
"$ref": "#/definitions/positiveInteger" |
| 8234 |
}, |
| 8235 |
"minLength": { |
| 8236 |
"$ref": "#/definitions/positiveIntegerDefault0" |
| 8237 |
}, |
| 8238 |
"pattern": { |
| 8239 |
"type": "string", |
| 8240 |
"format": "regex" |
| 8241 |
}, |
| 8242 |
"additionalItems": { |
| 8243 |
"anyOf": [ |
| 8244 |
{ |
| 8245 |
"type": "boolean" |
| 8246 |
}, |
| 8247 |
{ |
| 8248 |
"$ref": "#" |
| 8249 |
} |
| 8250 |
], |
| 8251 |
"default": {} |
| 8252 |
}, |
| 8253 |
"items": { |
| 8254 |
"anyOf": [ |
| 8255 |
{ |
| 8256 |
"$ref": "#" |
| 8257 |
}, |
| 8258 |
{ |
| 8259 |
"$ref": "#/definitions/schemaArray" |
| 8260 |
} |
| 8261 |
], |
| 8262 |
"default": {} |
| 8263 |
}, |
| 8264 |
"maxItems": { |
| 8265 |
"$ref": "#/definitions/positiveInteger" |
| 8266 |
}, |
| 8267 |
"minItems": { |
| 8268 |
"$ref": "#/definitions/positiveIntegerDefault0" |
| 8269 |
}, |
| 8270 |
"uniqueItems": { |
| 8271 |
"type": "boolean", |
| 8272 |
"default": false |
| 8273 |
}, |
| 8274 |
"maxProperties": { |
| 8275 |
"$ref": "#/definitions/positiveInteger" |
| 8276 |
}, |
| 8277 |
"minProperties": { |
| 8278 |
"$ref": "#/definitions/positiveIntegerDefault0" |
| 8279 |
}, |
| 8280 |
"required": { |
| 8281 |
"$ref": "#/definitions/stringArray" |
| 8282 |
}, |
| 8283 |
"additionalProperties": { |
| 8284 |
"anyOf": [ |
| 8285 |
{ |
| 8286 |
"type": "boolean" |
| 8287 |
}, |
| 8288 |
{ |
| 8289 |
"$ref": "#" |
| 8290 |
} |
| 8291 |
], |
| 8292 |
"default": {} |
| 8293 |
}, |
| 8294 |
"definitions": { |
| 8295 |
"type": "object", |
| 8296 |
"additionalProperties": { |
| 8297 |
"$ref": "#" |
| 8298 |
}, |
| 8299 |
"default": {} |
| 8300 |
}, |
| 8301 |
"properties": { |
| 8302 |
"type": "object", |
| 8303 |
"additionalProperties": { |
| 8304 |
"$ref": "#" |
| 8305 |
}, |
| 8306 |
"default": {} |
| 8307 |
}, |
| 8308 |
"patternProperties": { |
| 8309 |
"type": "object", |
| 8310 |
"additionalProperties": { |
| 8311 |
"$ref": "#" |
| 8312 |
}, |
| 8313 |
"default": {} |
| 8314 |
}, |
| 8315 |
"dependencies": { |
| 8316 |
"type": "object", |
| 8317 |
"additionalProperties": { |
| 8318 |
"anyOf": [ |
| 8319 |
{ |
| 8320 |
"$ref": "#" |
| 8321 |
}, |
| 8322 |
{ |
| 8323 |
"$ref": "#/definitions/stringArray" |
| 8324 |
} |
| 8325 |
] |
| 8326 |
} |
| 8327 |
}, |
| 8328 |
"enum": { |
| 8329 |
"type": "array", |
| 8330 |
"minItems": 1, |
| 8331 |
"uniqueItems": true |
| 8332 |
}, |
| 8333 |
"type": { |
| 8334 |
"anyOf": [ |
| 8335 |
{ |
| 8336 |
"$ref": "#/definitions/simpleTypes" |
| 8337 |
}, |
| 8338 |
{ |
| 8339 |
"type": "array", |
| 8340 |
"items": { |
| 8341 |
"$ref": "#/definitions/simpleTypes" |
| 8342 |
}, |
| 8343 |
"minItems": 1, |
| 8344 |
"uniqueItems": true |
| 8345 |
} |
| 8346 |
] |
| 8347 |
}, |
| 8348 |
"allOf": { |
| 8349 |
"$ref": "#/definitions/schemaArray" |
| 8350 |
}, |
| 8351 |
"anyOf": { |
| 8352 |
"$ref": "#/definitions/schemaArray" |
| 8353 |
}, |
| 8354 |
"oneOf": { |
| 8355 |
"$ref": "#/definitions/schemaArray" |
| 8356 |
}, |
| 8357 |
"not": { |
| 8358 |
"$ref": "#" |
| 8359 |
} |
| 8360 |
}, |
| 8361 |
"dependencies": { |
| 8362 |
"exclusiveMaximum": [ |
| 8363 |
"maximum" |
| 8364 |
], |
| 8365 |
"exclusiveMinimum": [ |
| 8366 |
"minimum" |
| 8367 |
] |
| 8368 |
}, |
| 8369 |
"default": {} |
| 8370 |
}; |
| 8371 |
|
| 8372 |
/***/ }, |
| 8373 |
/* 51 */ |
| 8374 |
/***/ function(module, exports, __webpack_require__) { |
| 8375 |
|
| 8376 |
'use strict'; |
| 8377 |
|
| 8378 |
|
| 8379 |
var Highlighter = __webpack_require__(52); |
| 8380 |
var History = __webpack_require__(53); |
| 8381 |
var SearchBox = __webpack_require__(56); |
| 8382 |
var ContextMenu = __webpack_require__(57); |
| 8383 |
var Node = __webpack_require__(58); |
| 8384 |
var ModeSwitcher = __webpack_require__(61); |
| 8385 |
var util = __webpack_require__(54); |
| 8386 |
|
| 8387 |
// create a mixin with the functions for tree mode |
| 8388 |
var treemode = {}; |
| 8389 |
|
| 8390 |
/** |
| 8391 |
* Create a tree editor |
| 8392 |
* @param {Element} container Container element |
| 8393 |
* @param {Object} [options] Object with options. available options: |
| 8394 |
* {String} mode Editor mode. Available values: |
| 8395 |
* 'tree' (default), 'view', |
| 8396 |
* and 'form'. |
| 8397 |
* {Boolean} search Enable search box. |
| 8398 |
* True by default |
| 8399 |
* {Boolean} history Enable history (undo/redo). |
| 8400 |
* True by default |
| 8401 |
* {function} onChange Callback method, triggered |
| 8402 |
* on change of contents |
| 8403 |
* {String} name Field name for the root node. |
| 8404 |
* {boolean} escapeUnicode If true, unicode |
| 8405 |
* characters are escaped. |
| 8406 |
* false by default. |
| 8407 |
* {Object} schema A JSON Schema for validation |
| 8408 |
* @private |
| 8409 |
*/ |
| 8410 |
treemode.create = function (container, options) { |
| 8411 |
if (!container) { |
| 8412 |
throw new Error('No container element provided.'); |
| 8413 |
} |
| 8414 |
this.container = container; |
| 8415 |
this.dom = {}; |
| 8416 |
this.highlighter = new Highlighter(); |
| 8417 |
this.selection = undefined; // will hold the last input selection |
| 8418 |
this.multiselection = { |
| 8419 |
nodes: [] |
| 8420 |
}; |
| 8421 |
this.validateSchema = null; // will be set in .setSchema(schema) |
| 8422 |
this.errorNodes = []; |
| 8423 |
|
| 8424 |
this.node = null; |
| 8425 |
this.focusTarget = null; |
| 8426 |
|
| 8427 |
this._setOptions(options); |
| 8428 |
|
| 8429 |
if (this.options.history && this.options.mode !== 'view') { |
| 8430 |
this.history = new History(this); |
| 8431 |
} |
| 8432 |
|
| 8433 |
this._createFrame(); |
| 8434 |
this._createTable(); |
| 8435 |
}; |
| 8436 |
|
| 8437 |
/** |
| 8438 |
* Destroy the editor. Clean up DOM, event listeners, and web workers. |
| 8439 |
*/ |
| 8440 |
treemode.destroy = function () { |
| 8441 |
if (this.frame && this.container && this.frame.parentNode == this.container) { |
| 8442 |
this.container.removeChild(this.frame); |
| 8443 |
this.frame = null; |
| 8444 |
} |
| 8445 |
this.container = null; |
| 8446 |
|
| 8447 |
this.dom = null; |
| 8448 |
|
| 8449 |
this.clear(); |
| 8450 |
this.node = null; |
| 8451 |
this.focusTarget = null; |
| 8452 |
this.selection = null; |
| 8453 |
this.multiselection = null; |
| 8454 |
this.errorNodes = null; |
| 8455 |
this.validateSchema = null; |
| 8456 |
this._debouncedValidate = null; |
| 8457 |
|
| 8458 |
if (this.history) { |
| 8459 |
this.history.destroy(); |
| 8460 |
this.history = null; |
| 8461 |
} |
| 8462 |
|
| 8463 |
if (this.searchBox) { |
| 8464 |
this.searchBox.destroy(); |
| 8465 |
this.searchBox = null; |
| 8466 |
} |
| 8467 |
|
| 8468 |
if (this.modeSwitcher) { |
| 8469 |
this.modeSwitcher.destroy(); |
| 8470 |
this.modeSwitcher = null; |
| 8471 |
} |
| 8472 |
}; |
| 8473 |
|
| 8474 |
/** |
| 8475 |
* Initialize and set default options |
| 8476 |
* @param {Object} [options] See description in constructor |
| 8477 |
* @private |
| 8478 |
*/ |
| 8479 |
treemode._setOptions = function (options) { |
| 8480 |
this.options = { |
| 8481 |
search: true, |
| 8482 |
history: true, |
| 8483 |
mode: 'tree', |
| 8484 |
name: undefined, // field name of root node |
| 8485 |
schema: null |
| 8486 |
}; |
| 8487 |
|
| 8488 |
// copy all options |
| 8489 |
if (options) { |
| 8490 |
for (var prop in options) { |
| 8491 |
if (options.hasOwnProperty(prop)) { |
| 8492 |
this.options[prop] = options[prop]; |
| 8493 |
} |
| 8494 |
} |
| 8495 |
} |
| 8496 |
|
| 8497 |
// compile a JSON schema validator if a JSON schema is provided |
| 8498 |
this.setSchema(this.options.schema); |
| 8499 |
|
| 8500 |
// create a debounced validate function |
| 8501 |
this._debouncedValidate = util.debounce(this.validate.bind(this), this.DEBOUNCE_INTERVAL); |
| 8502 |
}; |
| 8503 |
|
| 8504 |
/** |
| 8505 |
* Set JSON object in editor |
| 8506 |
* @param {Object | undefined} json JSON data |
| 8507 |
* @param {String} [name] Optional field name for the root node. |
| 8508 |
* Can also be set using setName(name). |
| 8509 |
*/ |
| 8510 |
treemode.set = function (json, name) { |
| 8511 |
// adjust field name for root node |
| 8512 |
if (name) { |
| 8513 |
// TODO: deprecated since version 2.2.0. Cleanup some day. |
| 8514 |
console.warn('Second parameter "name" is deprecated. Use setName(name) instead.'); |
| 8515 |
this.options.name = name; |
| 8516 |
} |
| 8517 |
|
| 8518 |
// verify if json is valid JSON, ignore when a function |
| 8519 |
if (json instanceof Function || (json === undefined)) { |
| 8520 |
this.clear(); |
| 8521 |
} |
| 8522 |
else { |
| 8523 |
this.content.removeChild(this.table); // Take the table offline |
| 8524 |
|
| 8525 |
// replace the root node |
| 8526 |
var params = { |
| 8527 |
field: this.options.name, |
| 8528 |
value: json |
| 8529 |
}; |
| 8530 |
var node = new Node(this, params); |
| 8531 |
this._setRoot(node); |
| 8532 |
|
| 8533 |
// validate JSON schema (if configured) |
| 8534 |
this.validate(); |
| 8535 |
|
| 8536 |
// expand |
| 8537 |
var recurse = false; |
| 8538 |
this.node.expand(recurse); |
| 8539 |
|
| 8540 |
this.content.appendChild(this.table); // Put the table online again |
| 8541 |
} |
| 8542 |
|
| 8543 |
// TODO: maintain history, store last state and previous document |
| 8544 |
if (this.history) { |
| 8545 |
this.history.clear(); |
| 8546 |
} |
| 8547 |
|
| 8548 |
// clear search |
| 8549 |
if (this.searchBox) { |
| 8550 |
this.searchBox.clear(); |
| 8551 |
} |
| 8552 |
}; |
| 8553 |
|
| 8554 |
/** |
| 8555 |
* Get JSON object from editor |
| 8556 |
* @return {Object | undefined} json |
| 8557 |
*/ |
| 8558 |
treemode.get = function () { |
| 8559 |
// remove focus from currently edited node |
| 8560 |
if (this.focusTarget) { |
| 8561 |
var node = Node.getNodeFromTarget(this.focusTarget); |
| 8562 |
if (node) { |
| 8563 |
node.blur(); |
| 8564 |
} |
| 8565 |
} |
| 8566 |
|
| 8567 |
if (this.node) { |
| 8568 |
return this.node.getValue(); |
| 8569 |
} |
| 8570 |
else { |
| 8571 |
return undefined; |
| 8572 |
} |
| 8573 |
}; |
| 8574 |
|
| 8575 |
/** |
| 8576 |
* Get the text contents of the editor |
| 8577 |
* @return {String} jsonText |
| 8578 |
*/ |
| 8579 |
treemode.getText = function() { |
| 8580 |
return JSON.stringify(this.get()); |
| 8581 |
}; |
| 8582 |
|
| 8583 |
/** |
| 8584 |
* Set the text contents of the editor |
| 8585 |
* @param {String} jsonText |
| 8586 |
*/ |
| 8587 |
treemode.setText = function(jsonText) { |
| 8588 |
this.set(util.parse(jsonText)); |
| 8589 |
}; |
| 8590 |
|
| 8591 |
/** |
| 8592 |
* Set a field name for the root node. |
| 8593 |
* @param {String | undefined} name |
| 8594 |
*/ |
| 8595 |
treemode.setName = function (name) { |
| 8596 |
this.options.name = name; |
| 8597 |
if (this.node) { |
| 8598 |
this.node.updateField(this.options.name); |
| 8599 |
} |
| 8600 |
}; |
| 8601 |
|
| 8602 |
/** |
| 8603 |
* Get the field name for the root node. |
| 8604 |
* @return {String | undefined} name |
| 8605 |
*/ |
| 8606 |
treemode.getName = function () { |
| 8607 |
return this.options.name; |
| 8608 |
}; |
| 8609 |
|
| 8610 |
/** |
| 8611 |
* Set focus to the editor. Focus will be set to: |
| 8612 |
* - the first editable field or value, or else |
| 8613 |
* - to the expand button of the root node, or else |
| 8614 |
* - to the context menu button of the root node, or else |
| 8615 |
* - to the first button in the top menu |
| 8616 |
*/ |
| 8617 |
treemode.focus = function () { |
| 8618 |
var input = this.content.querySelector('[contenteditable=true]'); |
| 8619 |
if (input) { |
| 8620 |
input.focus(); |
| 8621 |
} |
| 8622 |
else if (this.node.dom.expand) { |
| 8623 |
this.node.dom.expand.focus(); |
| 8624 |
} |
| 8625 |
else if (this.node.dom.menu) { |
| 8626 |
this.node.dom.menu.focus(); |
| 8627 |
} |
| 8628 |
else { |
| 8629 |
// focus to the first button in the menu |
| 8630 |
input = this.frame.querySelector('button'); |
| 8631 |
if (input) { |
| 8632 |
input.focus(); |
| 8633 |
} |
| 8634 |
} |
| 8635 |
}; |
| 8636 |
|
| 8637 |
/** |
| 8638 |
* Remove the root node from the editor |
| 8639 |
*/ |
| 8640 |
treemode.clear = function () { |
| 8641 |
if (this.node) { |
| 8642 |
this.node.collapse(); |
| 8643 |
this.tbody.removeChild(this.node.getDom()); |
| 8644 |
delete this.node; |
| 8645 |
} |
| 8646 |
}; |
| 8647 |
|
| 8648 |
/** |
| 8649 |
* Set the root node for the json editor |
| 8650 |
* @param {Node} node |
| 8651 |
* @private |
| 8652 |
*/ |
| 8653 |
treemode._setRoot = function (node) { |
| 8654 |
this.clear(); |
| 8655 |
|
| 8656 |
this.node = node; |
| 8657 |
|
| 8658 |
// append to the dom |
| 8659 |
this.tbody.appendChild(node.getDom()); |
| 8660 |
}; |
| 8661 |
|
| 8662 |
/** |
| 8663 |
* Search text in all nodes |
| 8664 |
* The nodes will be expanded when the text is found one of its childs, |
| 8665 |
* else it will be collapsed. Searches are case insensitive. |
| 8666 |
* @param {String} text |
| 8667 |
* @return {Object[]} results Array with nodes containing the search results |
| 8668 |
* The result objects contains fields: |
| 8669 |
* - {Node} node, |
| 8670 |
* - {String} elem the dom element name where |
| 8671 |
* the result is found ('field' or |
| 8672 |
* 'value') |
| 8673 |
*/ |
| 8674 |
treemode.search = function (text) { |
| 8675 |
var results; |
| 8676 |
if (this.node) { |
| 8677 |
this.content.removeChild(this.table); // Take the table offline |
| 8678 |
results = this.node.search(text); |
| 8679 |
this.content.appendChild(this.table); // Put the table online again |
| 8680 |
} |
| 8681 |
else { |
| 8682 |
results = []; |
| 8683 |
} |
| 8684 |
|
| 8685 |
return results; |
| 8686 |
}; |
| 8687 |
|
| 8688 |
/** |
| 8689 |
* Expand all nodes |
| 8690 |
*/ |
| 8691 |
treemode.expandAll = function () { |
| 8692 |
if (this.node) { |
| 8693 |
this.content.removeChild(this.table); // Take the table offline |
| 8694 |
this.node.expand(); |
| 8695 |
this.content.appendChild(this.table); // Put the table online again |
| 8696 |
} |
| 8697 |
}; |
| 8698 |
|
| 8699 |
/** |
| 8700 |
* Collapse all nodes |
| 8701 |
*/ |
| 8702 |
treemode.collapseAll = function () { |
| 8703 |
if (this.node) { |
| 8704 |
this.content.removeChild(this.table); // Take the table offline |
| 8705 |
this.node.collapse(); |
| 8706 |
this.content.appendChild(this.table); // Put the table online again |
| 8707 |
} |
| 8708 |
}; |
| 8709 |
|
| 8710 |
/** |
| 8711 |
* The method onChange is called whenever a field or value is changed, created, |
| 8712 |
* deleted, duplicated, etc. |
| 8713 |
* @param {String} action Change action. Available values: "editField", |
| 8714 |
* "editValue", "changeType", "appendNode", |
| 8715 |
* "removeNode", "duplicateNode", "moveNode", "expand", |
| 8716 |
* "collapse". |
| 8717 |
* @param {Object} params Object containing parameters describing the change. |
| 8718 |
* The parameters in params depend on the action (for |
| 8719 |
* example for "editValue" the Node, old value, and new |
| 8720 |
* value are provided). params contains all information |
| 8721 |
* needed to undo or redo the action. |
| 8722 |
* @private |
| 8723 |
*/ |
| 8724 |
treemode._onAction = function (action, params) { |
| 8725 |
// add an action to the history |
| 8726 |
if (this.history) { |
| 8727 |
this.history.add(action, params); |
| 8728 |
} |
| 8729 |
|
| 8730 |
this._onChange(); |
| 8731 |
}; |
| 8732 |
|
| 8733 |
/** |
| 8734 |
* Handle a change: |
| 8735 |
* - Validate JSON schema |
| 8736 |
* - Send a callback to the onChange listener if provided |
| 8737 |
* @private |
| 8738 |
*/ |
| 8739 |
treemode._onChange = function () { |
| 8740 |
// validate JSON schema (if configured) |
| 8741 |
this._debouncedValidate(); |
| 8742 |
|
| 8743 |
// trigger the onChange callback |
| 8744 |
if (this.options.onChange) { |
| 8745 |
try { |
| 8746 |
this.options.onChange(); |
| 8747 |
} |
| 8748 |
catch (err) { |
| 8749 |
console.error('Error in onChange callback: ', err); |
| 8750 |
} |
| 8751 |
} |
| 8752 |
}; |
| 8753 |
|
| 8754 |
/** |
| 8755 |
* Validate current JSON object against the configured JSON schema |
| 8756 |
* Throws an exception when no JSON schema is configured |
| 8757 |
*/ |
| 8758 |
treemode.validate = function () { |
| 8759 |
// clear all current errors |
| 8760 |
if (this.errorNodes) { |
| 8761 |
this.errorNodes.forEach(function (node) { |
| 8762 |
node.setError(null); |
| 8763 |
}); |
| 8764 |
} |
| 8765 |
|
| 8766 |
var root = this.node; |
| 8767 |
if (!root) { // TODO: this should be redundant but is needed on mode switch |
| 8768 |
return; |
| 8769 |
} |
| 8770 |
|
| 8771 |
// check for duplicate keys |
| 8772 |
var duplicateErrors = root.validate(); |
| 8773 |
|
| 8774 |
// validate the JSON |
| 8775 |
var schemaErrors = []; |
| 8776 |
if (this.validateSchema) { |
| 8777 |
var valid = this.validateSchema(root.getValue()); |
| 8778 |
if (!valid) { |
| 8779 |
// apply all new errors |
| 8780 |
schemaErrors = this.validateSchema.errors |
| 8781 |
.map(function (error) { |
| 8782 |
return util.improveSchemaError(error); |
| 8783 |
}) |
| 8784 |
.map(function findNode (error) { |
| 8785 |
return { |
| 8786 |
node: root.findNode(error.dataPath), |
| 8787 |
error: error |
| 8788 |
} |
| 8789 |
}) |
| 8790 |
.filter(function hasNode (entry) { |
| 8791 |
return entry.node != null |
| 8792 |
}); |
| 8793 |
} |
| 8794 |
} |
| 8795 |
|
| 8796 |
// display the error in the nodes with a problem |
| 8797 |
this.errorNodes = duplicateErrors |
| 8798 |
.concat(schemaErrors) |
| 8799 |
.reduce(function expandParents (all, entry) { |
| 8800 |
// expand parents, then merge such that parents come first and |
| 8801 |
// original entries last |
| 8802 |
return entry.node |
| 8803 |
.findParents() |
| 8804 |
.map(function (parent) { |
| 8805 |
return { |
| 8806 |
node: parent, |
| 8807 |
child: entry.node, |
| 8808 |
error: { |
| 8809 |
message: parent.type === 'object' |
| 8810 |
? 'Contains invalid properties' // object |
| 8811 |
: 'Contains invalid items' // array |
| 8812 |
} |
| 8813 |
}; |
| 8814 |
}) |
| 8815 |
.concat(all, [entry]); |
| 8816 |
}, []) |
| 8817 |
// TODO: dedupe the parent nodes |
| 8818 |
.map(function setError (entry) { |
| 8819 |
entry.node.setError(entry.error, entry.child); |
| 8820 |
return entry.node; |
| 8821 |
}); |
| 8822 |
}; |
| 8823 |
|
| 8824 |
/** |
| 8825 |
* Refresh the rendered contents |
| 8826 |
*/ |
| 8827 |
treemode.refresh = function () { |
| 8828 |
if (this.node) { |
| 8829 |
this.node.updateDom({recurse: true}); |
| 8830 |
} |
| 8831 |
}; |
| 8832 |
|
| 8833 |
/** |
| 8834 |
* Start autoscrolling when given mouse position is above the top of the |
| 8835 |
* editor contents, or below the bottom. |
| 8836 |
* @param {Number} mouseY Absolute mouse position in pixels |
| 8837 |
*/ |
| 8838 |
treemode.startAutoScroll = function (mouseY) { |
| 8839 |
var me = this; |
| 8840 |
var content = this.content; |
| 8841 |
var top = util.getAbsoluteTop(content); |
| 8842 |
var height = content.clientHeight; |
| 8843 |
var bottom = top + height; |
| 8844 |
var margin = 24; |
| 8845 |
var interval = 50; // ms |
| 8846 |
|
| 8847 |
if ((mouseY < top + margin) && content.scrollTop > 0) { |
| 8848 |
this.autoScrollStep = ((top + margin) - mouseY) / 3; |
| 8849 |
} |
| 8850 |
else if (mouseY > bottom - margin && |
| 8851 |
height + content.scrollTop < content.scrollHeight) { |
| 8852 |
this.autoScrollStep = ((bottom - margin) - mouseY) / 3; |
| 8853 |
} |
| 8854 |
else { |
| 8855 |
this.autoScrollStep = undefined; |
| 8856 |
} |
| 8857 |
|
| 8858 |
if (this.autoScrollStep) { |
| 8859 |
if (!this.autoScrollTimer) { |
| 8860 |
this.autoScrollTimer = setInterval(function () { |
| 8861 |
if (me.autoScrollStep) { |
| 8862 |
content.scrollTop -= me.autoScrollStep; |
| 8863 |
} |
| 8864 |
else { |
| 8865 |
me.stopAutoScroll(); |
| 8866 |
} |
| 8867 |
}, interval); |
| 8868 |
} |
| 8869 |
} |
| 8870 |
else { |
| 8871 |
this.stopAutoScroll(); |
| 8872 |
} |
| 8873 |
}; |
| 8874 |
|
| 8875 |
/** |
| 8876 |
* Stop auto scrolling. Only applicable when scrolling |
| 8877 |
*/ |
| 8878 |
treemode.stopAutoScroll = function () { |
| 8879 |
if (this.autoScrollTimer) { |
| 8880 |
clearTimeout(this.autoScrollTimer); |
| 8881 |
delete this.autoScrollTimer; |
| 8882 |
} |
| 8883 |
if (this.autoScrollStep) { |
| 8884 |
delete this.autoScrollStep; |
| 8885 |
} |
| 8886 |
}; |
| 8887 |
|
| 8888 |
|
| 8889 |
/** |
| 8890 |
* Set the focus to an element in the editor, set text selection, and |
| 8891 |
* set scroll position. |
| 8892 |
* @param {Object} selection An object containing fields: |
| 8893 |
* {Element | undefined} dom The dom element |
| 8894 |
* which has focus |
| 8895 |
* {Range | TextRange} range A text selection |
| 8896 |
* {Node[]} nodes Nodes in case of multi selection |
| 8897 |
* {Number} scrollTop Scroll position |
| 8898 |
*/ |
| 8899 |
treemode.setSelection = function (selection) { |
| 8900 |
if (!selection) { |
| 8901 |
return; |
| 8902 |
} |
| 8903 |
|
| 8904 |
if ('scrollTop' in selection && this.content) { |
| 8905 |
// TODO: animated scroll |
| 8906 |
this.content.scrollTop = selection.scrollTop; |
| 8907 |
} |
| 8908 |
if (selection.nodes) { |
| 8909 |
// multi-select |
| 8910 |
this.select(selection.nodes); |
| 8911 |
} |
| 8912 |
if (selection.range) { |
| 8913 |
util.setSelectionOffset(selection.range); |
| 8914 |
} |
| 8915 |
if (selection.dom) { |
| 8916 |
selection.dom.focus(); |
| 8917 |
} |
| 8918 |
}; |
| 8919 |
|
| 8920 |
/** |
| 8921 |
* Get the current focus |
| 8922 |
* @return {Object} selection An object containing fields: |
| 8923 |
* {Element | undefined} dom The dom element |
| 8924 |
* which has focus |
| 8925 |
* {Range | TextRange} range A text selection |
| 8926 |
* {Node[]} nodes Nodes in case of multi selection |
| 8927 |
* {Number} scrollTop Scroll position |
| 8928 |
*/ |
| 8929 |
treemode.getSelection = function () { |
| 8930 |
var range = util.getSelectionOffset(); |
| 8931 |
if (range && range.container.nodeName !== 'DIV') { // filter on (editable) divs) |
| 8932 |
range = null; |
| 8933 |
} |
| 8934 |
|
| 8935 |
return { |
| 8936 |
dom: this.focusTarget, |
| 8937 |
range: range, |
| 8938 |
nodes: this.multiselection.nodes.slice(0), |
| 8939 |
scrollTop: this.content ? this.content.scrollTop : 0 |
| 8940 |
}; |
| 8941 |
}; |
| 8942 |
|
| 8943 |
/** |
| 8944 |
* Adjust the scroll position such that given top position is shown at 1/4 |
| 8945 |
* of the window height. |
| 8946 |
* @param {Number} top |
| 8947 |
* @param {function(boolean)} [callback] Callback, executed when animation is |
| 8948 |
* finished. The callback returns true |
| 8949 |
* when animation is finished, or false |
| 8950 |
* when not. |
| 8951 |
*/ |
| 8952 |
treemode.scrollTo = function (top, callback) { |
| 8953 |
var content = this.content; |
| 8954 |
if (content) { |
| 8955 |
var editor = this; |
| 8956 |
// cancel any running animation |
| 8957 |
if (editor.animateTimeout) { |
| 8958 |
clearTimeout(editor.animateTimeout); |
| 8959 |
delete editor.animateTimeout; |
| 8960 |
} |
| 8961 |
if (editor.animateCallback) { |
| 8962 |
editor.animateCallback(false); |
| 8963 |
delete editor.animateCallback; |
| 8964 |
} |
| 8965 |
|
| 8966 |
// calculate final scroll position |
| 8967 |
var height = content.clientHeight; |
| 8968 |
var bottom = content.scrollHeight - height; |
| 8969 |
var finalScrollTop = Math.min(Math.max(top - height / 4, 0), bottom); |
| 8970 |
|
| 8971 |
// animate towards the new scroll position |
| 8972 |
var animate = function () { |
| 8973 |
var scrollTop = content.scrollTop; |
| 8974 |
var diff = (finalScrollTop - scrollTop); |
| 8975 |
if (Math.abs(diff) > 3) { |
| 8976 |
content.scrollTop += diff / 3; |
| 8977 |
editor.animateCallback = callback; |
| 8978 |
editor.animateTimeout = setTimeout(animate, 50); |
| 8979 |
} |
| 8980 |
else { |
| 8981 |
// finished |
| 8982 |
if (callback) { |
| 8983 |
callback(true); |
| 8984 |
} |
| 8985 |
content.scrollTop = finalScrollTop; |
| 8986 |
delete editor.animateTimeout; |
| 8987 |
delete editor.animateCallback; |
| 8988 |
} |
| 8989 |
}; |
| 8990 |
animate(); |
| 8991 |
} |
| 8992 |
else { |
| 8993 |
if (callback) { |
| 8994 |
callback(false); |
| 8995 |
} |
| 8996 |
} |
| 8997 |
}; |
| 8998 |
|
| 8999 |
/** |
| 9000 |
* Create main frame |
| 9001 |
* @private |
| 9002 |
*/ |
| 9003 |
treemode._createFrame = function () { |
| 9004 |
// create the frame |
| 9005 |
this.frame = document.createElement('div'); |
| 9006 |
this.frame.className = 'jsoneditor jsoneditor-mode-' + this.options.mode; |
| 9007 |
this.container.appendChild(this.frame); |
| 9008 |
|
| 9009 |
// create one global event listener to handle all events from all nodes |
| 9010 |
var editor = this; |
| 9011 |
function onEvent(event) { |
| 9012 |
// when switching to mode "code" or "text" via the menu, some events |
| 9013 |
// are still fired whilst the _onEvent methods is already removed. |
| 9014 |
if (editor._onEvent) { |
| 9015 |
editor._onEvent(event); |
| 9016 |
} |
| 9017 |
} |
| 9018 |
this.frame.onclick = function (event) { |
| 9019 |
var target = event.target;// || event.srcElement; |
| 9020 |
|
| 9021 |
onEvent(event); |
| 9022 |
|
| 9023 |
// prevent default submit action of buttons when editor is located |
| 9024 |
// inside a form |
| 9025 |
if (target.nodeName == 'BUTTON') { |
| 9026 |
event.preventDefault(); |
| 9027 |
} |
| 9028 |
}; |
| 9029 |
this.frame.oninput = onEvent; |
| 9030 |
this.frame.onchange = onEvent; |
| 9031 |
this.frame.onkeydown = onEvent; |
| 9032 |
this.frame.onkeyup = onEvent; |
| 9033 |
this.frame.oncut = onEvent; |
| 9034 |
this.frame.onpaste = onEvent; |
| 9035 |
this.frame.onmousedown = onEvent; |
| 9036 |
this.frame.onmouseup = onEvent; |
| 9037 |
this.frame.onmouseover = onEvent; |
| 9038 |
this.frame.onmouseout = onEvent; |
| 9039 |
// Note: focus and blur events do not propagate, therefore they defined |
| 9040 |
// using an eventListener with useCapture=true |
| 9041 |
// see http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html |
| 9042 |
util.addEventListener(this.frame, 'focus', onEvent, true); |
| 9043 |
util.addEventListener(this.frame, 'blur', onEvent, true); |
| 9044 |
this.frame.onfocusin = onEvent; // for IE |
| 9045 |
this.frame.onfocusout = onEvent; // for IE |
| 9046 |
|
| 9047 |
// create menu |
| 9048 |
this.menu = document.createElement('div'); |
| 9049 |
this.menu.className = 'jsoneditor-menu'; |
| 9050 |
this.frame.appendChild(this.menu); |
| 9051 |
|
| 9052 |
// create expand all button |
| 9053 |
var expandAll = document.createElement('button'); |
| 9054 |
expandAll.type = 'button'; |
| 9055 |
expandAll.className = 'jsoneditor-expand-all'; |
| 9056 |
expandAll.title = 'Expand all fields'; |
| 9057 |
expandAll.onclick = function () { |
| 9058 |
editor.expandAll(); |
| 9059 |
}; |
| 9060 |
this.menu.appendChild(expandAll); |
| 9061 |
|
| 9062 |
// create expand all button |
| 9063 |
var collapseAll = document.createElement('button'); |
| 9064 |
collapseAll.type = 'button'; |
| 9065 |
collapseAll.title = 'Collapse all fields'; |
| 9066 |
collapseAll.className = 'jsoneditor-collapse-all'; |
| 9067 |
collapseAll.onclick = function () { |
| 9068 |
editor.collapseAll(); |
| 9069 |
}; |
| 9070 |
this.menu.appendChild(collapseAll); |
| 9071 |
|
| 9072 |
// create undo/redo buttons |
| 9073 |
if (this.history) { |
| 9074 |
// create undo button |
| 9075 |
var undo = document.createElement('button'); |
| 9076 |
undo.type = 'button'; |
| 9077 |
undo.className = 'jsoneditor-undo jsoneditor-separator'; |
| 9078 |
undo.title = 'Undo last action (Ctrl+Z)'; |
| 9079 |
undo.onclick = function () { |
| 9080 |
editor._onUndo(); |
| 9081 |
}; |
| 9082 |
this.menu.appendChild(undo); |
| 9083 |
this.dom.undo = undo; |
| 9084 |
|
| 9085 |
// create redo button |
| 9086 |
var redo = document.createElement('button'); |
| 9087 |
redo.type = 'button'; |
| 9088 |
redo.className = 'jsoneditor-redo'; |
| 9089 |
redo.title = 'Redo (Ctrl+Shift+Z)'; |
| 9090 |
redo.onclick = function () { |
| 9091 |
editor._onRedo(); |
| 9092 |
}; |
| 9093 |
this.menu.appendChild(redo); |
| 9094 |
this.dom.redo = redo; |
| 9095 |
|
| 9096 |
// register handler for onchange of history |
| 9097 |
this.history.onChange = function () { |
| 9098 |
undo.disabled = !editor.history.canUndo(); |
| 9099 |
redo.disabled = !editor.history.canRedo(); |
| 9100 |
}; |
| 9101 |
this.history.onChange(); |
| 9102 |
} |
| 9103 |
|
| 9104 |
// create mode box |
| 9105 |
if (this.options && this.options.modes && this.options.modes.length) { |
| 9106 |
var me = this; |
| 9107 |
this.modeSwitcher = new ModeSwitcher(this.menu, this.options.modes, this.options.mode, function onSwitch(mode) { |
| 9108 |
me.modeSwitcher.destroy(); |
| 9109 |
|
| 9110 |
// switch mode and restore focus |
| 9111 |
me.setMode(mode); |
| 9112 |
me.modeSwitcher.focus(); |
| 9113 |
}); |
| 9114 |
} |
| 9115 |
|
| 9116 |
// create search box |
| 9117 |
if (this.options.search) { |
| 9118 |
this.searchBox = new SearchBox(this, this.menu); |
| 9119 |
} |
| 9120 |
}; |
| 9121 |
|
| 9122 |
/** |
| 9123 |
* Perform an undo action |
| 9124 |
* @private |
| 9125 |
*/ |
| 9126 |
treemode._onUndo = function () { |
| 9127 |
if (this.history) { |
| 9128 |
// undo last action |
| 9129 |
this.history.undo(); |
| 9130 |
|
| 9131 |
// fire change event |
| 9132 |
this._onChange(); |
| 9133 |
} |
| 9134 |
}; |
| 9135 |
|
| 9136 |
/** |
| 9137 |
* Perform a redo action |
| 9138 |
* @private |
| 9139 |
*/ |
| 9140 |
treemode._onRedo = function () { |
| 9141 |
if (this.history) { |
| 9142 |
// redo last action |
| 9143 |
this.history.redo(); |
| 9144 |
|
| 9145 |
// fire change event |
| 9146 |
this._onChange(); |
| 9147 |
} |
| 9148 |
}; |
| 9149 |
|
| 9150 |
/** |
| 9151 |
* Event handler |
| 9152 |
* @param event |
| 9153 |
* @private |
| 9154 |
*/ |
| 9155 |
treemode._onEvent = function (event) { |
| 9156 |
if (event.type == 'keydown') { |
| 9157 |
this._onKeyDown(event); |
| 9158 |
} |
| 9159 |
|
| 9160 |
if (event.type == 'focus') { |
| 9161 |
this.focusTarget = event.target; |
| 9162 |
} |
| 9163 |
|
| 9164 |
if (event.type == 'mousedown') { |
| 9165 |
this._startDragDistance(event); |
| 9166 |
} |
| 9167 |
if (event.type == 'mousemove' || event.type == 'mouseup' || event.type == 'click') { |
| 9168 |
this._updateDragDistance(event); |
| 9169 |
} |
| 9170 |
|
| 9171 |
var node = Node.getNodeFromTarget(event.target); |
| 9172 |
|
| 9173 |
if (node && node.selected) { |
| 9174 |
if (event.type == 'click') { |
| 9175 |
if (event.target == node.dom.menu) { |
| 9176 |
this.showContextMenu(event.target); |
| 9177 |
|
| 9178 |
// stop propagation (else we will open the context menu of a single node) |
| 9179 |
return; |
| 9180 |
} |
| 9181 |
|
| 9182 |
// deselect a multi selection |
| 9183 |
if (!event.hasMoved) { |
| 9184 |
this.deselect(); |
| 9185 |
} |
| 9186 |
} |
| 9187 |
|
| 9188 |
if (event.type == 'mousedown') { |
| 9189 |
// drag multiple nodes |
| 9190 |
Node.onDragStart(this.multiselection.nodes, event); |
| 9191 |
} |
| 9192 |
} |
| 9193 |
else { |
| 9194 |
if (event.type == 'mousedown') { |
| 9195 |
this.deselect(); |
| 9196 |
|
| 9197 |
if (node && event.target == node.dom.drag) { |
| 9198 |
// drag a singe node |
| 9199 |
Node.onDragStart(node, event); |
| 9200 |
} |
| 9201 |
else if (!node || (event.target != node.dom.field && event.target != node.dom.value && event.target != node.dom.select)) { |
| 9202 |
// select multiple nodes |
| 9203 |
this._onMultiSelectStart(event); |
| 9204 |
} |
| 9205 |
} |
| 9206 |
} |
| 9207 |
|
| 9208 |
if (node) { |
| 9209 |
node.onEvent(event); |
| 9210 |
} |
| 9211 |
}; |
| 9212 |
|
| 9213 |
treemode._startDragDistance = function (event) { |
| 9214 |
this.dragDistanceEvent = { |
| 9215 |
initialTarget: event.target, |
| 9216 |
initialPageX: event.pageX, |
| 9217 |
initialPageY: event.pageY, |
| 9218 |
dragDistance: 0, |
| 9219 |
hasMoved: false |
| 9220 |
}; |
| 9221 |
}; |
| 9222 |
|
| 9223 |
treemode._updateDragDistance = function (event) { |
| 9224 |
if (!this.dragDistanceEvent) { |
| 9225 |
this._startDragDistance(event); |
| 9226 |
} |
| 9227 |
|
| 9228 |
var diffX = event.pageX - this.dragDistanceEvent.initialPageX; |
| 9229 |
var diffY = event.pageY - this.dragDistanceEvent.initialPageY; |
| 9230 |
|
| 9231 |
this.dragDistanceEvent.dragDistance = Math.sqrt(diffX * diffX + diffY * diffY); |
| 9232 |
this.dragDistanceEvent.hasMoved = |
| 9233 |
this.dragDistanceEvent.hasMoved || this.dragDistanceEvent.dragDistance > 10; |
| 9234 |
|
| 9235 |
event.dragDistance = this.dragDistanceEvent.dragDistance; |
| 9236 |
event.hasMoved = this.dragDistanceEvent.hasMoved; |
| 9237 |
|
| 9238 |
return event.dragDistance; |
| 9239 |
}; |
| 9240 |
|
| 9241 |
/** |
| 9242 |
* Start multi selection of nodes by dragging the mouse |
| 9243 |
* @param event |
| 9244 |
* @private |
| 9245 |
*/ |
| 9246 |
treemode._onMultiSelectStart = function (event) { |
| 9247 |
var node = Node.getNodeFromTarget(event.target); |
| 9248 |
|
| 9249 |
if (this.options.mode !== 'tree' || this.options.onEditable !== undefined) { |
| 9250 |
// dragging not allowed in modes 'view' and 'form' |
| 9251 |
// TODO: allow multiselection of items when option onEditable is specified |
| 9252 |
return; |
| 9253 |
} |
| 9254 |
|
| 9255 |
this.multiselection = { |
| 9256 |
start: node || null, |
| 9257 |
end: null, |
| 9258 |
nodes: [] |
| 9259 |
}; |
| 9260 |
|
| 9261 |
this._startDragDistance(event); |
| 9262 |
|
| 9263 |
var editor = this; |
| 9264 |
if (!this.mousemove) { |
| 9265 |
this.mousemove = util.addEventListener(window, 'mousemove', function (event) { |
| 9266 |
editor._onMultiSelect(event); |
| 9267 |
}); |
| 9268 |
} |
| 9269 |
if (!this.mouseup) { |
| 9270 |
this.mouseup = util.addEventListener(window, 'mouseup', function (event ) { |
| 9271 |
editor._onMultiSelectEnd(event); |
| 9272 |
}); |
| 9273 |
} |
| 9274 |
|
| 9275 |
}; |
| 9276 |
|
| 9277 |
/** |
| 9278 |
* Multiselect nodes by dragging |
| 9279 |
* @param event |
| 9280 |
* @private |
| 9281 |
*/ |
| 9282 |
treemode._onMultiSelect = function (event) { |
| 9283 |
event.preventDefault(); |
| 9284 |
|
| 9285 |
this._updateDragDistance(event); |
| 9286 |
if (!event.hasMoved) { |
| 9287 |
return; |
| 9288 |
} |
| 9289 |
|
| 9290 |
var node = Node.getNodeFromTarget(event.target); |
| 9291 |
|
| 9292 |
if (node) { |
| 9293 |
if (this.multiselection.start == null) { |
| 9294 |
this.multiselection.start = node; |
| 9295 |
} |
| 9296 |
this.multiselection.end = node; |
| 9297 |
} |
| 9298 |
|
| 9299 |
// deselect previous selection |
| 9300 |
this.deselect(); |
| 9301 |
|
| 9302 |
// find the selected nodes in the range from first to last |
| 9303 |
var start = this.multiselection.start; |
| 9304 |
var end = this.multiselection.end || this.multiselection.start; |
| 9305 |
if (start && end) { |
| 9306 |
// find the top level childs, all having the same parent |
| 9307 |
this.multiselection.nodes = this._findTopLevelNodes(start, end); |
| 9308 |
this.select(this.multiselection.nodes); |
| 9309 |
} |
| 9310 |
}; |
| 9311 |
|
| 9312 |
/** |
| 9313 |
* End of multiselect nodes by dragging |
| 9314 |
* @param event |
| 9315 |
* @private |
| 9316 |
*/ |
| 9317 |
treemode._onMultiSelectEnd = function (event) { |
| 9318 |
// set focus to the context menu button of the first node |
| 9319 |
if (this.multiselection.nodes[0]) { |
| 9320 |
this.multiselection.nodes[0].dom.menu.focus(); |
| 9321 |
} |
| 9322 |
|
| 9323 |
this.multiselection.start = null; |
| 9324 |
this.multiselection.end = null; |
| 9325 |
|
| 9326 |
// cleanup global event listeners |
| 9327 |
if (this.mousemove) { |
| 9328 |
util.removeEventListener(window, 'mousemove', this.mousemove); |
| 9329 |
delete this.mousemove; |
| 9330 |
} |
| 9331 |
if (this.mouseup) { |
| 9332 |
util.removeEventListener(window, 'mouseup', this.mouseup); |
| 9333 |
delete this.mouseup; |
| 9334 |
} |
| 9335 |
}; |
| 9336 |
|
| 9337 |
/** |
| 9338 |
* deselect currently selected nodes |
| 9339 |
* @param {boolean} [clearStartAndEnd=false] If true, the `start` and `end` |
| 9340 |
* state is cleared too. |
| 9341 |
*/ |
| 9342 |
treemode.deselect = function (clearStartAndEnd) { |
| 9343 |
this.multiselection.nodes.forEach(function (node) { |
| 9344 |
node.setSelected(false); |
| 9345 |
}); |
| 9346 |
this.multiselection.nodes = []; |
| 9347 |
|
| 9348 |
if (clearStartAndEnd) { |
| 9349 |
this.multiselection.start = null; |
| 9350 |
this.multiselection.end = null; |
| 9351 |
} |
| 9352 |
}; |
| 9353 |
|
| 9354 |
/** |
| 9355 |
* select nodes |
| 9356 |
* @param {Node[] | Node} nodes |
| 9357 |
*/ |
| 9358 |
treemode.select = function (nodes) { |
| 9359 |
if (!Array.isArray(nodes)) { |
| 9360 |
return this.select([nodes]); |
| 9361 |
} |
| 9362 |
|
| 9363 |
if (nodes) { |
| 9364 |
this.deselect(); |
| 9365 |
|
| 9366 |
this.multiselection.nodes = nodes.slice(0); |
| 9367 |
|
| 9368 |
var first = nodes[0]; |
| 9369 |
nodes.forEach(function (node) { |
| 9370 |
node.setSelected(true, node === first); |
| 9371 |
}); |
| 9372 |
} |
| 9373 |
}; |
| 9374 |
|
| 9375 |
/** |
| 9376 |
* From two arbitrary selected nodes, find their shared parent node. |
| 9377 |
* From that parent node, select the two child nodes in the brances going to |
| 9378 |
* nodes `start` and `end`, and select all childs in between. |
| 9379 |
* @param {Node} start |
| 9380 |
* @param {Node} end |
| 9381 |
* @return {Array.<Node>} Returns an ordered list with child nodes |
| 9382 |
* @private |
| 9383 |
*/ |
| 9384 |
treemode._findTopLevelNodes = function (start, end) { |
| 9385 |
var startPath = start.getNodePath(); |
| 9386 |
var endPath = end.getNodePath(); |
| 9387 |
var i = 0; |
| 9388 |
while (i < startPath.length && startPath[i] === endPath[i]) { |
| 9389 |
i++; |
| 9390 |
} |
| 9391 |
var root = startPath[i - 1]; |
| 9392 |
var startChild = startPath[i]; |
| 9393 |
var endChild = endPath[i]; |
| 9394 |
|
| 9395 |
if (!startChild || !endChild) { |
| 9396 |
if (root.parent) { |
| 9397 |
// startChild is a parent of endChild or vice versa |
| 9398 |
startChild = root; |
| 9399 |
endChild = root; |
| 9400 |
root = root.parent |
| 9401 |
} |
| 9402 |
else { |
| 9403 |
// we have selected the root node (which doesn't have a parent) |
| 9404 |
startChild = root.childs[0]; |
| 9405 |
endChild = root.childs[root.childs.length - 1]; |
| 9406 |
} |
| 9407 |
} |
| 9408 |
|
| 9409 |
if (root && startChild && endChild) { |
| 9410 |
var startIndex = root.childs.indexOf(startChild); |
| 9411 |
var endIndex = root.childs.indexOf(endChild); |
| 9412 |
var firstIndex = Math.min(startIndex, endIndex); |
| 9413 |
var lastIndex = Math.max(startIndex, endIndex); |
| 9414 |
|
| 9415 |
return root.childs.slice(firstIndex, lastIndex + 1); |
| 9416 |
} |
| 9417 |
else { |
| 9418 |
return []; |
| 9419 |
} |
| 9420 |
}; |
| 9421 |
|
| 9422 |
/** |
| 9423 |
* Event handler for keydown. Handles shortcut keys |
| 9424 |
* @param {Event} event |
| 9425 |
* @private |
| 9426 |
*/ |
| 9427 |
treemode._onKeyDown = function (event) { |
| 9428 |
var keynum = event.which || event.keyCode; |
| 9429 |
var ctrlKey = event.ctrlKey; |
| 9430 |
var shiftKey = event.shiftKey; |
| 9431 |
var handled = false; |
| 9432 |
|
| 9433 |
if (keynum == 9) { // Tab or Shift+Tab |
| 9434 |
var me = this; |
| 9435 |
setTimeout(function () { |
| 9436 |
// select all text when moving focus to an editable div |
| 9437 |
util.selectContentEditable(me.focusTarget); |
| 9438 |
}, 0); |
| 9439 |
} |
| 9440 |
|
| 9441 |
if (this.searchBox) { |
| 9442 |
if (ctrlKey && keynum == 70) { // Ctrl+F |
| 9443 |
this.searchBox.dom.search.focus(); |
| 9444 |
this.searchBox.dom.search.select(); |
| 9445 |
handled = true; |
| 9446 |
} |
| 9447 |
else if (keynum == 114 || (ctrlKey && keynum == 71)) { // F3 or Ctrl+G |
| 9448 |
var focus = true; |
| 9449 |
if (!shiftKey) { |
| 9450 |
// select next search result (F3 or Ctrl+G) |
| 9451 |
this.searchBox.next(focus); |
| 9452 |
} |
| 9453 |
else { |
| 9454 |
// select previous search result (Shift+F3 or Ctrl+Shift+G) |
| 9455 |
this.searchBox.previous(focus); |
| 9456 |
} |
| 9457 |
|
| 9458 |
handled = true; |
| 9459 |
} |
| 9460 |
} |
| 9461 |
|
| 9462 |
if (this.history) { |
| 9463 |
if (ctrlKey && !shiftKey && keynum == 90) { // Ctrl+Z |
| 9464 |
// undo |
| 9465 |
this._onUndo(); |
| 9466 |
handled = true; |
| 9467 |
} |
| 9468 |
else if (ctrlKey && shiftKey && keynum == 90) { // Ctrl+Shift+Z |
| 9469 |
// redo |
| 9470 |
this._onRedo(); |
| 9471 |
handled = true; |
| 9472 |
} |
| 9473 |
} |
| 9474 |
|
| 9475 |
if (handled) { |
| 9476 |
event.preventDefault(); |
| 9477 |
event.stopPropagation(); |
| 9478 |
} |
| 9479 |
}; |
| 9480 |
|
| 9481 |
/** |
| 9482 |
* Create main table |
| 9483 |
* @private |
| 9484 |
*/ |
| 9485 |
treemode._createTable = function () { |
| 9486 |
var contentOuter = document.createElement('div'); |
| 9487 |
contentOuter.className = 'jsoneditor-outer'; |
| 9488 |
this.contentOuter = contentOuter; |
| 9489 |
|
| 9490 |
this.content = document.createElement('div'); |
| 9491 |
this.content.className = 'jsoneditor-tree'; |
| 9492 |
contentOuter.appendChild(this.content); |
| 9493 |
|
| 9494 |
this.table = document.createElement('table'); |
| 9495 |
this.table.className = 'jsoneditor-tree'; |
| 9496 |
this.content.appendChild(this.table); |
| 9497 |
|
| 9498 |
// create colgroup where the first two columns don't have a fixed |
| 9499 |
// width, and the edit columns do have a fixed width |
| 9500 |
var col; |
| 9501 |
this.colgroupContent = document.createElement('colgroup'); |
| 9502 |
if (this.options.mode === 'tree') { |
| 9503 |
col = document.createElement('col'); |
| 9504 |
col.width = "24px"; |
| 9505 |
this.colgroupContent.appendChild(col); |
| 9506 |
} |
| 9507 |
col = document.createElement('col'); |
| 9508 |
col.width = "24px"; |
| 9509 |
this.colgroupContent.appendChild(col); |
| 9510 |
col = document.createElement('col'); |
| 9511 |
this.colgroupContent.appendChild(col); |
| 9512 |
this.table.appendChild(this.colgroupContent); |
| 9513 |
|
| 9514 |
this.tbody = document.createElement('tbody'); |
| 9515 |
this.table.appendChild(this.tbody); |
| 9516 |
|
| 9517 |
this.frame.appendChild(contentOuter); |
| 9518 |
}; |
| 9519 |
|
| 9520 |
/** |
| 9521 |
* Show a contextmenu for this node. |
| 9522 |
* Used for multiselection |
| 9523 |
* @param {HTMLElement} anchor Anchor element to attache the context menu to. |
| 9524 |
* @param {function} [onClose] Callback method called when the context menu |
| 9525 |
* is being closed. |
| 9526 |
*/ |
| 9527 |
treemode.showContextMenu = function (anchor, onClose) { |
| 9528 |
var items = []; |
| 9529 |
var editor = this; |
| 9530 |
|
| 9531 |
// create duplicate button |
| 9532 |
items.push({ |
| 9533 |
text: 'Duplicate', |
| 9534 |
title: 'Duplicate selected fields (Ctrl+D)', |
| 9535 |
className: 'jsoneditor-duplicate', |
| 9536 |
click: function () { |
| 9537 |
Node.onDuplicate(editor.multiselection.nodes); |
| 9538 |
} |
| 9539 |
}); |
| 9540 |
|
| 9541 |
// create remove button |
| 9542 |
items.push({ |
| 9543 |
text: 'Remove', |
| 9544 |
title: 'Remove selected fields (Ctrl+Del)', |
| 9545 |
className: 'jsoneditor-remove', |
| 9546 |
click: function () { |
| 9547 |
Node.onRemove(editor.multiselection.nodes); |
| 9548 |
} |
| 9549 |
}); |
| 9550 |
|
| 9551 |
var menu = new ContextMenu(items, {close: onClose}); |
| 9552 |
menu.show(anchor, this.content); |
| 9553 |
}; |
| 9554 |
|
| 9555 |
|
| 9556 |
// define modes |
| 9557 |
module.exports = [ |
| 9558 |
{ |
| 9559 |
mode: 'tree', |
| 9560 |
mixin: treemode, |
| 9561 |
data: 'json' |
| 9562 |
}, |
| 9563 |
{ |
| 9564 |
mode: 'view', |
| 9565 |
mixin: treemode, |
| 9566 |
data: 'json' |
| 9567 |
}, |
| 9568 |
{ |
| 9569 |
mode: 'form', |
| 9570 |
mixin: treemode, |
| 9571 |
data: 'json' |
| 9572 |
} |
| 9573 |
]; |
| 9574 |
|
| 9575 |
|
| 9576 |
/***/ }, |
| 9577 |
/* 52 */ |
| 9578 |
/***/ function(module, exports) { |
| 9579 |
|
| 9580 |
'use strict'; |
| 9581 |
|
| 9582 |
/** |
| 9583 |
* The highlighter can highlight/unhighlight a node, and |
| 9584 |
* animate the visibility of a context menu. |
| 9585 |
* @constructor Highlighter |
| 9586 |
*/ |
| 9587 |
function Highlighter () { |
| 9588 |
this.locked = false; |
| 9589 |
} |
| 9590 |
|
| 9591 |
/** |
| 9592 |
* Hightlight given node and its childs |
| 9593 |
* @param {Node} node |
| 9594 |
*/ |
| 9595 |
Highlighter.prototype.highlight = function (node) { |
| 9596 |
if (this.locked) { |
| 9597 |
return; |
| 9598 |
} |
| 9599 |
|
| 9600 |
if (this.node != node) { |
| 9601 |
// unhighlight current node |
| 9602 |
if (this.node) { |
| 9603 |
this.node.setHighlight(false); |
| 9604 |
} |
| 9605 |
|
| 9606 |
// highlight new node |
| 9607 |
this.node = node; |
| 9608 |
this.node.setHighlight(true); |
| 9609 |
} |
| 9610 |
|
| 9611 |
// cancel any current timeout |
| 9612 |
this._cancelUnhighlight(); |
| 9613 |
}; |
| 9614 |
|
| 9615 |
/** |
| 9616 |
* Unhighlight currently highlighted node. |
| 9617 |
* Will be done after a delay |
| 9618 |
*/ |
| 9619 |
Highlighter.prototype.unhighlight = function () { |
| 9620 |
if (this.locked) { |
| 9621 |
return; |
| 9622 |
} |
| 9623 |
|
| 9624 |
var me = this; |
| 9625 |
if (this.node) { |
| 9626 |
this._cancelUnhighlight(); |
| 9627 |
|
| 9628 |
// do the unhighlighting after a small delay, to prevent re-highlighting |
| 9629 |
// the same node when moving from the drag-icon to the contextmenu-icon |
| 9630 |
// or vice versa. |
| 9631 |
this.unhighlightTimer = setTimeout(function () { |
| 9632 |
me.node.setHighlight(false); |
| 9633 |
me.node = undefined; |
| 9634 |
me.unhighlightTimer = undefined; |
| 9635 |
}, 0); |
| 9636 |
} |
| 9637 |
}; |
| 9638 |
|
| 9639 |
/** |
| 9640 |
* Cancel an unhighlight action (if before the timeout of the unhighlight action) |
| 9641 |
* @private |
| 9642 |
*/ |
| 9643 |
Highlighter.prototype._cancelUnhighlight = function () { |
| 9644 |
if (this.unhighlightTimer) { |
| 9645 |
clearTimeout(this.unhighlightTimer); |
| 9646 |
this.unhighlightTimer = undefined; |
| 9647 |
} |
| 9648 |
}; |
| 9649 |
|
| 9650 |
/** |
| 9651 |
* Lock highlighting or unhighlighting nodes. |
| 9652 |
* methods highlight and unhighlight do not work while locked. |
| 9653 |
*/ |
| 9654 |
Highlighter.prototype.lock = function () { |
| 9655 |
this.locked = true; |
| 9656 |
}; |
| 9657 |
|
| 9658 |
/** |
| 9659 |
* Unlock highlighting or unhighlighting nodes |
| 9660 |
*/ |
| 9661 |
Highlighter.prototype.unlock = function () { |
| 9662 |
this.locked = false; |
| 9663 |
}; |
| 9664 |
|
| 9665 |
module.exports = Highlighter; |
| 9666 |
|
| 9667 |
|
| 9668 |
/***/ }, |
| 9669 |
/* 53 */ |
| 9670 |
/***/ function(module, exports, __webpack_require__) { |
| 9671 |
|
| 9672 |
'use strict'; |
| 9673 |
|
| 9674 |
var util = __webpack_require__(54); |
| 9675 |
|
| 9676 |
/** |
| 9677 |
* @constructor History |
| 9678 |
* Store action history, enables undo and redo |
| 9679 |
* @param {JSONEditor} editor |
| 9680 |
*/ |
| 9681 |
function History (editor) { |
| 9682 |
this.editor = editor; |
| 9683 |
this.history = []; |
| 9684 |
this.index = -1; |
| 9685 |
|
| 9686 |
this.clear(); |
| 9687 |
|
| 9688 |
// map with all supported actions |
| 9689 |
this.actions = { |
| 9690 |
'editField': { |
| 9691 |
'undo': function (params) { |
| 9692 |
params.node.updateField(params.oldValue); |
| 9693 |
}, |
| 9694 |
'redo': function (params) { |
| 9695 |
params.node.updateField(params.newValue); |
| 9696 |
} |
| 9697 |
}, |
| 9698 |
'editValue': { |
| 9699 |
'undo': function (params) { |
| 9700 |
params.node.updateValue(params.oldValue); |
| 9701 |
}, |
| 9702 |
'redo': function (params) { |
| 9703 |
params.node.updateValue(params.newValue); |
| 9704 |
} |
| 9705 |
}, |
| 9706 |
'changeType': { |
| 9707 |
'undo': function (params) { |
| 9708 |
params.node.changeType(params.oldType); |
| 9709 |
}, |
| 9710 |
'redo': function (params) { |
| 9711 |
params.node.changeType(params.newType); |
| 9712 |
} |
| 9713 |
}, |
| 9714 |
|
| 9715 |
'appendNodes': { |
| 9716 |
'undo': function (params) { |
| 9717 |
params.nodes.forEach(function (node) { |
| 9718 |
params.parent.removeChild(node); |
| 9719 |
}); |
| 9720 |
}, |
| 9721 |
'redo': function (params) { |
| 9722 |
params.nodes.forEach(function (node) { |
| 9723 |
params.parent.appendChild(node); |
| 9724 |
}); |
| 9725 |
} |
| 9726 |
}, |
| 9727 |
'insertBeforeNodes': { |
| 9728 |
'undo': function (params) { |
| 9729 |
params.nodes.forEach(function (node) { |
| 9730 |
params.parent.removeChild(node); |
| 9731 |
}); |
| 9732 |
}, |
| 9733 |
'redo': function (params) { |
| 9734 |
params.nodes.forEach(function (node) { |
| 9735 |
params.parent.insertBefore(node, params.beforeNode); |
| 9736 |
}); |
| 9737 |
} |
| 9738 |
}, |
| 9739 |
'insertAfterNodes': { |
| 9740 |
'undo': function (params) { |
| 9741 |
params.nodes.forEach(function (node) { |
| 9742 |
params.parent.removeChild(node); |
| 9743 |
}); |
| 9744 |
}, |
| 9745 |
'redo': function (params) { |
| 9746 |
var afterNode = params.afterNode; |
| 9747 |
params.nodes.forEach(function (node) { |
| 9748 |
params.parent.insertAfter(params.node, afterNode); |
| 9749 |
afterNode = node; |
| 9750 |
}); |
| 9751 |
} |
| 9752 |
}, |
| 9753 |
'removeNodes': { |
| 9754 |
'undo': function (params) { |
| 9755 |
var parent = params.parent; |
| 9756 |
var beforeNode = parent.childs[params.index] || parent.append; |
| 9757 |
params.nodes.forEach(function (node) { |
| 9758 |
parent.insertBefore(node, beforeNode); |
| 9759 |
}); |
| 9760 |
}, |
| 9761 |
'redo': function (params) { |
| 9762 |
params.nodes.forEach(function (node) { |
| 9763 |
params.parent.removeChild(node); |
| 9764 |
}); |
| 9765 |
} |
| 9766 |
}, |
| 9767 |
'duplicateNodes': { |
| 9768 |
'undo': function (params) { |
| 9769 |
params.nodes.forEach(function (node) { |
| 9770 |
params.parent.removeChild(node); |
| 9771 |
}); |
| 9772 |
}, |
| 9773 |
'redo': function (params) { |
| 9774 |
var afterNode = params.afterNode; |
| 9775 |
params.nodes.forEach(function (node) { |
| 9776 |
params.parent.insertAfter(node, afterNode); |
| 9777 |
afterNode = node; |
| 9778 |
}); |
| 9779 |
} |
| 9780 |
}, |
| 9781 |
'moveNodes': { |
| 9782 |
'undo': function (params) { |
| 9783 |
params.nodes.forEach(function (node) { |
| 9784 |
params.oldBeforeNode.parent.moveBefore(node, params.oldBeforeNode); |
| 9785 |
}); |
| 9786 |
}, |
| 9787 |
'redo': function (params) { |
| 9788 |
params.nodes.forEach(function (node) { |
| 9789 |
params.newBeforeNode.parent.moveBefore(node, params.newBeforeNode); |
| 9790 |
}); |
| 9791 |
} |
| 9792 |
}, |
| 9793 |
|
| 9794 |
'sort': { |
| 9795 |
'undo': function (params) { |
| 9796 |
var node = params.node; |
| 9797 |
node.hideChilds(); |
| 9798 |
node.sort = params.oldSort; |
| 9799 |
node.childs = params.oldChilds; |
| 9800 |
node.showChilds(); |
| 9801 |
}, |
| 9802 |
'redo': function (params) { |
| 9803 |
var node = params.node; |
| 9804 |
node.hideChilds(); |
| 9805 |
node.sort = params.newSort; |
| 9806 |
node.childs = params.newChilds; |
| 9807 |
node.showChilds(); |
| 9808 |
} |
| 9809 |
} |
| 9810 |
|
| 9811 |
// TODO: restore the original caret position and selection with each undo |
| 9812 |
// TODO: implement history for actions "expand", "collapse", "scroll", "setDocument" |
| 9813 |
}; |
| 9814 |
} |
| 9815 |
|
| 9816 |
/** |
| 9817 |
* The method onChange is executed when the History is changed, and can |
| 9818 |
* be overloaded. |
| 9819 |
*/ |
| 9820 |
History.prototype.onChange = function () {}; |
| 9821 |
|
| 9822 |
/** |
| 9823 |
* Add a new action to the history |
| 9824 |
* @param {String} action The executed action. Available actions: "editField", |
| 9825 |
* "editValue", "changeType", "appendNode", |
| 9826 |
* "removeNode", "duplicateNode", "moveNode" |
| 9827 |
* @param {Object} params Object containing parameters describing the change. |
| 9828 |
* The parameters in params depend on the action (for |
| 9829 |
* example for "editValue" the Node, old value, and new |
| 9830 |
* value are provided). params contains all information |
| 9831 |
* needed to undo or redo the action. |
| 9832 |
*/ |
| 9833 |
History.prototype.add = function (action, params) { |
| 9834 |
this.index++; |
| 9835 |
this.history[this.index] = { |
| 9836 |
'action': action, |
| 9837 |
'params': params, |
| 9838 |
'timestamp': new Date() |
| 9839 |
}; |
| 9840 |
|
| 9841 |
// remove redo actions which are invalid now |
| 9842 |
if (this.index < this.history.length - 1) { |
| 9843 |
this.history.splice(this.index + 1, this.history.length - this.index - 1); |
| 9844 |
} |
| 9845 |
|
| 9846 |
// fire onchange event |
| 9847 |
this.onChange(); |
| 9848 |
}; |
| 9849 |
|
| 9850 |
/** |
| 9851 |
* Clear history |
| 9852 |
*/ |
| 9853 |
History.prototype.clear = function () { |
| 9854 |
this.history = []; |
| 9855 |
this.index = -1; |
| 9856 |
|
| 9857 |
// fire onchange event |
| 9858 |
this.onChange(); |
| 9859 |
}; |
| 9860 |
|
| 9861 |
/** |
| 9862 |
* Check if there is an action available for undo |
| 9863 |
* @return {Boolean} canUndo |
| 9864 |
*/ |
| 9865 |
History.prototype.canUndo = function () { |
| 9866 |
return (this.index >= 0); |
| 9867 |
}; |
| 9868 |
|
| 9869 |
/** |
| 9870 |
* Check if there is an action available for redo |
| 9871 |
* @return {Boolean} canRedo |
| 9872 |
*/ |
| 9873 |
History.prototype.canRedo = function () { |
| 9874 |
return (this.index < this.history.length - 1); |
| 9875 |
}; |
| 9876 |
|
| 9877 |
/** |
| 9878 |
* Undo the last action |
| 9879 |
*/ |
| 9880 |
History.prototype.undo = function () { |
| 9881 |
if (this.canUndo()) { |
| 9882 |
var obj = this.history[this.index]; |
| 9883 |
if (obj) { |
| 9884 |
var action = this.actions[obj.action]; |
| 9885 |
if (action && action.undo) { |
| 9886 |
action.undo(obj.params); |
| 9887 |
if (obj.params.oldSelection) { |
| 9888 |
this.editor.setSelection(obj.params.oldSelection); |
| 9889 |
} |
| 9890 |
} |
| 9891 |
else { |
| 9892 |
console.error(new Error('unknown action "' + obj.action + '"')); |
| 9893 |
} |
| 9894 |
} |
| 9895 |
this.index--; |
| 9896 |
|
| 9897 |
// fire onchange event |
| 9898 |
this.onChange(); |
| 9899 |
} |
| 9900 |
}; |
| 9901 |
|
| 9902 |
/** |
| 9903 |
* Redo the last action |
| 9904 |
*/ |
| 9905 |
History.prototype.redo = function () { |
| 9906 |
if (this.canRedo()) { |
| 9907 |
this.index++; |
| 9908 |
|
| 9909 |
var obj = this.history[this.index]; |
| 9910 |
if (obj) { |
| 9911 |
var action = this.actions[obj.action]; |
| 9912 |
if (action && action.redo) { |
| 9913 |
action.redo(obj.params); |
| 9914 |
if (obj.params.newSelection) { |
| 9915 |
this.editor.setSelection(obj.params.newSelection); |
| 9916 |
} |
| 9917 |
} |
| 9918 |
else { |
| 9919 |
console.error(new Error('unknown action "' + obj.action + '"')); |
| 9920 |
} |
| 9921 |
} |
| 9922 |
|
| 9923 |
// fire onchange event |
| 9924 |
this.onChange(); |
| 9925 |
} |
| 9926 |
}; |
| 9927 |
|
| 9928 |
/** |
| 9929 |
* Destroy history |
| 9930 |
*/ |
| 9931 |
History.prototype.destroy = function () { |
| 9932 |
this.editor = null; |
| 9933 |
|
| 9934 |
this.history = []; |
| 9935 |
this.index = -1; |
| 9936 |
}; |
| 9937 |
|
| 9938 |
module.exports = History; |
| 9939 |
|
| 9940 |
|
| 9941 |
/***/ }, |
| 9942 |
/* 54 */ |
| 9943 |
/***/ function(module, exports, __webpack_require__) { |
| 9944 |
|
| 9945 |
'use strict'; |
| 9946 |
|
| 9947 |
var jsonlint = __webpack_require__(55); |
| 9948 |
|
| 9949 |
/** |
| 9950 |
* Parse JSON using the parser built-in in the browser. |
| 9951 |
* On exception, the jsonString is validated and a detailed error is thrown. |
| 9952 |
* @param {String} jsonString |
| 9953 |
* @return {JSON} json |
| 9954 |
*/ |
| 9955 |
exports.parse = function parse(jsonString) { |
| 9956 |
try { |
| 9957 |
return JSON.parse(jsonString); |
| 9958 |
} |
| 9959 |
catch (err) { |
| 9960 |
// try to throw a more detailed error message using validate |
| 9961 |
exports.validate(jsonString); |
| 9962 |
|
| 9963 |
// rethrow the original error |
| 9964 |
throw err; |
| 9965 |
} |
| 9966 |
}; |
| 9967 |
|
| 9968 |
/** |
| 9969 |
* Sanitize a JSON-like string containing. For example changes JavaScript |
| 9970 |
* notation into JSON notation. |
| 9971 |
* This function for example changes a string like "{a: 2, 'b': {c: 'd'}" |
| 9972 |
* into '{"a": 2, "b": {"c": "d"}' |
| 9973 |
* @param {string} jsString |
| 9974 |
* @returns {string} json |
| 9975 |
*/ |
| 9976 |
exports.sanitize = function (jsString) { |
| 9977 |
// escape all single and double quotes inside strings |
| 9978 |
var chars = []; |
| 9979 |
var i = 0; |
| 9980 |
|
| 9981 |
//If JSON starts with a function (characters/digits/"_-"), remove this function. |
| 9982 |
//This is useful for "stripping" JSONP objects to become JSON |
| 9983 |
//For example: /* some comment */ function_12321321 ( [{"a":"b"}] ); => [{"a":"b"}] |
| 9984 |
var match = jsString.match(/^\s*(\/\*(.|[\r\n])*?\*\/)?\s*[\da-zA-Z_$]+\s*\(([\s\S]*)\)\s*;?\s*$/); |
| 9985 |
if (match) { |
| 9986 |
jsString = match[3]; |
| 9987 |
} |
| 9988 |
|
| 9989 |
// helper functions to get the current/prev/next character |
| 9990 |
function curr () { return jsString.charAt(i); } |
| 9991 |
function next() { return jsString.charAt(i + 1); } |
| 9992 |
function prev() { return jsString.charAt(i - 1); } |
| 9993 |
|
| 9994 |
// get the last parsed non-whitespace character |
| 9995 |
function lastNonWhitespace () { |
| 9996 |
var p = chars.length - 1; |
| 9997 |
|
| 9998 |
while (p >= 0) { |
| 9999 |
var pp = chars[p]; |
| 10000 |
if (pp !== ' ' && pp !== '\n' && pp !== '\r' && pp !== '\t') { // non whitespace |
| 10001 |
return pp; |
| 10002 |
} |
| 10003 |
p--; |
| 10004 |
} |
| 10005 |
|
| 10006 |
return ''; |
| 10007 |
} |
| 10008 |
|
| 10009 |
// skip a block comment '/* ... */' |
| 10010 |
function skipBlockComment () { |
| 10011 |
i += 2; |
| 10012 |
while (i < jsString.length && (curr() !== '*' || next() !== '/')) { |
| 10013 |
i++; |
| 10014 |
} |
| 10015 |
i += 2; |
| 10016 |
} |
| 10017 |
|
| 10018 |
// skip a comment '// ...' |
| 10019 |
function skipComment () { |
| 10020 |
i += 2; |
| 10021 |
while (i < jsString.length && (curr() !== '\n')) { |
| 10022 |
i++; |
| 10023 |
} |
| 10024 |
} |
| 10025 |
|
| 10026 |
// parse single or double quoted string |
| 10027 |
function parseString(quote) { |
| 10028 |
chars.push('"'); |
| 10029 |
i++; |
| 10030 |
var c = curr(); |
| 10031 |
while (i < jsString.length && c !== quote) { |
| 10032 |
if (c === '"' && prev() !== '\\') { |
| 10033 |
// unescaped double quote, escape it |
| 10034 |
chars.push('\\'); |
| 10035 |
} |
| 10036 |
|
| 10037 |
// handle escape character |
| 10038 |
if (c === '\\') { |
| 10039 |
i++; |
| 10040 |
c = curr(); |
| 10041 |
|
| 10042 |
// remove the escape character when followed by a single quote ', not needed |
| 10043 |
if (c !== '\'') { |
| 10044 |
chars.push('\\'); |
| 10045 |
} |
| 10046 |
} |
| 10047 |
chars.push(c); |
| 10048 |
|
| 10049 |
i++; |
| 10050 |
c = curr(); |
| 10051 |
} |
| 10052 |
if (c === quote) { |
| 10053 |
chars.push('"'); |
| 10054 |
i++; |
| 10055 |
} |
| 10056 |
} |
| 10057 |
|
| 10058 |
// parse an unquoted key |
| 10059 |
function parseKey() { |
| 10060 |
var specialValues = ['null', 'true', 'false']; |
| 10061 |
var key = ''; |
| 10062 |
var c = curr(); |
| 10063 |
|
| 10064 |
var regexp = /[a-zA-Z_$\d]/; // letter, number, underscore, dollar character |
| 10065 |
while (regexp.test(c)) { |
| 10066 |
key += c; |
| 10067 |
i++; |
| 10068 |
c = curr(); |
| 10069 |
} |
| 10070 |
|
| 10071 |
if (specialValues.indexOf(key) === -1) { |
| 10072 |
chars.push('"' + key + '"'); |
| 10073 |
} |
| 10074 |
else { |
| 10075 |
chars.push(key); |
| 10076 |
} |
| 10077 |
} |
| 10078 |
|
| 10079 |
while(i < jsString.length) { |
| 10080 |
var c = curr(); |
| 10081 |
|
| 10082 |
if (c === '/' && next() === '*') { |
| 10083 |
skipBlockComment(); |
| 10084 |
} |
| 10085 |
else if (c === '/' && next() === '/') { |
| 10086 |
skipComment(); |
| 10087 |
} |
| 10088 |
else if (c === '\'' || c === '"') { |
| 10089 |
parseString(c); |
| 10090 |
} |
| 10091 |
else if (/[a-zA-Z_$]/.test(c) && ['{', ','].indexOf(lastNonWhitespace()) !== -1) { |
| 10092 |
// an unquoted object key (like a in '{a:2}') |
| 10093 |
parseKey(); |
| 10094 |
} |
| 10095 |
else { |
| 10096 |
chars.push(c); |
| 10097 |
i++; |
| 10098 |
} |
| 10099 |
} |
| 10100 |
|
| 10101 |
return chars.join(''); |
| 10102 |
}; |
| 10103 |
|
| 10104 |
/** |
| 10105 |
* Escape unicode characters. |
| 10106 |
* For example input '\u2661' (length 1) will output '\\u2661' (length 5). |
| 10107 |
* @param {string} text |
| 10108 |
* @return {string} |
| 10109 |
*/ |
| 10110 |
exports.escapeUnicodeChars = function (text) { |
| 10111 |
// see https://www.wikiwand.com/en/UTF-16 |
| 10112 |
// note: we leave surrogate pairs as two individual chars, |
| 10113 |
// as JSON doesn't interpret them as a single unicode char. |
| 10114 |
return text.replace(/[\u007F-\uFFFF]/g, function(c) { |
| 10115 |
return '\\u'+('0000' + c.charCodeAt(0).toString(16)).slice(-4); |
| 10116 |
}) |
| 10117 |
}; |
| 10118 |
|
| 10119 |
/** |
| 10120 |
* Validate a string containing a JSON object |
| 10121 |
* This method uses JSONLint to validate the String. If JSONLint is not |
| 10122 |
* available, the built-in JSON parser of the browser is used. |
| 10123 |
* @param {String} jsonString String with an (invalid) JSON object |
| 10124 |
* @throws Error |
| 10125 |
*/ |
| 10126 |
exports.validate = function validate(jsonString) { |
| 10127 |
if (typeof(jsonlint) != 'undefined') { |
| 10128 |
jsonlint.parse(jsonString); |
| 10129 |
} |
| 10130 |
else { |
| 10131 |
JSON.parse(jsonString); |
| 10132 |
} |
| 10133 |
}; |
| 10134 |
|
| 10135 |
/** |
| 10136 |
* Extend object a with the properties of object b |
| 10137 |
* @param {Object} a |
| 10138 |
* @param {Object} b |
| 10139 |
* @return {Object} a |
| 10140 |
*/ |
| 10141 |
exports.extend = function extend(a, b) { |
| 10142 |
for (var prop in b) { |
| 10143 |
if (b.hasOwnProperty(prop)) { |
| 10144 |
a[prop] = b[prop]; |
| 10145 |
} |
| 10146 |
} |
| 10147 |
return a; |
| 10148 |
}; |
| 10149 |
|
| 10150 |
/** |
| 10151 |
* Remove all properties from object a |
| 10152 |
* @param {Object} a |
| 10153 |
* @return {Object} a |
| 10154 |
*/ |
| 10155 |
exports.clear = function clear (a) { |
| 10156 |
for (var prop in a) { |
| 10157 |
if (a.hasOwnProperty(prop)) { |
| 10158 |
delete a[prop]; |
| 10159 |
} |
| 10160 |
} |
| 10161 |
return a; |
| 10162 |
}; |
| 10163 |
|
| 10164 |
/** |
| 10165 |
* Get the type of an object |
| 10166 |
* @param {*} object |
| 10167 |
* @return {String} type |
| 10168 |
*/ |
| 10169 |
exports.type = function type (object) { |
| 10170 |
if (object === null) { |
| 10171 |
return 'null'; |
| 10172 |
} |
| 10173 |
if (object === undefined) { |
| 10174 |
return 'undefined'; |
| 10175 |
} |
| 10176 |
if ((object instanceof Number) || (typeof object === 'number')) { |
| 10177 |
return 'number'; |
| 10178 |
} |
| 10179 |
if ((object instanceof String) || (typeof object === 'string')) { |
| 10180 |
return 'string'; |
| 10181 |
} |
| 10182 |
if ((object instanceof Boolean) || (typeof object === 'boolean')) { |
| 10183 |
return 'boolean'; |
| 10184 |
} |
| 10185 |
if ((object instanceof RegExp) || (typeof object === 'regexp')) { |
| 10186 |
return 'regexp'; |
| 10187 |
} |
| 10188 |
if (exports.isArray(object)) { |
| 10189 |
return 'array'; |
| 10190 |
} |
| 10191 |
|
| 10192 |
return 'object'; |
| 10193 |
}; |
| 10194 |
|
| 10195 |
/** |
| 10196 |
* Test whether a text contains a url (matches when a string starts |
| 10197 |
* with 'http://*' or 'https://*' and has no whitespace characters) |
| 10198 |
* @param {String} text |
| 10199 |
*/ |
| 10200 |
var isUrlRegex = /^https?:\/\/\S+$/; |
| 10201 |
exports.isUrl = function isUrl (text) { |
| 10202 |
return (typeof text == 'string' || text instanceof String) && |
| 10203 |
isUrlRegex.test(text); |
| 10204 |
}; |
| 10205 |
|
| 10206 |
/** |
| 10207 |
* Tes whether given object is an Array |
| 10208 |
* @param {*} obj |
| 10209 |
* @returns {boolean} returns true when obj is an array |
| 10210 |
*/ |
| 10211 |
exports.isArray = function (obj) { |
| 10212 |
return Object.prototype.toString.call(obj) === '[object Array]'; |
| 10213 |
}; |
| 10214 |
|
| 10215 |
/** |
| 10216 |
* Retrieve the absolute left value of a DOM element |
| 10217 |
* @param {Element} elem A dom element, for example a div |
| 10218 |
* @return {Number} left The absolute left position of this element |
| 10219 |
* in the browser page. |
| 10220 |
*/ |
| 10221 |
exports.getAbsoluteLeft = function getAbsoluteLeft(elem) { |
| 10222 |
var rect = elem.getBoundingClientRect(); |
| 10223 |
return rect.left + window.pageXOffset || document.scrollLeft || 0; |
| 10224 |
}; |
| 10225 |
|
| 10226 |
/** |
| 10227 |
* Retrieve the absolute top value of a DOM element |
| 10228 |
* @param {Element} elem A dom element, for example a div |
| 10229 |
* @return {Number} top The absolute top position of this element |
| 10230 |
* in the browser page. |
| 10231 |
*/ |
| 10232 |
exports.getAbsoluteTop = function getAbsoluteTop(elem) { |
| 10233 |
var rect = elem.getBoundingClientRect(); |
| 10234 |
return rect.top + window.pageYOffset || document.scrollTop || 0; |
| 10235 |
}; |
| 10236 |
|
| 10237 |
/** |
| 10238 |
* add a className to the given elements style |
| 10239 |
* @param {Element} elem |
| 10240 |
* @param {String} className |
| 10241 |
*/ |
| 10242 |
exports.addClassName = function addClassName(elem, className) { |
| 10243 |
var classes = elem.className.split(' '); |
| 10244 |
if (classes.indexOf(className) == -1) { |
| 10245 |
classes.push(className); // add the class to the array |
| 10246 |
elem.className = classes.join(' '); |
| 10247 |
} |
| 10248 |
}; |
| 10249 |
|
| 10250 |
/** |
| 10251 |
* add a className to the given elements style |
| 10252 |
* @param {Element} elem |
| 10253 |
* @param {String} className |
| 10254 |
*/ |
| 10255 |
exports.removeClassName = function removeClassName(elem, className) { |
| 10256 |
var classes = elem.className.split(' '); |
| 10257 |
var index = classes.indexOf(className); |
| 10258 |
if (index != -1) { |
| 10259 |
classes.splice(index, 1); // remove the class from the array |
| 10260 |
elem.className = classes.join(' '); |
| 10261 |
} |
| 10262 |
}; |
| 10263 |
|
| 10264 |
/** |
| 10265 |
* Strip the formatting from the contents of a div |
| 10266 |
* the formatting from the div itself is not stripped, only from its childs. |
| 10267 |
* @param {Element} divElement |
| 10268 |
*/ |
| 10269 |
exports.stripFormatting = function stripFormatting(divElement) { |
| 10270 |
var childs = divElement.childNodes; |
| 10271 |
for (var i = 0, iMax = childs.length; i < iMax; i++) { |
| 10272 |
var child = childs[i]; |
| 10273 |
|
| 10274 |
// remove the style |
| 10275 |
if (child.style) { |
| 10276 |
// TODO: test if child.attributes does contain style |
| 10277 |
child.removeAttribute('style'); |
| 10278 |
} |
| 10279 |
|
| 10280 |
// remove all attributes |
| 10281 |
var attributes = child.attributes; |
| 10282 |
if (attributes) { |
| 10283 |
for (var j = attributes.length - 1; j >= 0; j--) { |
| 10284 |
var attribute = attributes[j]; |
| 10285 |
if (attribute.specified === true) { |
| 10286 |
child.removeAttribute(attribute.name); |
| 10287 |
} |
| 10288 |
} |
| 10289 |
} |
| 10290 |
|
| 10291 |
// recursively strip childs |
| 10292 |
exports.stripFormatting(child); |
| 10293 |
} |
| 10294 |
}; |
| 10295 |
|
| 10296 |
/** |
| 10297 |
* Set focus to the end of an editable div |
| 10298 |
* code from Nico Burns |
| 10299 |
* http://stackoverflow.com/users/140293/nico-burns |
| 10300 |
* http://stackoverflow.com/questions/1125292/how-to-move-cursor-to-end-of-contenteditable-entity |
| 10301 |
* @param {Element} contentEditableElement A content editable div |
| 10302 |
*/ |
| 10303 |
exports.setEndOfContentEditable = function setEndOfContentEditable(contentEditableElement) { |
| 10304 |
var range, selection; |
| 10305 |
if(document.createRange) { |
| 10306 |
range = document.createRange();//Create a range (a range is a like the selection but invisible) |
| 10307 |
range.selectNodeContents(contentEditableElement);//Select the entire contents of the element with the range |
| 10308 |
range.collapse(false);//collapse the range to the end point. false means collapse to end rather than the start |
| 10309 |
selection = window.getSelection();//get the selection object (allows you to change selection) |
| 10310 |
selection.removeAllRanges();//remove any selections already made |
| 10311 |
selection.addRange(range);//make the range you have just created the visible selection |
| 10312 |
} |
| 10313 |
}; |
| 10314 |
|
| 10315 |
/** |
| 10316 |
* Select all text of a content editable div. |
| 10317 |
* http://stackoverflow.com/a/3806004/1262753 |
| 10318 |
* @param {Element} contentEditableElement A content editable div |
| 10319 |
*/ |
| 10320 |
exports.selectContentEditable = function selectContentEditable(contentEditableElement) { |
| 10321 |
if (!contentEditableElement || contentEditableElement.nodeName != 'DIV') { |
| 10322 |
return; |
| 10323 |
} |
| 10324 |
|
| 10325 |
var sel, range; |
| 10326 |
if (window.getSelection && document.createRange) { |
| 10327 |
range = document.createRange(); |
| 10328 |
range.selectNodeContents(contentEditableElement); |
| 10329 |
sel = window.getSelection(); |
| 10330 |
sel.removeAllRanges(); |
| 10331 |
sel.addRange(range); |
| 10332 |
} |
| 10333 |
}; |
| 10334 |
|
| 10335 |
/** |
| 10336 |
* Get text selection |
| 10337 |
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore |
| 10338 |
* @return {Range | TextRange | null} range |
| 10339 |
*/ |
| 10340 |
exports.getSelection = function getSelection() { |
| 10341 |
if (window.getSelection) { |
| 10342 |
var sel = window.getSelection(); |
| 10343 |
if (sel.getRangeAt && sel.rangeCount) { |
| 10344 |
return sel.getRangeAt(0); |
| 10345 |
} |
| 10346 |
} |
| 10347 |
return null; |
| 10348 |
}; |
| 10349 |
|
| 10350 |
/** |
| 10351 |
* Set text selection |
| 10352 |
* http://stackoverflow.com/questions/4687808/contenteditable-selected-text-save-and-restore |
| 10353 |
* @param {Range | TextRange | null} range |
| 10354 |
*/ |
| 10355 |
exports.setSelection = function setSelection(range) { |
| 10356 |
if (range) { |
| 10357 |
if (window.getSelection) { |
| 10358 |
var sel = window.getSelection(); |
| 10359 |
sel.removeAllRanges(); |
| 10360 |
sel.addRange(range); |
| 10361 |
} |
| 10362 |
} |
| 10363 |
}; |
| 10364 |
|
| 10365 |
/** |
| 10366 |
* Get selected text range |
| 10367 |
* @return {Object} params object containing parameters: |
| 10368 |
* {Number} startOffset |
| 10369 |
* {Number} endOffset |
| 10370 |
* {Element} container HTML element holding the |
| 10371 |
* selected text element |
| 10372 |
* Returns null if no text selection is found |
| 10373 |
*/ |
| 10374 |
exports.getSelectionOffset = function getSelectionOffset() { |
| 10375 |
var range = exports.getSelection(); |
| 10376 |
|
| 10377 |
if (range && 'startOffset' in range && 'endOffset' in range && |
| 10378 |
range.startContainer && (range.startContainer == range.endContainer)) { |
| 10379 |
return { |
| 10380 |
startOffset: range.startOffset, |
| 10381 |
endOffset: range.endOffset, |
| 10382 |
container: range.startContainer.parentNode |
| 10383 |
}; |
| 10384 |
} |
| 10385 |
|
| 10386 |
return null; |
| 10387 |
}; |
| 10388 |
|
| 10389 |
/** |
| 10390 |
* Set selected text range in given element |
| 10391 |
* @param {Object} params An object containing: |
| 10392 |
* {Element} container |
| 10393 |
* {Number} startOffset |
| 10394 |
* {Number} endOffset |
| 10395 |
*/ |
| 10396 |
exports.setSelectionOffset = function setSelectionOffset(params) { |
| 10397 |
if (document.createRange && window.getSelection) { |
| 10398 |
var selection = window.getSelection(); |
| 10399 |
if(selection) { |
| 10400 |
var range = document.createRange(); |
| 10401 |
|
| 10402 |
if (!params.container.firstChild) { |
| 10403 |
params.container.appendChild(document.createTextNode('')); |
| 10404 |
} |
| 10405 |
|
| 10406 |
// TODO: do not suppose that the first child of the container is a textnode, |
| 10407 |
// but recursively find the textnodes |
| 10408 |
range.setStart(params.container.firstChild, params.startOffset); |
| 10409 |
range.setEnd(params.container.firstChild, params.endOffset); |
| 10410 |
|
| 10411 |
exports.setSelection(range); |
| 10412 |
} |
| 10413 |
} |
| 10414 |
}; |
| 10415 |
|
| 10416 |
/** |
| 10417 |
* Get the inner text of an HTML element (for example a div element) |
| 10418 |
* @param {Element} element |
| 10419 |
* @param {Object} [buffer] |
| 10420 |
* @return {String} innerText |
| 10421 |
*/ |
| 10422 |
exports.getInnerText = function getInnerText(element, buffer) { |
| 10423 |
var first = (buffer == undefined); |
| 10424 |
if (first) { |
| 10425 |
buffer = { |
| 10426 |
'text': '', |
| 10427 |
'flush': function () { |
| 10428 |
var text = this.text; |
| 10429 |
this.text = ''; |
| 10430 |
return text; |
| 10431 |
}, |
| 10432 |
'set': function (text) { |
| 10433 |
this.text = text; |
| 10434 |
} |
| 10435 |
}; |
| 10436 |
} |
| 10437 |
|
| 10438 |
// text node |
| 10439 |
if (element.nodeValue) { |
| 10440 |
return buffer.flush() + element.nodeValue; |
| 10441 |
} |
| 10442 |
|
| 10443 |
// divs or other HTML elements |
| 10444 |
if (element.hasChildNodes()) { |
| 10445 |
var childNodes = element.childNodes; |
| 10446 |
var innerText = ''; |
| 10447 |
|
| 10448 |
for (var i = 0, iMax = childNodes.length; i < iMax; i++) { |
| 10449 |
var child = childNodes[i]; |
| 10450 |
|
| 10451 |
if (child.nodeName == 'DIV' || child.nodeName == 'P') { |
| 10452 |
var prevChild = childNodes[i - 1]; |
| 10453 |
var prevName = prevChild ? prevChild.nodeName : undefined; |
| 10454 |
if (prevName && prevName != 'DIV' && prevName != 'P' && prevName != 'BR') { |
| 10455 |
innerText += '\n'; |
| 10456 |
buffer.flush(); |
| 10457 |
} |
| 10458 |
innerText += exports.getInnerText(child, buffer); |
| 10459 |
buffer.set('\n'); |
| 10460 |
} |
| 10461 |
else if (child.nodeName == 'BR') { |
| 10462 |
innerText += buffer.flush(); |
| 10463 |
buffer.set('\n'); |
| 10464 |
} |
| 10465 |
else { |
| 10466 |
innerText += exports.getInnerText(child, buffer); |
| 10467 |
} |
| 10468 |
} |
| 10469 |
|
| 10470 |
return innerText; |
| 10471 |
} |
| 10472 |
else { |
| 10473 |
if (element.nodeName == 'P' && exports.getInternetExplorerVersion() != -1) { |
| 10474 |
// On Internet Explorer, a <p> with hasChildNodes()==false is |
| 10475 |
// rendered with a new line. Note that a <p> with |
| 10476 |
// hasChildNodes()==true is rendered without a new line |
| 10477 |
// Other browsers always ensure there is a <br> inside the <p>, |
| 10478 |
// and if not, the <p> does not render a new line |
| 10479 |
return buffer.flush(); |
| 10480 |
} |
| 10481 |
} |
| 10482 |
|
| 10483 |
// br or unknown |
| 10484 |
return ''; |
| 10485 |
}; |
| 10486 |
|
| 10487 |
/** |
| 10488 |
* Returns the version of Internet Explorer or a -1 |
| 10489 |
* (indicating the use of another browser). |
| 10490 |
* Source: http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx |
| 10491 |
* @return {Number} Internet Explorer version, or -1 in case of an other browser |
| 10492 |
*/ |
| 10493 |
exports.getInternetExplorerVersion = function getInternetExplorerVersion() { |
| 10494 |
if (_ieVersion == -1) { |
| 10495 |
var rv = -1; // Return value assumes failure. |
| 10496 |
if (navigator.appName == 'Microsoft Internet Explorer') |
| 10497 |
{ |
| 10498 |
var ua = navigator.userAgent; |
| 10499 |
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); |
| 10500 |
if (re.exec(ua) != null) { |
| 10501 |
rv = parseFloat( RegExp.$1 ); |
| 10502 |
} |
| 10503 |
} |
| 10504 |
|
| 10505 |
_ieVersion = rv; |
| 10506 |
} |
| 10507 |
|
| 10508 |
return _ieVersion; |
| 10509 |
}; |
| 10510 |
|
| 10511 |
/** |
| 10512 |
* Test whether the current browser is Firefox |
| 10513 |
* @returns {boolean} isFirefox |
| 10514 |
*/ |
| 10515 |
exports.isFirefox = function isFirefox () { |
| 10516 |
return (navigator.userAgent.indexOf("Firefox") != -1); |
| 10517 |
}; |
| 10518 |
|
| 10519 |
/** |
| 10520 |
* cached internet explorer version |
| 10521 |
* @type {Number} |
| 10522 |
* @private |
| 10523 |
*/ |
| 10524 |
var _ieVersion = -1; |
| 10525 |
|
| 10526 |
/** |
| 10527 |
* Add and event listener. Works for all browsers |
| 10528 |
* @param {Element} element An html element |
| 10529 |
* @param {string} action The action, for example "click", |
| 10530 |
* without the prefix "on" |
| 10531 |
* @param {function} listener The callback function to be executed |
| 10532 |
* @param {boolean} [useCapture] false by default |
| 10533 |
* @return {function} the created event listener |
| 10534 |
*/ |
| 10535 |
exports.addEventListener = function addEventListener(element, action, listener, useCapture) { |
| 10536 |
if (element.addEventListener) { |
| 10537 |
if (useCapture === undefined) |
| 10538 |
useCapture = false; |
| 10539 |
|
| 10540 |
if (action === "mousewheel" && exports.isFirefox()) { |
| 10541 |
action = "DOMMouseScroll"; // For Firefox |
| 10542 |
} |
| 10543 |
|
| 10544 |
element.addEventListener(action, listener, useCapture); |
| 10545 |
return listener; |
| 10546 |
} else if (element.attachEvent) { |
| 10547 |
// Old IE browsers |
| 10548 |
var f = function () { |
| 10549 |
return listener.call(element, window.event); |
| 10550 |
}; |
| 10551 |
element.attachEvent("on" + action, f); |
| 10552 |
return f; |
| 10553 |
} |
| 10554 |
}; |
| 10555 |
|
| 10556 |
/** |
| 10557 |
* Remove an event listener from an element |
| 10558 |
* @param {Element} element An html dom element |
| 10559 |
* @param {string} action The name of the event, for example "mousedown" |
| 10560 |
* @param {function} listener The listener function |
| 10561 |
* @param {boolean} [useCapture] false by default |
| 10562 |
*/ |
| 10563 |
exports.removeEventListener = function removeEventListener(element, action, listener, useCapture) { |
| 10564 |
if (element.removeEventListener) { |
| 10565 |
if (useCapture === undefined) |
| 10566 |
useCapture = false; |
| 10567 |
|
| 10568 |
if (action === "mousewheel" && exports.isFirefox()) { |
| 10569 |
action = "DOMMouseScroll"; // For Firefox |
| 10570 |
} |
| 10571 |
|
| 10572 |
element.removeEventListener(action, listener, useCapture); |
| 10573 |
} else if (element.detachEvent) { |
| 10574 |
// Old IE browsers |
| 10575 |
element.detachEvent("on" + action, listener); |
| 10576 |
} |
| 10577 |
}; |
| 10578 |
|
| 10579 |
/** |
| 10580 |
* Parse a JSON path like '.items[3].name' into an array |
| 10581 |
* @param {string} jsonPath |
| 10582 |
* @return {Array} |
| 10583 |
*/ |
| 10584 |
exports.parsePath = function parsePath(jsonPath) { |
| 10585 |
var prop, remainder; |
| 10586 |
|
| 10587 |
if (jsonPath.length === 0) { |
| 10588 |
return []; |
| 10589 |
} |
| 10590 |
|
| 10591 |
// find a match like '.prop' |
| 10592 |
var match = jsonPath.match(/^\.(\w+)/); |
| 10593 |
if (match) { |
| 10594 |
prop = match[1]; |
| 10595 |
remainder = jsonPath.substr(prop.length + 1); |
| 10596 |
} |
| 10597 |
else if (jsonPath[0] === '[') { |
| 10598 |
// find a match like |
| 10599 |
var end = jsonPath.indexOf(']'); |
| 10600 |
if (end === -1) { |
| 10601 |
throw new SyntaxError('Character ] expected in path'); |
| 10602 |
} |
| 10603 |
if (end === 1) { |
| 10604 |
throw new SyntaxError('Index expected after ['); |
| 10605 |
} |
| 10606 |
|
| 10607 |
var value = jsonPath.substring(1, end); |
| 10608 |
if (value[0] === '\'') { |
| 10609 |
// ajv produces string prop names with single quotes, so we need |
| 10610 |
// to reformat them into valid double-quoted JSON strings |
| 10611 |
value = '\"' + value.substring(1, value.length - 1) + '\"'; |
| 10612 |
} |
| 10613 |
|
| 10614 |
prop = value === '*' ? value : JSON.parse(value); // parse string and number |
| 10615 |
remainder = jsonPath.substr(end + 1); |
| 10616 |
} |
| 10617 |
else { |
| 10618 |
throw new SyntaxError('Failed to parse path'); |
| 10619 |
} |
| 10620 |
|
| 10621 |
return [prop].concat(parsePath(remainder)) |
| 10622 |
}; |
| 10623 |
|
| 10624 |
/** |
| 10625 |
* Improve the error message of a JSON schema error |
| 10626 |
* @param {Object} error |
| 10627 |
* @return {Object} The error |
| 10628 |
*/ |
| 10629 |
exports.improveSchemaError = function (error) { |
| 10630 |
if (error.keyword === 'enum' && Array.isArray(error.schema)) { |
| 10631 |
var enums = error.schema; |
| 10632 |
if (enums) { |
| 10633 |
enums = enums.map(function (value) { |
| 10634 |
return JSON.stringify(value); |
| 10635 |
}); |
| 10636 |
|
| 10637 |
if (enums.length > 5) { |
| 10638 |
var more = ['(' + (enums.length - 5) + ' more...)']; |
| 10639 |
enums = enums.slice(0, 5); |
| 10640 |
enums.push(more); |
| 10641 |
} |
| 10642 |
error.message = 'should be equal to one of: ' + enums.join(', '); |
| 10643 |
} |
| 10644 |
} |
| 10645 |
|
| 10646 |
if (error.keyword === 'additionalProperties') { |
| 10647 |
error.message = 'should NOT have additional property: ' + error.params.additionalProperty; |
| 10648 |
} |
| 10649 |
|
| 10650 |
return error; |
| 10651 |
}; |
| 10652 |
|
| 10653 |
/** |
| 10654 |
* Test whether the child rect fits completely inside the parent rect. |
| 10655 |
* @param {ClientRect} parent |
| 10656 |
* @param {ClientRect} child |
| 10657 |
* @param {number} margin |
| 10658 |
*/ |
| 10659 |
exports.insideRect = function (parent, child, margin) { |
| 10660 |
var _margin = margin !== undefined ? margin : 0; |
| 10661 |
return child.left - _margin >= parent.left |
| 10662 |
&& child.right + _margin <= parent.right |
| 10663 |
&& child.top - _margin >= parent.top |
| 10664 |
&& child.bottom + _margin <= parent.bottom; |
| 10665 |
}; |
| 10666 |
|
| 10667 |
/** |
| 10668 |
* Returns a function, that, as long as it continues to be invoked, will not |
| 10669 |
* be triggered. The function will be called after it stops being called for |
| 10670 |
* N milliseconds. |
| 10671 |
* |
| 10672 |
* Source: https://davidwalsh.name/javascript-debounce-function |
| 10673 |
* |
| 10674 |
* @param {function} func |
| 10675 |
* @param {number} wait Number in milliseconds |
| 10676 |
* @param {boolean} [immediate=false] If `immediate` is passed, trigger the |
| 10677 |
* function on the leading edge, instead |
| 10678 |
* of the trailing. |
| 10679 |
* @return {function} Return the debounced function |
| 10680 |
*/ |
| 10681 |
exports.debounce = function debounce(func, wait, immediate) { |
| 10682 |
var timeout; |
| 10683 |
return function() { |
| 10684 |
var context = this, args = arguments; |
| 10685 |
var later = function() { |
| 10686 |
timeout = null; |
| 10687 |
if (!immediate) func.apply(context, args); |
| 10688 |
}; |
| 10689 |
var callNow = immediate && !timeout; |
| 10690 |
clearTimeout(timeout); |
| 10691 |
timeout = setTimeout(later, wait); |
| 10692 |
if (callNow) func.apply(context, args); |
| 10693 |
}; |
| 10694 |
}; |
| 10695 |
|
| 10696 |
/** |
| 10697 |
* Determines the difference between two texts. |
| 10698 |
* Can only detect one removed or inserted block of characters. |
| 10699 |
* @param {string} oldText |
| 10700 |
* @param {string} newText |
| 10701 |
* @return {{start: number, end: number}} Returns the start and end |
| 10702 |
* of the changed part in newText. |
| 10703 |
*/ |
| 10704 |
exports.textDiff = function textDiff(oldText, newText) { |
| 10705 |
var len = newText.length; |
| 10706 |
var start = 0; |
| 10707 |
var oldEnd = oldText.length; |
| 10708 |
var newEnd = newText.length; |
| 10709 |
|
| 10710 |
while (newText.charAt(start) === oldText.charAt(start) |
| 10711 |
&& start < len) { |
| 10712 |
start++; |
| 10713 |
} |
| 10714 |
|
| 10715 |
while (newText.charAt(newEnd - 1) === oldText.charAt(oldEnd - 1) |
| 10716 |
&& newEnd > start && oldEnd > 0) { |
| 10717 |
newEnd--; |
| 10718 |
oldEnd--; |
| 10719 |
} |
| 10720 |
|
| 10721 |
return {start: start, end: newEnd}; |
| 10722 |
}; |
| 10723 |
|
| 10724 |
|
| 10725 |
/***/ }, |
| 10726 |
/* 55 */ |
| 10727 |
/***/ function(module, exports, __webpack_require__) { |
| 10728 |
|
| 10729 |
/* Jison generated parser */ |
| 10730 |
var jsonlint = (function(){ |
| 10731 |
var parser = {trace: function trace() { }, |
| 10732 |
yy: {}, |
| 10733 |
symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONValue":13,"EOF":14,"JSONObject":15,"JSONArray":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1}, |
| 10734 |
terminals_: {2:"error",4:"STRING",6:"NUMBER",8:"NULL",10:"TRUE",11:"FALSE",14:"EOF",17:"{",18:"}",21:":",22:",",23:"[",24:"]"}, |
| 10735 |
productions_: [0,[3,1],[5,1],[7,1],[9,1],[9,1],[12,2],[13,1],[13,1],[13,1],[13,1],[13,1],[13,1],[15,2],[15,3],[20,3],[19,1],[19,3],[16,2],[16,3],[25,1],[25,3]], |
| 10736 |
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) { |
| 10737 |
|
| 10738 |
var $0 = $$.length - 1; |
| 10739 |
switch (yystate) { |
| 10740 |
case 1: // replace escaped characters with actual character |
| 10741 |
this.$ = yytext.replace(/\\(\\|")/g, "$"+"1") |
| 10742 |
.replace(/\\n/g,'\n') |
| 10743 |
.replace(/\\r/g,'\r') |
| 10744 |
.replace(/\\t/g,'\t') |
| 10745 |
.replace(/\\v/g,'\v') |
| 10746 |
.replace(/\\f/g,'\f') |
| 10747 |
.replace(/\\b/g,'\b'); |
| 10748 |
|
| 10749 |
break; |
| 10750 |
case 2:this.$ = Number(yytext); |
| 10751 |
break; |
| 10752 |
case 3:this.$ = null; |
| 10753 |
break; |
| 10754 |
case 4:this.$ = true; |
| 10755 |
break; |
| 10756 |
case 5:this.$ = false; |
| 10757 |
break; |
| 10758 |
case 6:return this.$ = $$[$0-1]; |
| 10759 |
break; |
| 10760 |
case 13:this.$ = {}; |
| 10761 |
break; |
| 10762 |
case 14:this.$ = $$[$0-1]; |
| 10763 |
break; |
| 10764 |
case 15:this.$ = [$$[$0-2], $$[$0]]; |
| 10765 |
break; |
| 10766 |
case 16:this.$ = {}; this.$[$$[$0][0]] = $$[$0][1]; |
| 10767 |
break; |
| 10768 |
case 17:this.$ = $$[$0-2]; $$[$0-2][$$[$0][0]] = $$[$0][1]; |
| 10769 |
break; |
| 10770 |
case 18:this.$ = []; |
| 10771 |
break; |
| 10772 |
case 19:this.$ = $$[$0-1]; |
| 10773 |
break; |
| 10774 |
case 20:this.$ = [$$[$0]]; |
| 10775 |
break; |
| 10776 |
case 21:this.$ = $$[$0-2]; $$[$0-2].push($$[$0]); |
| 10777 |
break; |
| 10778 |
} |
| 10779 |
}, |
| 10780 |
table: [{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],12:1,13:2,15:7,16:8,17:[1,14],23:[1,15]},{1:[3]},{14:[1,16]},{14:[2,7],18:[2,7],22:[2,7],24:[2,7]},{14:[2,8],18:[2,8],22:[2,8],24:[2,8]},{14:[2,9],18:[2,9],22:[2,9],24:[2,9]},{14:[2,10],18:[2,10],22:[2,10],24:[2,10]},{14:[2,11],18:[2,11],22:[2,11],24:[2,11]},{14:[2,12],18:[2,12],22:[2,12],24:[2,12]},{14:[2,3],18:[2,3],22:[2,3],24:[2,3]},{14:[2,4],18:[2,4],22:[2,4],24:[2,4]},{14:[2,5],18:[2,5],22:[2,5],24:[2,5]},{14:[2,1],18:[2,1],21:[2,1],22:[2,1],24:[2,1]},{14:[2,2],18:[2,2],22:[2,2],24:[2,2]},{3:20,4:[1,12],18:[1,17],19:18,20:19},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:23,15:7,16:8,17:[1,14],23:[1,15],24:[1,21],25:22},{1:[2,6]},{14:[2,13],18:[2,13],22:[2,13],24:[2,13]},{18:[1,24],22:[1,25]},{18:[2,16],22:[2,16]},{21:[1,26]},{14:[2,18],18:[2,18],22:[2,18],24:[2,18]},{22:[1,28],24:[1,27]},{22:[2,20],24:[2,20]},{14:[2,14],18:[2,14],22:[2,14],24:[2,14]},{3:20,4:[1,12],20:29},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:30,15:7,16:8,17:[1,14],23:[1,15]},{14:[2,19],18:[2,19],22:[2,19],24:[2,19]},{3:5,4:[1,12],5:6,6:[1,13],7:3,8:[1,9],9:4,10:[1,10],11:[1,11],13:31,15:7,16:8,17:[1,14],23:[1,15]},{18:[2,17],22:[2,17]},{18:[2,15],22:[2,15]},{22:[2,21],24:[2,21]}], |
| 10781 |
defaultActions: {16:[2,6]}, |
| 10782 |
parseError: function parseError(str, hash) { |
| 10783 |
throw new Error(str); |
| 10784 |
}, |
| 10785 |
parse: function parse(input) { |
| 10786 |
var self = this, |
| 10787 |
stack = [0], |
| 10788 |
vstack = [null], // semantic value stack |
| 10789 |
lstack = [], // location stack |
| 10790 |
table = this.table, |
| 10791 |
yytext = '', |
| 10792 |
yylineno = 0, |
| 10793 |
yyleng = 0, |
| 10794 |
recovering = 0, |
| 10795 |
TERROR = 2, |
| 10796 |
EOF = 1; |
| 10797 |
|
| 10798 |
//this.reductionCount = this.shiftCount = 0; |
| 10799 |
|
| 10800 |
this.lexer.setInput(input); |
| 10801 |
this.lexer.yy = this.yy; |
| 10802 |
this.yy.lexer = this.lexer; |
| 10803 |
if (typeof this.lexer.yylloc == 'undefined') |
| 10804 |
this.lexer.yylloc = {}; |
| 10805 |
var yyloc = this.lexer.yylloc; |
| 10806 |
lstack.push(yyloc); |
| 10807 |
|
| 10808 |
if (typeof this.yy.parseError === 'function') |
| 10809 |
this.parseError = this.yy.parseError; |
| 10810 |
|
| 10811 |
function popStack (n) { |
| 10812 |
stack.length = stack.length - 2*n; |
| 10813 |
vstack.length = vstack.length - n; |
| 10814 |
lstack.length = lstack.length - n; |
| 10815 |
} |
| 10816 |
|
| 10817 |
function lex() { |
| 10818 |
var token; |
| 10819 |
token = self.lexer.lex() || 1; // $end = 1 |
| 10820 |
// if token isn't its numeric value, convert |
| 10821 |
if (typeof token !== 'number') { |
| 10822 |
token = self.symbols_[token] || token; |
| 10823 |
} |
| 10824 |
return token; |
| 10825 |
} |
| 10826 |
|
| 10827 |
var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected; |
| 10828 |
while (true) { |
| 10829 |
// retreive state number from top of stack |
| 10830 |
state = stack[stack.length-1]; |
| 10831 |
|
| 10832 |
// use default actions if available |
| 10833 |
if (this.defaultActions[state]) { |
| 10834 |
action = this.defaultActions[state]; |
| 10835 |
} else { |
| 10836 |
if (symbol == null) |
| 10837 |
symbol = lex(); |
| 10838 |
// read action for current state and first input |
| 10839 |
action = table[state] && table[state][symbol]; |
| 10840 |
} |
| 10841 |
|
| 10842 |
// handle parse error |
| 10843 |
_handle_error: |
| 10844 |
if (typeof action === 'undefined' || !action.length || !action[0]) { |
| 10845 |
|
| 10846 |
if (!recovering) { |
| 10847 |
// Report error |
| 10848 |
expected = []; |
| 10849 |
for (p in table[state]) if (this.terminals_[p] && p > 2) { |
| 10850 |
expected.push("'"+this.terminals_[p]+"'"); |
| 10851 |
} |
| 10852 |
var errStr = ''; |
| 10853 |
if (this.lexer.showPosition) { |
| 10854 |
errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'"; |
| 10855 |
} else { |
| 10856 |
errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " + |
| 10857 |
(symbol == 1 /*EOF*/ ? "end of input" : |
| 10858 |
("'"+(this.terminals_[symbol] || symbol)+"'")); |
| 10859 |
} |
| 10860 |
this.parseError(errStr, |
| 10861 |
{text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected}); |
| 10862 |
} |
| 10863 |
|
| 10864 |
// just recovered from another error |
| 10865 |
if (recovering == 3) { |
| 10866 |
if (symbol == EOF) { |
| 10867 |
throw new Error(errStr || 'Parsing halted.'); |
| 10868 |
} |
| 10869 |
|
| 10870 |
// discard current lookahead and grab another |
| 10871 |
yyleng = this.lexer.yyleng; |
| 10872 |
yytext = this.lexer.yytext; |
| 10873 |
yylineno = this.lexer.yylineno; |
| 10874 |
yyloc = this.lexer.yylloc; |
| 10875 |
symbol = lex(); |
| 10876 |
} |
| 10877 |
|
| 10878 |
// try to recover from error |
| 10879 |
while (1) { |
| 10880 |
// check for error recovery rule in this state |
| 10881 |
if ((TERROR.toString()) in table[state]) { |
| 10882 |
break; |
| 10883 |
} |
| 10884 |
if (state == 0) { |
| 10885 |
throw new Error(errStr || 'Parsing halted.'); |
| 10886 |
} |
| 10887 |
popStack(1); |
| 10888 |
state = stack[stack.length-1]; |
| 10889 |
} |
| 10890 |
|
| 10891 |
preErrorSymbol = symbol; // save the lookahead token |
| 10892 |
symbol = TERROR; // insert generic error symbol as new lookahead |
| 10893 |
state = stack[stack.length-1]; |
| 10894 |
action = table[state] && table[state][TERROR]; |
| 10895 |
recovering = 3; // allow 3 real symbols to be shifted before reporting a new error |
| 10896 |
} |
| 10897 |
|
| 10898 |
// this shouldn't happen, unless resolve defaults are off |
| 10899 |
if (action[0] instanceof Array && action.length > 1) { |
| 10900 |
throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol); |
| 10901 |
} |
| 10902 |
|
| 10903 |
switch (action[0]) { |
| 10904 |
|
| 10905 |
case 1: // shift |
| 10906 |
//this.shiftCount++; |
| 10907 |
|
| 10908 |
stack.push(symbol); |
| 10909 |
vstack.push(this.lexer.yytext); |
| 10910 |
lstack.push(this.lexer.yylloc); |
| 10911 |
stack.push(action[1]); // push state |
| 10912 |
symbol = null; |
| 10913 |
if (!preErrorSymbol) { // normal execution/no error |
| 10914 |
yyleng = this.lexer.yyleng; |
| 10915 |
yytext = this.lexer.yytext; |
| 10916 |
yylineno = this.lexer.yylineno; |
| 10917 |
yyloc = this.lexer.yylloc; |
| 10918 |
if (recovering > 0) |
| 10919 |
recovering--; |
| 10920 |
} else { // error just occurred, resume old lookahead f/ before error |
| 10921 |
symbol = preErrorSymbol; |
| 10922 |
preErrorSymbol = null; |
| 10923 |
} |
| 10924 |
break; |
| 10925 |
|
| 10926 |
case 2: // reduce |
| 10927 |
//this.reductionCount++; |
| 10928 |
|
| 10929 |
len = this.productions_[action[1]][1]; |
| 10930 |
|
| 10931 |
// perform semantic action |
| 10932 |
yyval.$ = vstack[vstack.length-len]; // default to $$ = $1 |
| 10933 |
// default location, uses first token for firsts, last for lasts |
| 10934 |
yyval._$ = { |
| 10935 |
first_line: lstack[lstack.length-(len||1)].first_line, |
| 10936 |
last_line: lstack[lstack.length-1].last_line, |
| 10937 |
first_column: lstack[lstack.length-(len||1)].first_column, |
| 10938 |
last_column: lstack[lstack.length-1].last_column |
| 10939 |
}; |
| 10940 |
r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); |
| 10941 |
|
| 10942 |
if (typeof r !== 'undefined') { |
| 10943 |
return r; |
| 10944 |
} |
| 10945 |
|
| 10946 |
// pop off stack |
| 10947 |
if (len) { |
| 10948 |
stack = stack.slice(0,-1*len*2); |
| 10949 |
vstack = vstack.slice(0, -1*len); |
| 10950 |
lstack = lstack.slice(0, -1*len); |
| 10951 |
} |
| 10952 |
|
| 10953 |
stack.push(this.productions_[action[1]][0]); // push nonterminal (reduce) |
| 10954 |
vstack.push(yyval.$); |
| 10955 |
lstack.push(yyval._$); |
| 10956 |
// goto new state = table[STATE][NONTERMINAL] |
| 10957 |
newState = table[stack[stack.length-2]][stack[stack.length-1]]; |
| 10958 |
stack.push(newState); |
| 10959 |
break; |
| 10960 |
|
| 10961 |
case 3: // accept |
| 10962 |
return true; |
| 10963 |
} |
| 10964 |
|
| 10965 |
} |
| 10966 |
|
| 10967 |
return true; |
| 10968 |
}}; |
| 10969 |
/* Jison generated lexer */ |
| 10970 |
var lexer = (function(){ |
| 10971 |
var lexer = ({EOF:1, |
| 10972 |
parseError:function parseError(str, hash) { |
| 10973 |
if (this.yy.parseError) { |
| 10974 |
this.yy.parseError(str, hash); |
| 10975 |
} else { |
| 10976 |
throw new Error(str); |
| 10977 |
} |
| 10978 |
}, |
| 10979 |
setInput:function (input) { |
| 10980 |
this._input = input; |
| 10981 |
this._more = this._less = this.done = false; |
| 10982 |
this.yylineno = this.yyleng = 0; |
| 10983 |
this.yytext = this.matched = this.match = ''; |
| 10984 |
this.conditionStack = ['INITIAL']; |
| 10985 |
this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0}; |
| 10986 |
return this; |
| 10987 |
}, |
| 10988 |
input:function () { |
| 10989 |
var ch = this._input[0]; |
| 10990 |
this.yytext+=ch; |
| 10991 |
this.yyleng++; |
| 10992 |
this.match+=ch; |
| 10993 |
this.matched+=ch; |
| 10994 |
var lines = ch.match(/\n/); |
| 10995 |
if (lines) this.yylineno++; |
| 10996 |
this._input = this._input.slice(1); |
| 10997 |
return ch; |
| 10998 |
}, |
| 10999 |
unput:function (ch) { |
| 11000 |
this._input = ch + this._input; |
| 11001 |
return this; |
| 11002 |
}, |
| 11003 |
more:function () { |
| 11004 |
this._more = true; |
| 11005 |
return this; |
| 11006 |
}, |
| 11007 |
less:function (n) { |
| 11008 |
this._input = this.match.slice(n) + this._input; |
| 11009 |
}, |
| 11010 |
pastInput:function () { |
| 11011 |
var past = this.matched.substr(0, this.matched.length - this.match.length); |
| 11012 |
return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, ""); |
| 11013 |
}, |
| 11014 |
upcomingInput:function () { |
| 11015 |
var next = this.match; |
| 11016 |
if (next.length < 20) { |
| 11017 |
next += this._input.substr(0, 20-next.length); |
| 11018 |
} |
| 11019 |
return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, ""); |
| 11020 |
}, |
| 11021 |
showPosition:function () { |
| 11022 |
var pre = this.pastInput(); |
| 11023 |
var c = new Array(pre.length + 1).join("-"); |
| 11024 |
return pre + this.upcomingInput() + "\n" + c+"^"; |
| 11025 |
}, |
| 11026 |
next:function () { |
| 11027 |
if (this.done) { |
| 11028 |
return this.EOF; |
| 11029 |
} |
| 11030 |
if (!this._input) this.done = true; |
| 11031 |
|
| 11032 |
var token, |
| 11033 |
match, |
| 11034 |
tempMatch, |
| 11035 |
index, |
| 11036 |
col, |
| 11037 |
lines; |
| 11038 |
if (!this._more) { |
| 11039 |
this.yytext = ''; |
| 11040 |
this.match = ''; |
| 11041 |
} |
| 11042 |
var rules = this._currentRules(); |
| 11043 |
for (var i=0;i < rules.length; i++) { |
| 11044 |
tempMatch = this._input.match(this.rules[rules[i]]); |
| 11045 |
if (tempMatch && (!match || tempMatch[0].length > match[0].length)) { |
| 11046 |
match = tempMatch; |
| 11047 |
index = i; |
| 11048 |
if (!this.options.flex) break; |
| 11049 |
} |
| 11050 |
} |
| 11051 |
if (match) { |
| 11052 |
lines = match[0].match(/\n.*/g); |
| 11053 |
if (lines) this.yylineno += lines.length; |
| 11054 |
this.yylloc = {first_line: this.yylloc.last_line, |
| 11055 |
last_line: this.yylineno+1, |
| 11056 |
first_column: this.yylloc.last_column, |
| 11057 |
last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length} |
| 11058 |
this.yytext += match[0]; |
| 11059 |
this.match += match[0]; |
| 11060 |
this.yyleng = this.yytext.length; |
| 11061 |
this._more = false; |
| 11062 |
this._input = this._input.slice(match[0].length); |
| 11063 |
this.matched += match[0]; |
| 11064 |
token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]); |
| 11065 |
if (this.done && this._input) this.done = false; |
| 11066 |
if (token) return token; |
| 11067 |
else return; |
| 11068 |
} |
| 11069 |
if (this._input === "") { |
| 11070 |
return this.EOF; |
| 11071 |
} else { |
| 11072 |
this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(), |
| 11073 |
{text: "", token: null, line: this.yylineno}); |
| 11074 |
} |
| 11075 |
}, |
| 11076 |
lex:function lex() { |
| 11077 |
var r = this.next(); |
| 11078 |
if (typeof r !== 'undefined') { |
| 11079 |
return r; |
| 11080 |
} else { |
| 11081 |
return this.lex(); |
| 11082 |
} |
| 11083 |
}, |
| 11084 |
begin:function begin(condition) { |
| 11085 |
this.conditionStack.push(condition); |
| 11086 |
}, |
| 11087 |
popState:function popState() { |
| 11088 |
return this.conditionStack.pop(); |
| 11089 |
}, |
| 11090 |
_currentRules:function _currentRules() { |
| 11091 |
return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules; |
| 11092 |
}, |
| 11093 |
topState:function () { |
| 11094 |
return this.conditionStack[this.conditionStack.length-2]; |
| 11095 |
}, |
| 11096 |
pushState:function begin(condition) { |
| 11097 |
this.begin(condition); |
| 11098 |
}}); |
| 11099 |
lexer.options = {}; |
| 11100 |
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { |
| 11101 |
|
| 11102 |
var YYSTATE=YY_START |
| 11103 |
switch($avoiding_name_collisions) { |
| 11104 |
case 0:/* skip whitespace */ |
| 11105 |
break; |
| 11106 |
case 1:return 6 |
| 11107 |
break; |
| 11108 |
case 2:yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2); return 4 |
| 11109 |
break; |
| 11110 |
case 3:return 17 |
| 11111 |
break; |
| 11112 |
case 4:return 18 |
| 11113 |
break; |
| 11114 |
case 5:return 23 |
| 11115 |
break; |
| 11116 |
case 6:return 24 |
| 11117 |
break; |
| 11118 |
case 7:return 22 |
| 11119 |
break; |
| 11120 |
case 8:return 21 |
| 11121 |
break; |
| 11122 |
case 9:return 10 |
| 11123 |
break; |
| 11124 |
case 10:return 11 |
| 11125 |
break; |
| 11126 |
case 11:return 8 |
| 11127 |
break; |
| 11128 |
case 12:return 14 |
| 11129 |
break; |
| 11130 |
case 13:return 'INVALID' |
| 11131 |
break; |
| 11132 |
} |
| 11133 |
}; |
| 11134 |
lexer.rules = [/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]+)?\b)/,/^(?:"(?:\\[\\"bfnrt/]|\\u[a-fA-F0-9]{4}|[^\\\0-\x09\x0a-\x1f"])*")/,/^(?:\{)/,/^(?:\})/,/^(?:\[)/,/^(?:\])/,/^(?:,)/,/^(?::)/,/^(?:true\b)/,/^(?:false\b)/,/^(?:null\b)/,/^(?:$)/,/^(?:.)/]; |
| 11135 |
lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}}; |
| 11136 |
|
| 11137 |
|
| 11138 |
; |
| 11139 |
return lexer;})() |
| 11140 |
parser.lexer = lexer; |
| 11141 |
return parser; |
| 11142 |
})(); |
| 11143 |
if (true) { |
| 11144 |
exports.parser = jsonlint; |
| 11145 |
exports.parse = jsonlint.parse.bind(jsonlint); |
| 11146 |
} |
| 11147 |
|
| 11148 |
/***/ }, |
| 11149 |
/* 56 */ |
| 11150 |
/***/ function(module, exports) { |
| 11151 |
|
| 11152 |
'use strict'; |
| 11153 |
|
| 11154 |
/** |
| 11155 |
* @constructor SearchBox |
| 11156 |
* Create a search box in given HTML container |
| 11157 |
* @param {JSONEditor} editor The JSON Editor to attach to |
| 11158 |
* @param {Element} container HTML container element of where to |
| 11159 |
* create the search box |
| 11160 |
*/ |
| 11161 |
function SearchBox (editor, container) { |
| 11162 |
var searchBox = this; |
| 11163 |
|
| 11164 |
this.editor = editor; |
| 11165 |
this.timeout = undefined; |
| 11166 |
this.delay = 200; // ms |
| 11167 |
this.lastText = undefined; |
| 11168 |
|
| 11169 |
this.dom = {}; |
| 11170 |
this.dom.container = container; |
| 11171 |
|
| 11172 |
var table = document.createElement('table'); |
| 11173 |
this.dom.table = table; |
| 11174 |
table.className = 'jsoneditor-search'; |
| 11175 |
container.appendChild(table); |
| 11176 |
var tbody = document.createElement('tbody'); |
| 11177 |
this.dom.tbody = tbody; |
| 11178 |
table.appendChild(tbody); |
| 11179 |
var tr = document.createElement('tr'); |
| 11180 |
tbody.appendChild(tr); |
| 11181 |
|
| 11182 |
var td = document.createElement('td'); |
| 11183 |
tr.appendChild(td); |
| 11184 |
var results = document.createElement('div'); |
| 11185 |
this.dom.results = results; |
| 11186 |
results.className = 'jsoneditor-results'; |
| 11187 |
td.appendChild(results); |
| 11188 |
|
| 11189 |
td = document.createElement('td'); |
| 11190 |
tr.appendChild(td); |
| 11191 |
var divInput = document.createElement('div'); |
| 11192 |
this.dom.input = divInput; |
| 11193 |
divInput.className = 'jsoneditor-frame'; |
| 11194 |
divInput.title = 'Search fields and values'; |
| 11195 |
td.appendChild(divInput); |
| 11196 |
|
| 11197 |
// table to contain the text input and search button |
| 11198 |
var tableInput = document.createElement('table'); |
| 11199 |
divInput.appendChild(tableInput); |
| 11200 |
var tbodySearch = document.createElement('tbody'); |
| 11201 |
tableInput.appendChild(tbodySearch); |
| 11202 |
tr = document.createElement('tr'); |
| 11203 |
tbodySearch.appendChild(tr); |
| 11204 |
|
| 11205 |
var refreshSearch = document.createElement('button'); |
| 11206 |
refreshSearch.type = 'button'; |
| 11207 |
refreshSearch.className = 'jsoneditor-refresh'; |
| 11208 |
td = document.createElement('td'); |
| 11209 |
td.appendChild(refreshSearch); |
| 11210 |
tr.appendChild(td); |
| 11211 |
|
| 11212 |
var search = document.createElement('input'); |
| 11213 |
// search.type = 'button'; |
| 11214 |
this.dom.search = search; |
| 11215 |
search.oninput = function (event) { |
| 11216 |
searchBox._onDelayedSearch(event); |
| 11217 |
}; |
| 11218 |
search.onchange = function (event) { // For IE 9 |
| 11219 |
searchBox._onSearch(); |
| 11220 |
}; |
| 11221 |
search.onkeydown = function (event) { |
| 11222 |
searchBox._onKeyDown(event); |
| 11223 |
}; |
| 11224 |
search.onkeyup = function (event) { |
| 11225 |
searchBox._onKeyUp(event); |
| 11226 |
}; |
| 11227 |
refreshSearch.onclick = function (event) { |
| 11228 |
search.select(); |
| 11229 |
}; |
| 11230 |
|
| 11231 |
// TODO: ESC in FF restores the last input, is a FF bug, https://bugzilla.mozilla.org/show_bug.cgi?id=598819 |
| 11232 |
td = document.createElement('td'); |
| 11233 |
td.appendChild(search); |
| 11234 |
tr.appendChild(td); |
| 11235 |
|
| 11236 |
var searchNext = document.createElement('button'); |
| 11237 |
searchNext.type = 'button'; |
| 11238 |
searchNext.title = 'Next result (Enter)'; |
| 11239 |
searchNext.className = 'jsoneditor-next'; |
| 11240 |
searchNext.onclick = function () { |
| 11241 |
searchBox.next(); |
| 11242 |
}; |
| 11243 |
td = document.createElement('td'); |
| 11244 |
td.appendChild(searchNext); |
| 11245 |
tr.appendChild(td); |
| 11246 |
|
| 11247 |
var searchPrevious = document.createElement('button'); |
| 11248 |
searchPrevious.type = 'button'; |
| 11249 |
searchPrevious.title = 'Previous result (Shift+Enter)'; |
| 11250 |
searchPrevious.className = 'jsoneditor-previous'; |
| 11251 |
searchPrevious.onclick = function () { |
| 11252 |
searchBox.previous(); |
| 11253 |
}; |
| 11254 |
td = document.createElement('td'); |
| 11255 |
td.appendChild(searchPrevious); |
| 11256 |
tr.appendChild(td); |
| 11257 |
} |
| 11258 |
|
| 11259 |
/** |
| 11260 |
* Go to the next search result |
| 11261 |
* @param {boolean} [focus] If true, focus will be set to the next result |
| 11262 |
* focus is false by default. |
| 11263 |
*/ |
| 11264 |
SearchBox.prototype.next = function(focus) { |
| 11265 |
if (this.results != undefined) { |
| 11266 |
var index = (this.resultIndex != undefined) ? this.resultIndex + 1 : 0; |
| 11267 |
if (index > this.results.length - 1) { |
| 11268 |
index = 0; |
| 11269 |
} |
| 11270 |
this._setActiveResult(index, focus); |
| 11271 |
} |
| 11272 |
}; |
| 11273 |
|
| 11274 |
/** |
| 11275 |
* Go to the prevous search result |
| 11276 |
* @param {boolean} [focus] If true, focus will be set to the next result |
| 11277 |
* focus is false by default. |
| 11278 |
*/ |
| 11279 |
SearchBox.prototype.previous = function(focus) { |
| 11280 |
if (this.results != undefined) { |
| 11281 |
var max = this.results.length - 1; |
| 11282 |
var index = (this.resultIndex != undefined) ? this.resultIndex - 1 : max; |
| 11283 |
if (index < 0) { |
| 11284 |
index = max; |
| 11285 |
} |
| 11286 |
this._setActiveResult(index, focus); |
| 11287 |
} |
| 11288 |
}; |
| 11289 |
|
| 11290 |
/** |
| 11291 |
* Set new value for the current active result |
| 11292 |
* @param {Number} index |
| 11293 |
* @param {boolean} [focus] If true, focus will be set to the next result. |
| 11294 |
* focus is false by default. |
| 11295 |
* @private |
| 11296 |
*/ |
| 11297 |
SearchBox.prototype._setActiveResult = function(index, focus) { |
| 11298 |
// de-activate current active result |
| 11299 |
if (this.activeResult) { |
| 11300 |
var prevNode = this.activeResult.node; |
| 11301 |
var prevElem = this.activeResult.elem; |
| 11302 |
if (prevElem == 'field') { |
| 11303 |
delete prevNode.searchFieldActive; |
| 11304 |
} |
| 11305 |
else { |
| 11306 |
delete prevNode.searchValueActive; |
| 11307 |
} |
| 11308 |
prevNode.updateDom(); |
| 11309 |
} |
| 11310 |
|
| 11311 |
if (!this.results || !this.results[index]) { |
| 11312 |
// out of range, set to undefined |
| 11313 |
this.resultIndex = undefined; |
| 11314 |
this.activeResult = undefined; |
| 11315 |
return; |
| 11316 |
} |
| 11317 |
|
| 11318 |
this.resultIndex = index; |
| 11319 |
|
| 11320 |
// set new node active |
| 11321 |
var node = this.results[this.resultIndex].node; |
| 11322 |
var elem = this.results[this.resultIndex].elem; |
| 11323 |
if (elem == 'field') { |
| 11324 |
node.searchFieldActive = true; |
| 11325 |
} |
| 11326 |
else { |
| 11327 |
node.searchValueActive = true; |
| 11328 |
} |
| 11329 |
this.activeResult = this.results[this.resultIndex]; |
| 11330 |
node.updateDom(); |
| 11331 |
|
| 11332 |
// TODO: not so nice that the focus is only set after the animation is finished |
| 11333 |
node.scrollTo(function () { |
| 11334 |
if (focus) { |
| 11335 |
node.focus(elem); |
| 11336 |
} |
| 11337 |
}); |
| 11338 |
}; |
| 11339 |
|
| 11340 |
/** |
| 11341 |
* Cancel any running onDelayedSearch. |
| 11342 |
* @private |
| 11343 |
*/ |
| 11344 |
SearchBox.prototype._clearDelay = function() { |
| 11345 |
if (this.timeout != undefined) { |
| 11346 |
clearTimeout(this.timeout); |
| 11347 |
delete this.timeout; |
| 11348 |
} |
| 11349 |
}; |
| 11350 |
|
| 11351 |
/** |
| 11352 |
* Start a timer to execute a search after a short delay. |
| 11353 |
* Used for reducing the number of searches while typing. |
| 11354 |
* @param {Event} event |
| 11355 |
* @private |
| 11356 |
*/ |
| 11357 |
SearchBox.prototype._onDelayedSearch = function (event) { |
| 11358 |
// execute the search after a short delay (reduces the number of |
| 11359 |
// search actions while typing in the search text box) |
| 11360 |
this._clearDelay(); |
| 11361 |
var searchBox = this; |
| 11362 |
this.timeout = setTimeout(function (event) { |
| 11363 |
searchBox._onSearch(); |
| 11364 |
}, |
| 11365 |
this.delay); |
| 11366 |
}; |
| 11367 |
|
| 11368 |
/** |
| 11369 |
* Handle onSearch event |
| 11370 |
* @param {boolean} [forceSearch] If true, search will be executed again even |
| 11371 |
* when the search text is not changed. |
| 11372 |
* Default is false. |
| 11373 |
* @private |
| 11374 |
*/ |
| 11375 |
SearchBox.prototype._onSearch = function (forceSearch) { |
| 11376 |
this._clearDelay(); |
| 11377 |
|
| 11378 |
var value = this.dom.search.value; |
| 11379 |
var text = (value.length > 0) ? value : undefined; |
| 11380 |
if (text != this.lastText || forceSearch) { |
| 11381 |
// only search again when changed |
| 11382 |
this.lastText = text; |
| 11383 |
this.results = this.editor.search(text); |
| 11384 |
this._setActiveResult(undefined); |
| 11385 |
|
| 11386 |
// display search results |
| 11387 |
if (text != undefined) { |
| 11388 |
var resultCount = this.results.length; |
| 11389 |
switch (resultCount) { |
| 11390 |
case 0: this.dom.results.innerHTML = 'no results'; break; |
| 11391 |
case 1: this.dom.results.innerHTML = '1 result'; break; |
| 11392 |
default: this.dom.results.innerHTML = resultCount + ' results'; break; |
| 11393 |
} |
| 11394 |
} |
| 11395 |
else { |
| 11396 |
this.dom.results.innerHTML = ''; |
| 11397 |
} |
| 11398 |
} |
| 11399 |
}; |
| 11400 |
|
| 11401 |
/** |
| 11402 |
* Handle onKeyDown event in the input box |
| 11403 |
* @param {Event} event |
| 11404 |
* @private |
| 11405 |
*/ |
| 11406 |
SearchBox.prototype._onKeyDown = function (event) { |
| 11407 |
var keynum = event.which; |
| 11408 |
if (keynum == 27) { // ESC |
| 11409 |
this.dom.search.value = ''; // clear search |
| 11410 |
this._onSearch(); |
| 11411 |
event.preventDefault(); |
| 11412 |
event.stopPropagation(); |
| 11413 |
} |
| 11414 |
else if (keynum == 13) { // Enter |
| 11415 |
if (event.ctrlKey) { |
| 11416 |
// force to search again |
| 11417 |
this._onSearch(true); |
| 11418 |
} |
| 11419 |
else if (event.shiftKey) { |
| 11420 |
// move to the previous search result |
| 11421 |
this.previous(); |
| 11422 |
} |
| 11423 |
else { |
| 11424 |
// move to the next search result |
| 11425 |
this.next(); |
| 11426 |
} |
| 11427 |
event.preventDefault(); |
| 11428 |
event.stopPropagation(); |
| 11429 |
} |
| 11430 |
}; |
| 11431 |
|
| 11432 |
/** |
| 11433 |
* Handle onKeyUp event in the input box |
| 11434 |
* @param {Event} event |
| 11435 |
* @private |
| 11436 |
*/ |
| 11437 |
SearchBox.prototype._onKeyUp = function (event) { |
| 11438 |
var keynum = event.keyCode; |
| 11439 |
if (keynum != 27 && keynum != 13) { // !show and !Enter |
| 11440 |
this._onDelayedSearch(event); // For IE 9 |
| 11441 |
} |
| 11442 |
}; |
| 11443 |
|
| 11444 |
/** |
| 11445 |
* Clear the search results |
| 11446 |
*/ |
| 11447 |
SearchBox.prototype.clear = function () { |
| 11448 |
this.dom.search.value = ''; |
| 11449 |
this._onSearch(); |
| 11450 |
}; |
| 11451 |
|
| 11452 |
/** |
| 11453 |
* Destroy the search box |
| 11454 |
*/ |
| 11455 |
SearchBox.prototype.destroy = function () { |
| 11456 |
this.editor = null; |
| 11457 |
this.dom.container.removeChild(this.dom.table); |
| 11458 |
this.dom = null; |
| 11459 |
|
| 11460 |
this.results = null; |
| 11461 |
this.activeResult = null; |
| 11462 |
|
| 11463 |
this._clearDelay(); |
| 11464 |
|
| 11465 |
}; |
| 11466 |
|
| 11467 |
module.exports = SearchBox; |
| 11468 |
|
| 11469 |
|
| 11470 |
/***/ }, |
| 11471 |
/* 57 */ |
| 11472 |
/***/ function(module, exports, __webpack_require__) { |
| 11473 |
|
| 11474 |
'use strict'; |
| 11475 |
|
| 11476 |
var util = __webpack_require__(54); |
| 11477 |
|
| 11478 |
/** |
| 11479 |
* A context menu |
| 11480 |
* @param {Object[]} items Array containing the menu structure |
| 11481 |
* TODO: describe structure |
| 11482 |
* @param {Object} [options] Object with options. Available options: |
| 11483 |
* {function} close Callback called when the |
| 11484 |
* context menu is being closed. |
| 11485 |
* @constructor |
| 11486 |
*/ |
| 11487 |
function ContextMenu (items, options) { |
| 11488 |
this.dom = {}; |
| 11489 |
|
| 11490 |
var me = this; |
| 11491 |
var dom = this.dom; |
| 11492 |
this.anchor = undefined; |
| 11493 |
this.items = items; |
| 11494 |
this.eventListeners = {}; |
| 11495 |
this.selection = undefined; // holds the selection before the menu was opened |
| 11496 |
this.onClose = options ? options.close : undefined; |
| 11497 |
|
| 11498 |
// create root element |
| 11499 |
var root = document.createElement('div'); |
| 11500 |
root.className = 'jsoneditor-contextmenu-root'; |
| 11501 |
dom.root = root; |
| 11502 |
|
| 11503 |
// create a container element |
| 11504 |
var menu = document.createElement('div'); |
| 11505 |
menu.className = 'jsoneditor-contextmenu'; |
| 11506 |
dom.menu = menu; |
| 11507 |
root.appendChild(menu); |
| 11508 |
|
| 11509 |
// create a list to hold the menu items |
| 11510 |
var list = document.createElement('ul'); |
| 11511 |
list.className = 'jsoneditor-menu'; |
| 11512 |
menu.appendChild(list); |
| 11513 |
dom.list = list; |
| 11514 |
dom.items = []; // list with all buttons |
| 11515 |
|
| 11516 |
// create a (non-visible) button to set the focus to the menu |
| 11517 |
var focusButton = document.createElement('button'); |
| 11518 |
focusButton.type = 'button'; |
| 11519 |
dom.focusButton = focusButton; |
| 11520 |
var li = document.createElement('li'); |
| 11521 |
li.style.overflow = 'hidden'; |
| 11522 |
li.style.height = '0'; |
| 11523 |
li.appendChild(focusButton); |
| 11524 |
list.appendChild(li); |
| 11525 |
|
| 11526 |
function createMenuItems (list, domItems, items) { |
| 11527 |
items.forEach(function (item) { |
| 11528 |
if (item.type == 'separator') { |
| 11529 |
// create a separator |
| 11530 |
var separator = document.createElement('div'); |
| 11531 |
separator.className = 'jsoneditor-separator'; |
| 11532 |
li = document.createElement('li'); |
| 11533 |
li.appendChild(separator); |
| 11534 |
list.appendChild(li); |
| 11535 |
} |
| 11536 |
else { |
| 11537 |
var domItem = {}; |
| 11538 |
|
| 11539 |
// create a menu item |
| 11540 |
var li = document.createElement('li'); |
| 11541 |
list.appendChild(li); |
| 11542 |
|
| 11543 |
// create a button in the menu item |
| 11544 |
var button = document.createElement('button'); |
| 11545 |
button.type = 'button'; |
| 11546 |
button.className = item.className; |
| 11547 |
domItem.button = button; |
| 11548 |
if (item.title) { |
| 11549 |
button.title = item.title; |
| 11550 |
} |
| 11551 |
if (item.click) { |
| 11552 |
button.onclick = function (event) { |
| 11553 |
event.preventDefault(); |
| 11554 |
me.hide(); |
| 11555 |
item.click(); |
| 11556 |
}; |
| 11557 |
} |
| 11558 |
li.appendChild(button); |
| 11559 |
|
| 11560 |
// create the contents of the button |
| 11561 |
if (item.submenu) { |
| 11562 |
// add the icon to the button |
| 11563 |
var divIcon = document.createElement('div'); |
| 11564 |
divIcon.className = 'jsoneditor-icon'; |
| 11565 |
button.appendChild(divIcon); |
| 11566 |
button.appendChild(document.createTextNode(item.text)); |
| 11567 |
|
| 11568 |
var buttonSubmenu; |
| 11569 |
if (item.click) { |
| 11570 |
// submenu and a button with a click handler |
| 11571 |
button.className += ' jsoneditor-default'; |
| 11572 |
|
| 11573 |
var buttonExpand = document.createElement('button'); |
| 11574 |
buttonExpand.type = 'button'; |
| 11575 |
domItem.buttonExpand = buttonExpand; |
| 11576 |
buttonExpand.className = 'jsoneditor-expand'; |
| 11577 |
buttonExpand.innerHTML = '<div class="jsoneditor-expand"></div>'; |
| 11578 |
li.appendChild(buttonExpand); |
| 11579 |
if (item.submenuTitle) { |
| 11580 |
buttonExpand.title = item.submenuTitle; |
| 11581 |
} |
| 11582 |
|
| 11583 |
buttonSubmenu = buttonExpand; |
| 11584 |
} |
| 11585 |
else { |
| 11586 |
// submenu and a button without a click handler |
| 11587 |
var divExpand = document.createElement('div'); |
| 11588 |
divExpand.className = 'jsoneditor-expand'; |
| 11589 |
button.appendChild(divExpand); |
| 11590 |
|
| 11591 |
buttonSubmenu = button; |
| 11592 |
} |
| 11593 |
|
| 11594 |
// attach a handler to expand/collapse the submenu |
| 11595 |
buttonSubmenu.onclick = function (event) { |
| 11596 |
event.preventDefault(); |
| 11597 |
me._onExpandItem(domItem); |
| 11598 |
buttonSubmenu.focus(); |
| 11599 |
}; |
| 11600 |
|
| 11601 |
// create the submenu |
| 11602 |
var domSubItems = []; |
| 11603 |
domItem.subItems = domSubItems; |
| 11604 |
var ul = document.createElement('ul'); |
| 11605 |
domItem.ul = ul; |
| 11606 |
ul.className = 'jsoneditor-menu'; |
| 11607 |
ul.style.height = '0'; |
| 11608 |
li.appendChild(ul); |
| 11609 |
createMenuItems(ul, domSubItems, item.submenu); |
| 11610 |
} |
| 11611 |
else { |
| 11612 |
// no submenu, just a button with clickhandler |
| 11613 |
button.innerHTML = '<div class="jsoneditor-icon"></div>' + item.text; |
| 11614 |
} |
| 11615 |
|
| 11616 |
domItems.push(domItem); |
| 11617 |
} |
| 11618 |
}); |
| 11619 |
} |
| 11620 |
createMenuItems(list, this.dom.items, items); |
| 11621 |
|
| 11622 |
// TODO: when the editor is small, show the submenu on the right instead of inline? |
| 11623 |
|
| 11624 |
// calculate the max height of the menu with one submenu expanded |
| 11625 |
this.maxHeight = 0; // height in pixels |
| 11626 |
items.forEach(function (item) { |
| 11627 |
var height = (items.length + (item.submenu ? item.submenu.length : 0)) * 24; |
| 11628 |
me.maxHeight = Math.max(me.maxHeight, height); |
| 11629 |
}); |
| 11630 |
} |
| 11631 |
|
| 11632 |
/** |
| 11633 |
* Get the currently visible buttons |
| 11634 |
* @return {Array.<HTMLElement>} buttons |
| 11635 |
* @private |
| 11636 |
*/ |
| 11637 |
ContextMenu.prototype._getVisibleButtons = function () { |
| 11638 |
var buttons = []; |
| 11639 |
var me = this; |
| 11640 |
this.dom.items.forEach(function (item) { |
| 11641 |
buttons.push(item.button); |
| 11642 |
if (item.buttonExpand) { |
| 11643 |
buttons.push(item.buttonExpand); |
| 11644 |
} |
| 11645 |
if (item.subItems && item == me.expandedItem) { |
| 11646 |
item.subItems.forEach(function (subItem) { |
| 11647 |
buttons.push(subItem.button); |
| 11648 |
if (subItem.buttonExpand) { |
| 11649 |
buttons.push(subItem.buttonExpand); |
| 11650 |
} |
| 11651 |
// TODO: change to fully recursive method |
| 11652 |
}); |
| 11653 |
} |
| 11654 |
}); |
| 11655 |
|
| 11656 |
return buttons; |
| 11657 |
}; |
| 11658 |
|
| 11659 |
// currently displayed context menu, a singleton. We may only have one visible context menu |
| 11660 |
ContextMenu.visibleMenu = undefined; |
| 11661 |
|
| 11662 |
/** |
| 11663 |
* Attach the menu to an anchor |
| 11664 |
* @param {HTMLElement} anchor Anchor where the menu will be attached |
| 11665 |
* as sibling. |
| 11666 |
* @param {HTMLElement} [contentWindow] The DIV with with the (scrollable) contents |
| 11667 |
*/ |
| 11668 |
ContextMenu.prototype.show = function (anchor, contentWindow) { |
| 11669 |
this.hide(); |
| 11670 |
|
| 11671 |
// determine whether to display the menu below or above the anchor |
| 11672 |
var showBelow = true; |
| 11673 |
if (contentWindow) { |
| 11674 |
var anchorRect = anchor.getBoundingClientRect(); |
| 11675 |
var contentRect = contentWindow.getBoundingClientRect(); |
| 11676 |
|
| 11677 |
if (anchorRect.bottom + this.maxHeight < contentRect.bottom) { |
| 11678 |
// fits below -> show below |
| 11679 |
} |
| 11680 |
else if (anchorRect.top - this.maxHeight > contentRect.top) { |
| 11681 |
// fits above -> show above |
| 11682 |
showBelow = false; |
| 11683 |
} |
| 11684 |
else { |
| 11685 |
// doesn't fit above nor below -> show below |
| 11686 |
} |
| 11687 |
} |
| 11688 |
|
| 11689 |
// position the menu |
| 11690 |
if (showBelow) { |
| 11691 |
// display the menu below the anchor |
| 11692 |
var anchorHeight = anchor.offsetHeight; |
| 11693 |
this.dom.menu.style.left = '0px'; |
| 11694 |
this.dom.menu.style.top = anchorHeight + 'px'; |
| 11695 |
this.dom.menu.style.bottom = ''; |
| 11696 |
} |
| 11697 |
else { |
| 11698 |
// display the menu above the anchor |
| 11699 |
this.dom.menu.style.left = '0px'; |
| 11700 |
this.dom.menu.style.top = ''; |
| 11701 |
this.dom.menu.style.bottom = '0px'; |
| 11702 |
} |
| 11703 |
|
| 11704 |
// attach the menu to the parent of the anchor |
| 11705 |
var parent = anchor.parentNode; |
| 11706 |
parent.insertBefore(this.dom.root, parent.firstChild); |
| 11707 |
|
| 11708 |
// create and attach event listeners |
| 11709 |
var me = this; |
| 11710 |
var list = this.dom.list; |
| 11711 |
this.eventListeners.mousedown = util.addEventListener(window, 'mousedown', function (event) { |
| 11712 |
// hide menu on click outside of the menu |
| 11713 |
var target = event.target; |
| 11714 |
if ((target != list) && !me._isChildOf(target, list)) { |
| 11715 |
me.hide(); |
| 11716 |
event.stopPropagation(); |
| 11717 |
event.preventDefault(); |
| 11718 |
} |
| 11719 |
}); |
| 11720 |
this.eventListeners.keydown = util.addEventListener(window, 'keydown', function (event) { |
| 11721 |
me._onKeyDown(event); |
| 11722 |
}); |
| 11723 |
|
| 11724 |
// move focus to the first button in the context menu |
| 11725 |
this.selection = util.getSelection(); |
| 11726 |
this.anchor = anchor; |
| 11727 |
setTimeout(function () { |
| 11728 |
me.dom.focusButton.focus(); |
| 11729 |
}, 0); |
| 11730 |
|
| 11731 |
if (ContextMenu.visibleMenu) { |
| 11732 |
ContextMenu.visibleMenu.hide(); |
| 11733 |
} |
| 11734 |
ContextMenu.visibleMenu = this; |
| 11735 |
}; |
| 11736 |
|
| 11737 |
/** |
| 11738 |
* Hide the context menu if visible |
| 11739 |
*/ |
| 11740 |
ContextMenu.prototype.hide = function () { |
| 11741 |
// remove the menu from the DOM |
| 11742 |
if (this.dom.root.parentNode) { |
| 11743 |
this.dom.root.parentNode.removeChild(this.dom.root); |
| 11744 |
if (this.onClose) { |
| 11745 |
this.onClose(); |
| 11746 |
} |
| 11747 |
} |
| 11748 |
|
| 11749 |
// remove all event listeners |
| 11750 |
// all event listeners are supposed to be attached to document. |
| 11751 |
for (var name in this.eventListeners) { |
| 11752 |
if (this.eventListeners.hasOwnProperty(name)) { |
| 11753 |
var fn = this.eventListeners[name]; |
| 11754 |
if (fn) { |
| 11755 |
util.removeEventListener(window, name, fn); |
| 11756 |
} |
| 11757 |
delete this.eventListeners[name]; |
| 11758 |
} |
| 11759 |
} |
| 11760 |
|
| 11761 |
if (ContextMenu.visibleMenu == this) { |
| 11762 |
ContextMenu.visibleMenu = undefined; |
| 11763 |
} |
| 11764 |
}; |
| 11765 |
|
| 11766 |
/** |
| 11767 |
* Expand a submenu |
| 11768 |
* Any currently expanded submenu will be hided. |
| 11769 |
* @param {Object} domItem |
| 11770 |
* @private |
| 11771 |
*/ |
| 11772 |
ContextMenu.prototype._onExpandItem = function (domItem) { |
| 11773 |
var me = this; |
| 11774 |
var alreadyVisible = (domItem == this.expandedItem); |
| 11775 |
|
| 11776 |
// hide the currently visible submenu |
| 11777 |
var expandedItem = this.expandedItem; |
| 11778 |
if (expandedItem) { |
| 11779 |
//var ul = expandedItem.ul; |
| 11780 |
expandedItem.ul.style.height = '0'; |
| 11781 |
expandedItem.ul.style.padding = ''; |
| 11782 |
setTimeout(function () { |
| 11783 |
if (me.expandedItem != expandedItem) { |
| 11784 |
expandedItem.ul.style.display = ''; |
| 11785 |
util.removeClassName(expandedItem.ul.parentNode, 'jsoneditor-selected'); |
| 11786 |
} |
| 11787 |
}, 300); // timeout duration must match the css transition duration |
| 11788 |
this.expandedItem = undefined; |
| 11789 |
} |
| 11790 |
|
| 11791 |
if (!alreadyVisible) { |
| 11792 |
var ul = domItem.ul; |
| 11793 |
ul.style.display = 'block'; |
| 11794 |
var height = ul.clientHeight; // force a reflow in Firefox |
| 11795 |
setTimeout(function () { |
| 11796 |
if (me.expandedItem == domItem) { |
| 11797 |
ul.style.height = (ul.childNodes.length * 24) + 'px'; |
| 11798 |
ul.style.padding = '5px 10px'; |
| 11799 |
} |
| 11800 |
}, 0); |
| 11801 |
util.addClassName(ul.parentNode, 'jsoneditor-selected'); |
| 11802 |
this.expandedItem = domItem; |
| 11803 |
} |
| 11804 |
}; |
| 11805 |
|
| 11806 |
/** |
| 11807 |
* Handle onkeydown event |
| 11808 |
* @param {Event} event |
| 11809 |
* @private |
| 11810 |
*/ |
| 11811 |
ContextMenu.prototype._onKeyDown = function (event) { |
| 11812 |
var target = event.target; |
| 11813 |
var keynum = event.which; |
| 11814 |
var handled = false; |
| 11815 |
var buttons, targetIndex, prevButton, nextButton; |
| 11816 |
|
| 11817 |
if (keynum == 27) { // ESC |
| 11818 |
// hide the menu on ESC key |
| 11819 |
|
| 11820 |
// restore previous selection and focus |
| 11821 |
if (this.selection) { |
| 11822 |
util.setSelection(this.selection); |
| 11823 |
} |
| 11824 |
if (this.anchor) { |
| 11825 |
this.anchor.focus(); |
| 11826 |
} |
| 11827 |
|
| 11828 |
this.hide(); |
| 11829 |
|
| 11830 |
handled = true; |
| 11831 |
} |
| 11832 |
else if (keynum == 9) { // Tab |
| 11833 |
if (!event.shiftKey) { // Tab |
| 11834 |
buttons = this._getVisibleButtons(); |
| 11835 |
targetIndex = buttons.indexOf(target); |
| 11836 |
if (targetIndex == buttons.length - 1) { |
| 11837 |
// move to first button |
| 11838 |
buttons[0].focus(); |
| 11839 |
handled = true; |
| 11840 |
} |
| 11841 |
} |
| 11842 |
else { // Shift+Tab |
| 11843 |
buttons = this._getVisibleButtons(); |
| 11844 |
targetIndex = buttons.indexOf(target); |
| 11845 |
if (targetIndex == 0) { |
| 11846 |
// move to last button |
| 11847 |
buttons[buttons.length - 1].focus(); |
| 11848 |
handled = true; |
| 11849 |
} |
| 11850 |
} |
| 11851 |
} |
| 11852 |
else if (keynum == 37) { // Arrow Left |
| 11853 |
if (target.className == 'jsoneditor-expand') { |
| 11854 |
buttons = this._getVisibleButtons(); |
| 11855 |
targetIndex = buttons.indexOf(target); |
| 11856 |
prevButton = buttons[targetIndex - 1]; |
| 11857 |
if (prevButton) { |
| 11858 |
prevButton.focus(); |
| 11859 |
} |
| 11860 |
} |
| 11861 |
handled = true; |
| 11862 |
} |
| 11863 |
else if (keynum == 38) { // Arrow Up |
| 11864 |
buttons = this._getVisibleButtons(); |
| 11865 |
targetIndex = buttons.indexOf(target); |
| 11866 |
prevButton = buttons[targetIndex - 1]; |
| 11867 |
if (prevButton && prevButton.className == 'jsoneditor-expand') { |
| 11868 |
// skip expand button |
| 11869 |
prevButton = buttons[targetIndex - 2]; |
| 11870 |
} |
| 11871 |
if (!prevButton) { |
| 11872 |
// move to last button |
| 11873 |
prevButton = buttons[buttons.length - 1]; |
| 11874 |
} |
| 11875 |
if (prevButton) { |
| 11876 |
prevButton.focus(); |
| 11877 |
} |
| 11878 |
handled = true; |
| 11879 |
} |
| 11880 |
else if (keynum == 39) { // Arrow Right |
| 11881 |
buttons = this._getVisibleButtons(); |
| 11882 |
targetIndex = buttons.indexOf(target); |
| 11883 |
nextButton = buttons[targetIndex + 1]; |
| 11884 |
if (nextButton && nextButton.className == 'jsoneditor-expand') { |
| 11885 |
nextButton.focus(); |
| 11886 |
} |
| 11887 |
handled = true; |
| 11888 |
} |
| 11889 |
else if (keynum == 40) { // Arrow Down |
| 11890 |
buttons = this._getVisibleButtons(); |
| 11891 |
targetIndex = buttons.indexOf(target); |
| 11892 |
nextButton = buttons[targetIndex + 1]; |
| 11893 |
if (nextButton && nextButton.className == 'jsoneditor-expand') { |
| 11894 |
// skip expand button |
| 11895 |
nextButton = buttons[targetIndex + 2]; |
| 11896 |
} |
| 11897 |
if (!nextButton) { |
| 11898 |
// move to first button |
| 11899 |
nextButton = buttons[0]; |
| 11900 |
} |
| 11901 |
if (nextButton) { |
| 11902 |
nextButton.focus(); |
| 11903 |
handled = true; |
| 11904 |
} |
| 11905 |
handled = true; |
| 11906 |
} |
| 11907 |
// TODO: arrow left and right |
| 11908 |
|
| 11909 |
if (handled) { |
| 11910 |
event.stopPropagation(); |
| 11911 |
event.preventDefault(); |
| 11912 |
} |
| 11913 |
}; |
| 11914 |
|
| 11915 |
/** |
| 11916 |
* Test if an element is a child of a parent element. |
| 11917 |
* @param {Element} child |
| 11918 |
* @param {Element} parent |
| 11919 |
* @return {boolean} isChild |
| 11920 |
*/ |
| 11921 |
ContextMenu.prototype._isChildOf = function (child, parent) { |
| 11922 |
var e = child.parentNode; |
| 11923 |
while (e) { |
| 11924 |
if (e == parent) { |
| 11925 |
return true; |
| 11926 |
} |
| 11927 |
e = e.parentNode; |
| 11928 |
} |
| 11929 |
|
| 11930 |
return false; |
| 11931 |
}; |
| 11932 |
|
| 11933 |
module.exports = ContextMenu; |
| 11934 |
|
| 11935 |
|
| 11936 |
/***/ }, |
| 11937 |
/* 58 */ |
| 11938 |
/***/ function(module, exports, __webpack_require__) { |
| 11939 |
|
| 11940 |
'use strict'; |
| 11941 |
|
| 11942 |
var naturalSort = __webpack_require__(59); |
| 11943 |
var ContextMenu = __webpack_require__(57); |
| 11944 |
var appendNodeFactory = __webpack_require__(60); |
| 11945 |
var util = __webpack_require__(54); |
| 11946 |
|
| 11947 |
/** |
| 11948 |
* @constructor Node |
| 11949 |
* Create a new Node |
| 11950 |
* @param {./treemode} editor |
| 11951 |
* @param {Object} [params] Can contain parameters: |
| 11952 |
* {string} field |
| 11953 |
* {boolean} fieldEditable |
| 11954 |
* {*} value |
| 11955 |
* {String} type Can have values 'auto', 'array', |
| 11956 |
* 'object', or 'string'. |
| 11957 |
*/ |
| 11958 |
function Node (editor, params) { |
| 11959 |
/** @type {./treemode} */ |
| 11960 |
this.editor = editor; |
| 11961 |
this.dom = {}; |
| 11962 |
this.expanded = false; |
| 11963 |
|
| 11964 |
if(params && (params instanceof Object)) { |
| 11965 |
this.setField(params.field, params.fieldEditable); |
| 11966 |
this.setValue(params.value, params.type); |
| 11967 |
} |
| 11968 |
else { |
| 11969 |
this.setField(''); |
| 11970 |
this.setValue(null); |
| 11971 |
} |
| 11972 |
|
| 11973 |
this._debouncedOnChangeValue = util.debounce(this._onChangeValue.bind(this), Node.prototype.DEBOUNCE_INTERVAL); |
| 11974 |
this._debouncedOnChangeField = util.debounce(this._onChangeField.bind(this), Node.prototype.DEBOUNCE_INTERVAL); |
| 11975 |
} |
| 11976 |
|
| 11977 |
// debounce interval for keyboard input in milliseconds |
| 11978 |
Node.prototype.DEBOUNCE_INTERVAL = 150; |
| 11979 |
|
| 11980 |
/** |
| 11981 |
* Determine whether the field and/or value of this node are editable |
| 11982 |
* @private |
| 11983 |
*/ |
| 11984 |
Node.prototype._updateEditability = function () { |
| 11985 |
this.editable = { |
| 11986 |
field: true, |
| 11987 |
value: true |
| 11988 |
}; |
| 11989 |
|
| 11990 |
if (this.editor) { |
| 11991 |
this.editable.field = this.editor.options.mode === 'tree'; |
| 11992 |
this.editable.value = this.editor.options.mode !== 'view'; |
| 11993 |
|
| 11994 |
if ((this.editor.options.mode === 'tree' || this.editor.options.mode === 'form') && |
| 11995 |
(typeof this.editor.options.onEditable === 'function')) { |
| 11996 |
var editable = this.editor.options.onEditable({ |
| 11997 |
field: this.field, |
| 11998 |
value: this.value, |
| 11999 |
path: this.getPath() |
| 12000 |
}); |
| 12001 |
|
| 12002 |
if (typeof editable === 'boolean') { |
| 12003 |
this.editable.field = editable; |
| 12004 |
this.editable.value = editable; |
| 12005 |
} |
| 12006 |
else { |
| 12007 |
if (typeof editable.field === 'boolean') this.editable.field = editable.field; |
| 12008 |
if (typeof editable.value === 'boolean') this.editable.value = editable.value; |
| 12009 |
} |
| 12010 |
} |
| 12011 |
} |
| 12012 |
}; |
| 12013 |
|
| 12014 |
/** |
| 12015 |
* Get the path of this node |
| 12016 |
* @return {String[]} Array containing the path to this node |
| 12017 |
*/ |
| 12018 |
Node.prototype.getPath = function () { |
| 12019 |
var node = this; |
| 12020 |
var path = []; |
| 12021 |
while (node) { |
| 12022 |
var field = !node.parent |
| 12023 |
? undefined // do not add an (optional) field name of the root node |
| 12024 |
: (node.parent.type != 'array') |
| 12025 |
? node.field |
| 12026 |
: node.index; |
| 12027 |
|
| 12028 |
if (field !== undefined) { |
| 12029 |
path.unshift(field); |
| 12030 |
} |
| 12031 |
node = node.parent; |
| 12032 |
} |
| 12033 |
return path; |
| 12034 |
}; |
| 12035 |
|
| 12036 |
/** |
| 12037 |
* Find a Node from a JSON path like '.items[3].name' |
| 12038 |
* @param {string} jsonPath |
| 12039 |
* @return {Node | null} Returns the Node when found, returns null if not found |
| 12040 |
*/ |
| 12041 |
Node.prototype.findNode = function (jsonPath) { |
| 12042 |
var path = util.parsePath(jsonPath); |
| 12043 |
var node = this; |
| 12044 |
while (node && path.length > 0) { |
| 12045 |
var prop = path.shift(); |
| 12046 |
if (typeof prop === 'number') { |
| 12047 |
if (node.type !== 'array') { |
| 12048 |
throw new Error('Cannot get child node at index ' + prop + ': node is no array'); |
| 12049 |
} |
| 12050 |
node = node.childs[prop]; |
| 12051 |
} |
| 12052 |
else { // string |
| 12053 |
if (node.type !== 'object') { |
| 12054 |
throw new Error('Cannot get child node ' + prop + ': node is no object'); |
| 12055 |
} |
| 12056 |
node = node.childs.filter(function (child) { |
| 12057 |
return child.field === prop; |
| 12058 |
})[0]; |
| 12059 |
} |
| 12060 |
} |
| 12061 |
|
| 12062 |
return node; |
| 12063 |
}; |
| 12064 |
|
| 12065 |
/** |
| 12066 |
* Find all parents of this node. The parents are ordered from root node towards |
| 12067 |
* the original node. |
| 12068 |
* @return {Array.<Node>} |
| 12069 |
*/ |
| 12070 |
Node.prototype.findParents = function () { |
| 12071 |
var parents = []; |
| 12072 |
var parent = this.parent; |
| 12073 |
while (parent) { |
| 12074 |
parents.unshift(parent); |
| 12075 |
parent = parent.parent; |
| 12076 |
} |
| 12077 |
return parents; |
| 12078 |
}; |
| 12079 |
|
| 12080 |
/** |
| 12081 |
* |
| 12082 |
* @param {{dataPath: string, keyword: string, message: string, params: Object, schemaPath: string} | null} error |
| 12083 |
* @param {Node} [child] When this is the error of a parent node, pointing |
| 12084 |
* to an invalid child node, the child node itself |
| 12085 |
* can be provided. If provided, clicking the error |
| 12086 |
* icon will set focus to the invalid child node. |
| 12087 |
*/ |
| 12088 |
Node.prototype.setError = function (error, child) { |
| 12089 |
// ensure the dom exists |
| 12090 |
this.getDom(); |
| 12091 |
|
| 12092 |
this.error = error; |
| 12093 |
var tdError = this.dom.tdError; |
| 12094 |
if (error) { |
| 12095 |
if (!tdError) { |
| 12096 |
tdError = document.createElement('td'); |
| 12097 |
this.dom.tdError = tdError; |
| 12098 |
this.dom.tdValue.parentNode.appendChild(tdError); |
| 12099 |
} |
| 12100 |
|
| 12101 |
var popover = document.createElement('div'); |
| 12102 |
popover.className = 'jsoneditor-popover jsoneditor-right'; |
| 12103 |
popover.appendChild(document.createTextNode(error.message)); |
| 12104 |
|
| 12105 |
var button = document.createElement('button'); |
| 12106 |
button.type = 'button'; |
| 12107 |
button.className = 'jsoneditor-schema-error'; |
| 12108 |
button.appendChild(popover); |
| 12109 |
|
| 12110 |
// update the direction of the popover |
| 12111 |
button.onmouseover = button.onfocus = function updateDirection() { |
| 12112 |
var directions = ['right', 'above', 'below', 'left']; |
| 12113 |
for (var i = 0; i < directions.length; i++) { |
| 12114 |
var direction = directions[i]; |
| 12115 |
popover.className = 'jsoneditor-popover jsoneditor-' + direction; |
| 12116 |
|
| 12117 |
var contentRect = this.editor.content.getBoundingClientRect(); |
| 12118 |
var popoverRect = popover.getBoundingClientRect(); |
| 12119 |
var margin = 20; // account for a scroll bar |
| 12120 |
var fit = util.insideRect(contentRect, popoverRect, margin); |
| 12121 |
|
| 12122 |
if (fit) { |
| 12123 |
break; |
| 12124 |
} |
| 12125 |
} |
| 12126 |
}.bind(this); |
| 12127 |
|
| 12128 |
// when clicking the error icon, expand all nodes towards the invalid |
| 12129 |
// child node, and set focus to the child node |
| 12130 |
if (child) { |
| 12131 |
button.onclick = function showInvalidNode() { |
| 12132 |
child.findParents().forEach(function (parent) { |
| 12133 |
parent.expand(false); |
| 12134 |
}); |
| 12135 |
|
| 12136 |
child.scrollTo(function () { |
| 12137 |
child.focus(); |
| 12138 |
}); |
| 12139 |
}; |
| 12140 |
} |
| 12141 |
|
| 12142 |
// apply the error message to the node |
| 12143 |
while (tdError.firstChild) { |
| 12144 |
tdError.removeChild(tdError.firstChild); |
| 12145 |
} |
| 12146 |
tdError.appendChild(button); |
| 12147 |
} |
| 12148 |
else { |
| 12149 |
if (tdError) { |
| 12150 |
this.dom.tdError.parentNode.removeChild(this.dom.tdError); |
| 12151 |
delete this.dom.tdError; |
| 12152 |
} |
| 12153 |
} |
| 12154 |
}; |
| 12155 |
|
| 12156 |
/** |
| 12157 |
* Get the index of this node: the index in the list of childs where this |
| 12158 |
* node is part of |
| 12159 |
* @return {number} Returns the index, or -1 if this is the root node |
| 12160 |
*/ |
| 12161 |
Node.prototype.getIndex = function () { |
| 12162 |
return this.parent ? this.parent.childs.indexOf(this) : -1; |
| 12163 |
}; |
| 12164 |
|
| 12165 |
/** |
| 12166 |
* Set parent node |
| 12167 |
* @param {Node} parent |
| 12168 |
*/ |
| 12169 |
Node.prototype.setParent = function(parent) { |
| 12170 |
this.parent = parent; |
| 12171 |
}; |
| 12172 |
|
| 12173 |
/** |
| 12174 |
* Set field |
| 12175 |
* @param {String} field |
| 12176 |
* @param {boolean} [fieldEditable] |
| 12177 |
*/ |
| 12178 |
Node.prototype.setField = function(field, fieldEditable) { |
| 12179 |
this.field = field; |
| 12180 |
this.previousField = field; |
| 12181 |
this.fieldEditable = (fieldEditable === true); |
| 12182 |
}; |
| 12183 |
|
| 12184 |
/** |
| 12185 |
* Get field |
| 12186 |
* @return {String} |
| 12187 |
*/ |
| 12188 |
Node.prototype.getField = function() { |
| 12189 |
if (this.field === undefined) { |
| 12190 |
this._getDomField(); |
| 12191 |
} |
| 12192 |
|
| 12193 |
return this.field; |
| 12194 |
}; |
| 12195 |
|
| 12196 |
/** |
| 12197 |
* Set value. Value is a JSON structure or an element String, Boolean, etc. |
| 12198 |
* @param {*} value |
| 12199 |
* @param {String} [type] Specify the type of the value. Can be 'auto', |
| 12200 |
* 'array', 'object', or 'string' |
| 12201 |
*/ |
| 12202 |
Node.prototype.setValue = function(value, type) { |
| 12203 |
var childValue, child; |
| 12204 |
|
| 12205 |
// first clear all current childs (if any) |
| 12206 |
var childs = this.childs; |
| 12207 |
if (childs) { |
| 12208 |
while (childs.length) { |
| 12209 |
this.removeChild(childs[0]); |
| 12210 |
} |
| 12211 |
} |
| 12212 |
|
| 12213 |
// TODO: remove the DOM of this Node |
| 12214 |
|
| 12215 |
this.type = this._getType(value); |
| 12216 |
|
| 12217 |
// check if type corresponds with the provided type |
| 12218 |
if (type && type != this.type) { |
| 12219 |
if (type == 'string' && this.type == 'auto') { |
| 12220 |
this.type = type; |
| 12221 |
} |
| 12222 |
else { |
| 12223 |
throw new Error('Type mismatch: ' + |
| 12224 |
'cannot cast value of type "' + this.type + |
| 12225 |
' to the specified type "' + type + '"'); |
| 12226 |
} |
| 12227 |
} |
| 12228 |
|
| 12229 |
if (this.type == 'array') { |
| 12230 |
// array |
| 12231 |
this.childs = []; |
| 12232 |
for (var i = 0, iMax = value.length; i < iMax; i++) { |
| 12233 |
childValue = value[i]; |
| 12234 |
if (childValue !== undefined && !(childValue instanceof Function)) { |
| 12235 |
// ignore undefined and functions |
| 12236 |
child = new Node(this.editor, { |
| 12237 |
value: childValue |
| 12238 |
}); |
| 12239 |
this.appendChild(child); |
| 12240 |
} |
| 12241 |
} |
| 12242 |
this.value = ''; |
| 12243 |
} |
| 12244 |
else if (this.type == 'object') { |
| 12245 |
// object |
| 12246 |
this.childs = []; |
| 12247 |
for (var childField in value) { |
| 12248 |
if (value.hasOwnProperty(childField)) { |
| 12249 |
childValue = value[childField]; |
| 12250 |
if (childValue !== undefined && !(childValue instanceof Function)) { |
| 12251 |
// ignore undefined and functions |
| 12252 |
child = new Node(this.editor, { |
| 12253 |
field: childField, |
| 12254 |
value: childValue |
| 12255 |
}); |
| 12256 |
this.appendChild(child); |
| 12257 |
} |
| 12258 |
} |
| 12259 |
} |
| 12260 |
this.value = ''; |
| 12261 |
|
| 12262 |
// sort object keys |
| 12263 |
if (this.editor.options.sortObjectKeys === true) { |
| 12264 |
this.sort('asc'); |
| 12265 |
} |
| 12266 |
} |
| 12267 |
else { |
| 12268 |
// value |
| 12269 |
this.childs = undefined; |
| 12270 |
this.value = value; |
| 12271 |
} |
| 12272 |
|
| 12273 |
this.previousValue = this.value; |
| 12274 |
}; |
| 12275 |
|
| 12276 |
/** |
| 12277 |
* Get value. Value is a JSON structure |
| 12278 |
* @return {*} value |
| 12279 |
*/ |
| 12280 |
Node.prototype.getValue = function() { |
| 12281 |
//var childs, i, iMax; |
| 12282 |
|
| 12283 |
if (this.type == 'array') { |
| 12284 |
var arr = []; |
| 12285 |
this.childs.forEach (function (child) { |
| 12286 |
arr.push(child.getValue()); |
| 12287 |
}); |
| 12288 |
return arr; |
| 12289 |
} |
| 12290 |
else if (this.type == 'object') { |
| 12291 |
var obj = {}; |
| 12292 |
this.childs.forEach (function (child) { |
| 12293 |
obj[child.getField()] = child.getValue(); |
| 12294 |
}); |
| 12295 |
return obj; |
| 12296 |
} |
| 12297 |
else { |
| 12298 |
if (this.value === undefined) { |
| 12299 |
this._getDomValue(); |
| 12300 |
} |
| 12301 |
|
| 12302 |
return this.value; |
| 12303 |
} |
| 12304 |
}; |
| 12305 |
|
| 12306 |
/** |
| 12307 |
* Get the nesting level of this node |
| 12308 |
* @return {Number} level |
| 12309 |
*/ |
| 12310 |
Node.prototype.getLevel = function() { |
| 12311 |
return (this.parent ? this.parent.getLevel() + 1 : 0); |
| 12312 |
}; |
| 12313 |
|
| 12314 |
/** |
| 12315 |
* Get path of the root node till the current node |
| 12316 |
* @return {Node[]} Returns an array with nodes |
| 12317 |
*/ |
| 12318 |
Node.prototype.getNodePath = function() { |
| 12319 |
var path = this.parent ? this.parent.getNodePath() : []; |
| 12320 |
path.push(this); |
| 12321 |
return path; |
| 12322 |
}; |
| 12323 |
|
| 12324 |
/** |
| 12325 |
* Create a clone of a node |
| 12326 |
* The complete state of a clone is copied, including whether it is expanded or |
| 12327 |
* not. The DOM elements are not cloned. |
| 12328 |
* @return {Node} clone |
| 12329 |
*/ |
| 12330 |
Node.prototype.clone = function() { |
| 12331 |
var clone = new Node(this.editor); |
| 12332 |
clone.type = this.type; |
| 12333 |
clone.field = this.field; |
| 12334 |
clone.fieldInnerText = this.fieldInnerText; |
| 12335 |
clone.fieldEditable = this.fieldEditable; |
| 12336 |
clone.value = this.value; |
| 12337 |
clone.valueInnerText = this.valueInnerText; |
| 12338 |
clone.expanded = this.expanded; |
| 12339 |
|
| 12340 |
if (this.childs) { |
| 12341 |
// an object or array |
| 12342 |
var cloneChilds = []; |
| 12343 |
this.childs.forEach(function (child) { |
| 12344 |
var childClone = child.clone(); |
| 12345 |
childClone.setParent(clone); |
| 12346 |
cloneChilds.push(childClone); |
| 12347 |
}); |
| 12348 |
clone.childs = cloneChilds; |
| 12349 |
} |
| 12350 |
else { |
| 12351 |
// a value |
| 12352 |
clone.childs = undefined; |
| 12353 |
} |
| 12354 |
|
| 12355 |
return clone; |
| 12356 |
}; |
| 12357 |
|
| 12358 |
/** |
| 12359 |
* Expand this node and optionally its childs. |
| 12360 |
* @param {boolean} [recurse] Optional recursion, true by default. When |
| 12361 |
* true, all childs will be expanded recursively |
| 12362 |
*/ |
| 12363 |
Node.prototype.expand = function(recurse) { |
| 12364 |
if (!this.childs) { |
| 12365 |
return; |
| 12366 |
} |
| 12367 |
|
| 12368 |
// set this node expanded |
| 12369 |
this.expanded = true; |
| 12370 |
if (this.dom.expand) { |
| 12371 |
this.dom.expand.className = 'jsoneditor-expanded'; |
| 12372 |
} |
| 12373 |
|
| 12374 |
this.showChilds(); |
| 12375 |
|
| 12376 |
if (recurse !== false) { |
| 12377 |
this.childs.forEach(function (child) { |
| 12378 |
child.expand(recurse); |
| 12379 |
}); |
| 12380 |
} |
| 12381 |
}; |
| 12382 |
|
| 12383 |
/** |
| 12384 |
* Collapse this node and optionally its childs. |
| 12385 |
* @param {boolean} [recurse] Optional recursion, true by default. When |
| 12386 |
* true, all childs will be collapsed recursively |
| 12387 |
*/ |
| 12388 |
Node.prototype.collapse = function(recurse) { |
| 12389 |
if (!this.childs) { |
| 12390 |
return; |
| 12391 |
} |
| 12392 |
|
| 12393 |
this.hideChilds(); |
| 12394 |
|
| 12395 |
// collapse childs in case of recurse |
| 12396 |
if (recurse !== false) { |
| 12397 |
this.childs.forEach(function (child) { |
| 12398 |
child.collapse(recurse); |
| 12399 |
}); |
| 12400 |
|
| 12401 |
} |
| 12402 |
|
| 12403 |
// make this node collapsed |
| 12404 |
if (this.dom.expand) { |
| 12405 |
this.dom.expand.className = 'jsoneditor-collapsed'; |
| 12406 |
} |
| 12407 |
this.expanded = false; |
| 12408 |
}; |
| 12409 |
|
| 12410 |
/** |
| 12411 |
* Recursively show all childs when they are expanded |
| 12412 |
*/ |
| 12413 |
Node.prototype.showChilds = function() { |
| 12414 |
var childs = this.childs; |
| 12415 |
if (!childs) { |
| 12416 |
return; |
| 12417 |
} |
| 12418 |
if (!this.expanded) { |
| 12419 |
return; |
| 12420 |
} |
| 12421 |
|
| 12422 |
var tr = this.dom.tr; |
| 12423 |
var table = tr ? tr.parentNode : undefined; |
| 12424 |
if (table) { |
| 12425 |
// show row with append button |
| 12426 |
var append = this.getAppend(); |
| 12427 |
var nextTr = tr.nextSibling; |
| 12428 |
if (nextTr) { |
| 12429 |
table.insertBefore(append, nextTr); |
| 12430 |
} |
| 12431 |
else { |
| 12432 |
table.appendChild(append); |
| 12433 |
} |
| 12434 |
|
| 12435 |
// show childs |
| 12436 |
this.childs.forEach(function (child) { |
| 12437 |
table.insertBefore(child.getDom(), append); |
| 12438 |
child.showChilds(); |
| 12439 |
}); |
| 12440 |
} |
| 12441 |
}; |
| 12442 |
|
| 12443 |
/** |
| 12444 |
* Hide the node with all its childs |
| 12445 |
*/ |
| 12446 |
Node.prototype.hide = function() { |
| 12447 |
var tr = this.dom.tr; |
| 12448 |
var table = tr ? tr.parentNode : undefined; |
| 12449 |
if (table) { |
| 12450 |
table.removeChild(tr); |
| 12451 |
} |
| 12452 |
this.hideChilds(); |
| 12453 |
}; |
| 12454 |
|
| 12455 |
|
| 12456 |
/** |
| 12457 |
* Recursively hide all childs |
| 12458 |
*/ |
| 12459 |
Node.prototype.hideChilds = function() { |
| 12460 |
var childs = this.childs; |
| 12461 |
if (!childs) { |
| 12462 |
return; |
| 12463 |
} |
| 12464 |
if (!this.expanded) { |
| 12465 |
return; |
| 12466 |
} |
| 12467 |
|
| 12468 |
// hide append row |
| 12469 |
var append = this.getAppend(); |
| 12470 |
if (append.parentNode) { |
| 12471 |
append.parentNode.removeChild(append); |
| 12472 |
} |
| 12473 |
|
| 12474 |
// hide childs |
| 12475 |
this.childs.forEach(function (child) { |
| 12476 |
child.hide(); |
| 12477 |
}); |
| 12478 |
}; |
| 12479 |
|
| 12480 |
|
| 12481 |
/** |
| 12482 |
* Add a new child to the node. |
| 12483 |
* Only applicable when Node value is of type array or object |
| 12484 |
* @param {Node} node |
| 12485 |
*/ |
| 12486 |
Node.prototype.appendChild = function(node) { |
| 12487 |
if (this._hasChilds()) { |
| 12488 |
// adjust the link to the parent |
| 12489 |
node.setParent(this); |
| 12490 |
node.fieldEditable = (this.type == 'object'); |
| 12491 |
if (this.type == 'array') { |
| 12492 |
node.index = this.childs.length; |
| 12493 |
} |
| 12494 |
this.childs.push(node); |
| 12495 |
|
| 12496 |
if (this.expanded) { |
| 12497 |
// insert into the DOM, before the appendRow |
| 12498 |
var newTr = node.getDom(); |
| 12499 |
var appendTr = this.getAppend(); |
| 12500 |
var table = appendTr ? appendTr.parentNode : undefined; |
| 12501 |
if (appendTr && table) { |
| 12502 |
table.insertBefore(newTr, appendTr); |
| 12503 |
} |
| 12504 |
|
| 12505 |
node.showChilds(); |
| 12506 |
} |
| 12507 |
|
| 12508 |
this.updateDom({'updateIndexes': true}); |
| 12509 |
node.updateDom({'recurse': true}); |
| 12510 |
} |
| 12511 |
}; |
| 12512 |
|
| 12513 |
|
| 12514 |
/** |
| 12515 |
* Move a node from its current parent to this node |
| 12516 |
* Only applicable when Node value is of type array or object |
| 12517 |
* @param {Node} node |
| 12518 |
* @param {Node} beforeNode |
| 12519 |
*/ |
| 12520 |
Node.prototype.moveBefore = function(node, beforeNode) { |
| 12521 |
if (this._hasChilds()) { |
| 12522 |
// create a temporary row, to prevent the scroll position from jumping |
| 12523 |
// when removing the node |
| 12524 |
var tbody = (this.dom.tr) ? this.dom.tr.parentNode : undefined; |
| 12525 |
if (tbody) { |
| 12526 |
var trTemp = document.createElement('tr'); |
| 12527 |
trTemp.style.height = tbody.clientHeight + 'px'; |
| 12528 |
tbody.appendChild(trTemp); |
| 12529 |
} |
| 12530 |
|
| 12531 |
if (node.parent) { |
| 12532 |
node.parent.removeChild(node); |
| 12533 |
} |
| 12534 |
|
| 12535 |
if (beforeNode instanceof AppendNode) { |
| 12536 |
this.appendChild(node); |
| 12537 |
} |
| 12538 |
else { |
| 12539 |
this.insertBefore(node, beforeNode); |
| 12540 |
} |
| 12541 |
|
| 12542 |
if (tbody) { |
| 12543 |
tbody.removeChild(trTemp); |
| 12544 |
} |
| 12545 |
} |
| 12546 |
}; |
| 12547 |
|
| 12548 |
/** |
| 12549 |
* Move a node from its current parent to this node |
| 12550 |
* Only applicable when Node value is of type array or object. |
| 12551 |
* If index is out of range, the node will be appended to the end |
| 12552 |
* @param {Node} node |
| 12553 |
* @param {Number} index |
| 12554 |
*/ |
| 12555 |
Node.prototype.moveTo = function (node, index) { |
| 12556 |
if (node.parent == this) { |
| 12557 |
// same parent |
| 12558 |
var currentIndex = this.childs.indexOf(node); |
| 12559 |
if (currentIndex < index) { |
| 12560 |
// compensate the index for removal of the node itself |
| 12561 |
index++; |
| 12562 |
} |
| 12563 |
} |
| 12564 |
|
| 12565 |
var beforeNode = this.childs[index] || this.append; |
| 12566 |
this.moveBefore(node, beforeNode); |
| 12567 |
}; |
| 12568 |
|
| 12569 |
/** |
| 12570 |
* Insert a new child before a given node |
| 12571 |
* Only applicable when Node value is of type array or object |
| 12572 |
* @param {Node} node |
| 12573 |
* @param {Node} beforeNode |
| 12574 |
*/ |
| 12575 |
Node.prototype.insertBefore = function(node, beforeNode) { |
| 12576 |
if (this._hasChilds()) { |
| 12577 |
if (beforeNode == this.append) { |
| 12578 |
// append to the child nodes |
| 12579 |
|
| 12580 |
// adjust the link to the parent |
| 12581 |
node.setParent(this); |
| 12582 |
node.fieldEditable = (this.type == 'object'); |
| 12583 |
this.childs.push(node); |
| 12584 |
} |
| 12585 |
else { |
| 12586 |
// insert before a child node |
| 12587 |
var index = this.childs.indexOf(beforeNode); |
| 12588 |
if (index == -1) { |
| 12589 |
throw new Error('Node not found'); |
| 12590 |
} |
| 12591 |
|
| 12592 |
// adjust the link to the parent |
| 12593 |
node.setParent(this); |
| 12594 |
node.fieldEditable = (this.type == 'object'); |
| 12595 |
this.childs.splice(index, 0, node); |
| 12596 |
} |
| 12597 |
|
| 12598 |
if (this.expanded) { |
| 12599 |
// insert into the DOM |
| 12600 |
var newTr = node.getDom(); |
| 12601 |
var nextTr = beforeNode.getDom(); |
| 12602 |
var table = nextTr ? nextTr.parentNode : undefined; |
| 12603 |
if (nextTr && table) { |
| 12604 |
table.insertBefore(newTr, nextTr); |
| 12605 |
} |
| 12606 |
|
| 12607 |
node.showChilds(); |
| 12608 |
} |
| 12609 |
|
| 12610 |
this.updateDom({'updateIndexes': true}); |
| 12611 |
node.updateDom({'recurse': true}); |
| 12612 |
} |
| 12613 |
}; |
| 12614 |
|
| 12615 |
/** |
| 12616 |
* Insert a new child before a given node |
| 12617 |
* Only applicable when Node value is of type array or object |
| 12618 |
* @param {Node} node |
| 12619 |
* @param {Node} afterNode |
| 12620 |
*/ |
| 12621 |
Node.prototype.insertAfter = function(node, afterNode) { |
| 12622 |
if (this._hasChilds()) { |
| 12623 |
var index = this.childs.indexOf(afterNode); |
| 12624 |
var beforeNode = this.childs[index + 1]; |
| 12625 |
if (beforeNode) { |
| 12626 |
this.insertBefore(node, beforeNode); |
| 12627 |
} |
| 12628 |
else { |
| 12629 |
this.appendChild(node); |
| 12630 |
} |
| 12631 |
} |
| 12632 |
}; |
| 12633 |
|
| 12634 |
/** |
| 12635 |
* Search in this node |
| 12636 |
* The node will be expanded when the text is found one of its childs, else |
| 12637 |
* it will be collapsed. Searches are case insensitive. |
| 12638 |
* @param {String} text |
| 12639 |
* @return {Node[]} results Array with nodes containing the search text |
| 12640 |
*/ |
| 12641 |
Node.prototype.search = function(text) { |
| 12642 |
var results = []; |
| 12643 |
var index; |
| 12644 |
var search = text ? text.toLowerCase() : undefined; |
| 12645 |
|
| 12646 |
// delete old search data |
| 12647 |
delete this.searchField; |
| 12648 |
delete this.searchValue; |
| 12649 |
|
| 12650 |
// search in field |
| 12651 |
if (this.field != undefined) { |
| 12652 |
var field = String(this.field).toLowerCase(); |
| 12653 |
index = field.indexOf(search); |
| 12654 |
if (index != -1) { |
| 12655 |
this.searchField = true; |
| 12656 |
results.push({ |
| 12657 |
'node': this, |
| 12658 |
'elem': 'field' |
| 12659 |
}); |
| 12660 |
} |
| 12661 |
|
| 12662 |
// update dom |
| 12663 |
this._updateDomField(); |
| 12664 |
} |
| 12665 |
|
| 12666 |
// search in value |
| 12667 |
if (this._hasChilds()) { |
| 12668 |
// array, object |
| 12669 |
|
| 12670 |
// search the nodes childs |
| 12671 |
if (this.childs) { |
| 12672 |
var childResults = []; |
| 12673 |
this.childs.forEach(function (child) { |
| 12674 |
childResults = childResults.concat(child.search(text)); |
| 12675 |
}); |
| 12676 |
results = results.concat(childResults); |
| 12677 |
} |
| 12678 |
|
| 12679 |
// update dom |
| 12680 |
if (search != undefined) { |
| 12681 |
var recurse = false; |
| 12682 |
if (childResults.length == 0) { |
| 12683 |
this.collapse(recurse); |
| 12684 |
} |
| 12685 |
else { |
| 12686 |
this.expand(recurse); |
| 12687 |
} |
| 12688 |
} |
| 12689 |
} |
| 12690 |
else { |
| 12691 |
// string, auto |
| 12692 |
if (this.value != undefined ) { |
| 12693 |
var value = String(this.value).toLowerCase(); |
| 12694 |
index = value.indexOf(search); |
| 12695 |
if (index != -1) { |
| 12696 |
this.searchValue = true; |
| 12697 |
results.push({ |
| 12698 |
'node': this, |
| 12699 |
'elem': 'value' |
| 12700 |
}); |
| 12701 |
} |
| 12702 |
} |
| 12703 |
|
| 12704 |
// update dom |
| 12705 |
this._updateDomValue(); |
| 12706 |
} |
| 12707 |
|
| 12708 |
return results; |
| 12709 |
}; |
| 12710 |
|
| 12711 |
/** |
| 12712 |
* Move the scroll position such that this node is in the visible area. |
| 12713 |
* The node will not get the focus |
| 12714 |
* @param {function(boolean)} [callback] |
| 12715 |
*/ |
| 12716 |
Node.prototype.scrollTo = function(callback) { |
| 12717 |
if (!this.dom.tr || !this.dom.tr.parentNode) { |
| 12718 |
// if the node is not visible, expand its parents |
| 12719 |
var parent = this.parent; |
| 12720 |
var recurse = false; |
| 12721 |
while (parent) { |
| 12722 |
parent.expand(recurse); |
| 12723 |
parent = parent.parent; |
| 12724 |
} |
| 12725 |
} |
| 12726 |
|
| 12727 |
if (this.dom.tr && this.dom.tr.parentNode) { |
| 12728 |
this.editor.scrollTo(this.dom.tr.offsetTop, callback); |
| 12729 |
} |
| 12730 |
}; |
| 12731 |
|
| 12732 |
|
| 12733 |
// stores the element name currently having the focus |
| 12734 |
Node.focusElement = undefined; |
| 12735 |
|
| 12736 |
/** |
| 12737 |
* Set focus to this node |
| 12738 |
* @param {String} [elementName] The field name of the element to get the |
| 12739 |
* focus available values: 'drag', 'menu', |
| 12740 |
* 'expand', 'field', 'value' (default) |
| 12741 |
*/ |
| 12742 |
Node.prototype.focus = function(elementName) { |
| 12743 |
Node.focusElement = elementName; |
| 12744 |
|
| 12745 |
if (this.dom.tr && this.dom.tr.parentNode) { |
| 12746 |
var dom = this.dom; |
| 12747 |
|
| 12748 |
switch (elementName) { |
| 12749 |
case 'drag': |
| 12750 |
if (dom.drag) { |
| 12751 |
dom.drag.focus(); |
| 12752 |
} |
| 12753 |
else { |
| 12754 |
dom.menu.focus(); |
| 12755 |
} |
| 12756 |
break; |
| 12757 |
|
| 12758 |
case 'menu': |
| 12759 |
dom.menu.focus(); |
| 12760 |
break; |
| 12761 |
|
| 12762 |
case 'expand': |
| 12763 |
if (this._hasChilds()) { |
| 12764 |
dom.expand.focus(); |
| 12765 |
} |
| 12766 |
else if (dom.field && this.fieldEditable) { |
| 12767 |
dom.field.focus(); |
| 12768 |
util.selectContentEditable(dom.field); |
| 12769 |
} |
| 12770 |
else if (dom.value && !this._hasChilds()) { |
| 12771 |
dom.value.focus(); |
| 12772 |
util.selectContentEditable(dom.value); |
| 12773 |
} |
| 12774 |
else { |
| 12775 |
dom.menu.focus(); |
| 12776 |
} |
| 12777 |
break; |
| 12778 |
|
| 12779 |
case 'field': |
| 12780 |
if (dom.field && this.fieldEditable) { |
| 12781 |
dom.field.focus(); |
| 12782 |
util.selectContentEditable(dom.field); |
| 12783 |
} |
| 12784 |
else if (dom.value && !this._hasChilds()) { |
| 12785 |
dom.value.focus(); |
| 12786 |
util.selectContentEditable(dom.value); |
| 12787 |
} |
| 12788 |
else if (this._hasChilds()) { |
| 12789 |
dom.expand.focus(); |
| 12790 |
} |
| 12791 |
else { |
| 12792 |
dom.menu.focus(); |
| 12793 |
} |
| 12794 |
break; |
| 12795 |
|
| 12796 |
case 'value': |
| 12797 |
default: |
| 12798 |
if (dom.value && !this._hasChilds()) { |
| 12799 |
dom.value.focus(); |
| 12800 |
util.selectContentEditable(dom.value); |
| 12801 |
} |
| 12802 |
else if (dom.field && this.fieldEditable) { |
| 12803 |
dom.field.focus(); |
| 12804 |
util.selectContentEditable(dom.field); |
| 12805 |
} |
| 12806 |
else if (this._hasChilds()) { |
| 12807 |
dom.expand.focus(); |
| 12808 |
} |
| 12809 |
else { |
| 12810 |
dom.menu.focus(); |
| 12811 |
} |
| 12812 |
break; |
| 12813 |
} |
| 12814 |
} |
| 12815 |
}; |
| 12816 |
|
| 12817 |
/** |
| 12818 |
* Select all text in an editable div after a delay of 0 ms |
| 12819 |
* @param {Element} editableDiv |
| 12820 |
*/ |
| 12821 |
Node.select = function(editableDiv) { |
| 12822 |
setTimeout(function () { |
| 12823 |
util.selectContentEditable(editableDiv); |
| 12824 |
}, 0); |
| 12825 |
}; |
| 12826 |
|
| 12827 |
/** |
| 12828 |
* Update the values from the DOM field and value of this node |
| 12829 |
*/ |
| 12830 |
Node.prototype.blur = function() { |
| 12831 |
// retrieve the actual field and value from the DOM. |
| 12832 |
this._getDomValue(false); |
| 12833 |
this._getDomField(false); |
| 12834 |
}; |
| 12835 |
|
| 12836 |
/** |
| 12837 |
* Check if given node is a child. The method will check recursively to find |
| 12838 |
* this node. |
| 12839 |
* @param {Node} node |
| 12840 |
* @return {boolean} containsNode |
| 12841 |
*/ |
| 12842 |
Node.prototype.containsNode = function(node) { |
| 12843 |
if (this == node) { |
| 12844 |
return true; |
| 12845 |
} |
| 12846 |
|
| 12847 |
var childs = this.childs; |
| 12848 |
if (childs) { |
| 12849 |
// TODO: use the js5 Array.some() here? |
| 12850 |
for (var i = 0, iMax = childs.length; i < iMax; i++) { |
| 12851 |
if (childs[i].containsNode(node)) { |
| 12852 |
return true; |
| 12853 |
} |
| 12854 |
} |
| 12855 |
} |
| 12856 |
|
| 12857 |
return false; |
| 12858 |
}; |
| 12859 |
|
| 12860 |
/** |
| 12861 |
* Move given node into this node |
| 12862 |
* @param {Node} node the childNode to be moved |
| 12863 |
* @param {Node} beforeNode node will be inserted before given |
| 12864 |
* node. If no beforeNode is given, |
| 12865 |
* the node is appended at the end |
| 12866 |
* @private |
| 12867 |
*/ |
| 12868 |
Node.prototype._move = function(node, beforeNode) { |
| 12869 |
if (node == beforeNode) { |
| 12870 |
// nothing to do... |
| 12871 |
return; |
| 12872 |
} |
| 12873 |
|
| 12874 |
// check if this node is not a child of the node to be moved here |
| 12875 |
if (node.containsNode(this)) { |
| 12876 |
throw new Error('Cannot move a field into a child of itself'); |
| 12877 |
} |
| 12878 |
|
| 12879 |
// remove the original node |
| 12880 |
if (node.parent) { |
| 12881 |
node.parent.removeChild(node); |
| 12882 |
} |
| 12883 |
|
| 12884 |
// create a clone of the node |
| 12885 |
var clone = node.clone(); |
| 12886 |
node.clearDom(); |
| 12887 |
|
| 12888 |
// insert or append the node |
| 12889 |
if (beforeNode) { |
| 12890 |
this.insertBefore(clone, beforeNode); |
| 12891 |
} |
| 12892 |
else { |
| 12893 |
this.appendChild(clone); |
| 12894 |
} |
| 12895 |
|
| 12896 |
/* TODO: adjust the field name (to prevent equal field names) |
| 12897 |
if (this.type == 'object') { |
| 12898 |
} |
| 12899 |
*/ |
| 12900 |
}; |
| 12901 |
|
| 12902 |
/** |
| 12903 |
* Remove a child from the node. |
| 12904 |
* Only applicable when Node value is of type array or object |
| 12905 |
* @param {Node} node The child node to be removed; |
| 12906 |
* @return {Node | undefined} node The removed node on success, |
| 12907 |
* else undefined |
| 12908 |
*/ |
| 12909 |
Node.prototype.removeChild = function(node) { |
| 12910 |
if (this.childs) { |
| 12911 |
var index = this.childs.indexOf(node); |
| 12912 |
|
| 12913 |
if (index != -1) { |
| 12914 |
node.hide(); |
| 12915 |
|
| 12916 |
// delete old search results |
| 12917 |
delete node.searchField; |
| 12918 |
delete node.searchValue; |
| 12919 |
|
| 12920 |
var removedNode = this.childs.splice(index, 1)[0]; |
| 12921 |
removedNode.parent = null; |
| 12922 |
|
| 12923 |
this.updateDom({'updateIndexes': true}); |
| 12924 |
|
| 12925 |
return removedNode; |
| 12926 |
} |
| 12927 |
} |
| 12928 |
|
| 12929 |
return undefined; |
| 12930 |
}; |
| 12931 |
|
| 12932 |
/** |
| 12933 |
* Remove a child node node from this node |
| 12934 |
* This method is equal to Node.removeChild, except that _remove fire an |
| 12935 |
* onChange event. |
| 12936 |
* @param {Node} node |
| 12937 |
* @private |
| 12938 |
*/ |
| 12939 |
Node.prototype._remove = function (node) { |
| 12940 |
this.removeChild(node); |
| 12941 |
}; |
| 12942 |
|
| 12943 |
/** |
| 12944 |
* Change the type of the value of this Node |
| 12945 |
* @param {String} newType |
| 12946 |
*/ |
| 12947 |
Node.prototype.changeType = function (newType) { |
| 12948 |
var oldType = this.type; |
| 12949 |
|
| 12950 |
if (oldType == newType) { |
| 12951 |
// type is not changed |
| 12952 |
return; |
| 12953 |
} |
| 12954 |
|
| 12955 |
if ((newType == 'string' || newType == 'auto') && |
| 12956 |
(oldType == 'string' || oldType == 'auto')) { |
| 12957 |
// this is an easy change |
| 12958 |
this.type = newType; |
| 12959 |
} |
| 12960 |
else { |
| 12961 |
// change from array to object, or from string/auto to object/array |
| 12962 |
var table = this.dom.tr ? this.dom.tr.parentNode : undefined; |
| 12963 |
var lastTr; |
| 12964 |
if (this.expanded) { |
| 12965 |
lastTr = this.getAppend(); |
| 12966 |
} |
| 12967 |
else { |
| 12968 |
lastTr = this.getDom(); |
| 12969 |
} |
| 12970 |
var nextTr = (lastTr && lastTr.parentNode) ? lastTr.nextSibling : undefined; |
| 12971 |
|
| 12972 |
// hide current field and all its childs |
| 12973 |
this.hide(); |
| 12974 |
this.clearDom(); |
| 12975 |
|
| 12976 |
// adjust the field and the value |
| 12977 |
this.type = newType; |
| 12978 |
|
| 12979 |
// adjust childs |
| 12980 |
if (newType == 'object') { |
| 12981 |
if (!this.childs) { |
| 12982 |
this.childs = []; |
| 12983 |
} |
| 12984 |
|
| 12985 |
this.childs.forEach(function (child, index) { |
| 12986 |
child.clearDom(); |
| 12987 |
delete child.index; |
| 12988 |
child.fieldEditable = true; |
| 12989 |
if (child.field == undefined) { |
| 12990 |
child.field = ''; |
| 12991 |
} |
| 12992 |
}); |
| 12993 |
|
| 12994 |
if (oldType == 'string' || oldType == 'auto') { |
| 12995 |
this.expanded = true; |
| 12996 |
} |
| 12997 |
} |
| 12998 |
else if (newType == 'array') { |
| 12999 |
if (!this.childs) { |
| 13000 |
this.childs = []; |
| 13001 |
} |
| 13002 |
|
| 13003 |
this.childs.forEach(function (child, index) { |
| 13004 |
child.clearDom(); |
| 13005 |
child.fieldEditable = false; |
| 13006 |
child.index = index; |
| 13007 |
}); |
| 13008 |
|
| 13009 |
if (oldType == 'string' || oldType == 'auto') { |
| 13010 |
this.expanded = true; |
| 13011 |
} |
| 13012 |
} |
| 13013 |
else { |
| 13014 |
this.expanded = false; |
| 13015 |
} |
| 13016 |
|
| 13017 |
// create new DOM |
| 13018 |
if (table) { |
| 13019 |
if (nextTr) { |
| 13020 |
table.insertBefore(this.getDom(), nextTr); |
| 13021 |
} |
| 13022 |
else { |
| 13023 |
table.appendChild(this.getDom()); |
| 13024 |
} |
| 13025 |
} |
| 13026 |
this.showChilds(); |
| 13027 |
} |
| 13028 |
|
| 13029 |
if (newType == 'auto' || newType == 'string') { |
| 13030 |
// cast value to the correct type |
| 13031 |
if (newType == 'string') { |
| 13032 |
this.value = String(this.value); |
| 13033 |
} |
| 13034 |
else { |
| 13035 |
this.value = this._stringCast(String(this.value)); |
| 13036 |
} |
| 13037 |
|
| 13038 |
this.focus(); |
| 13039 |
} |
| 13040 |
|
| 13041 |
this.updateDom({'updateIndexes': true}); |
| 13042 |
}; |
| 13043 |
|
| 13044 |
/** |
| 13045 |
* Retrieve value from DOM |
| 13046 |
* @param {boolean} [silent] If true (default), no errors will be thrown in |
| 13047 |
* case of invalid data |
| 13048 |
* @private |
| 13049 |
*/ |
| 13050 |
Node.prototype._getDomValue = function(silent) { |
| 13051 |
if (this.dom.value && this.type != 'array' && this.type != 'object') { |
| 13052 |
this.valueInnerText = util.getInnerText(this.dom.value); |
| 13053 |
} |
| 13054 |
|
| 13055 |
if (this.valueInnerText != undefined) { |
| 13056 |
try { |
| 13057 |
// retrieve the value |
| 13058 |
var value; |
| 13059 |
if (this.type == 'string') { |
| 13060 |
value = this._unescapeHTML(this.valueInnerText); |
| 13061 |
} |
| 13062 |
else { |
| 13063 |
var str = this._unescapeHTML(this.valueInnerText); |
| 13064 |
value = this._stringCast(str); |
| 13065 |
} |
| 13066 |
if (value !== this.value) { |
| 13067 |
this.value = value; |
| 13068 |
this._debouncedOnChangeValue(); |
| 13069 |
} |
| 13070 |
} |
| 13071 |
catch (err) { |
| 13072 |
this.value = undefined; |
| 13073 |
// TODO: sent an action with the new, invalid value? |
| 13074 |
if (silent !== true) { |
| 13075 |
throw err; |
| 13076 |
} |
| 13077 |
} |
| 13078 |
} |
| 13079 |
}; |
| 13080 |
|
| 13081 |
/** |
| 13082 |
* Handle a changed value |
| 13083 |
* @private |
| 13084 |
*/ |
| 13085 |
Node.prototype._onChangeValue = function () { |
| 13086 |
// get current selection, then override the range such that we can select |
| 13087 |
// the added/removed text on undo/redo |
| 13088 |
var oldSelection = this.editor.getSelection(); |
| 13089 |
if (oldSelection.range) { |
| 13090 |
var undoDiff = util.textDiff(String(this.value), String(this.previousValue)); |
| 13091 |
oldSelection.range.startOffset = undoDiff.start; |
| 13092 |
oldSelection.range.endOffset = undoDiff.end; |
| 13093 |
} |
| 13094 |
var newSelection = this.editor.getSelection(); |
| 13095 |
if (newSelection.range) { |
| 13096 |
var redoDiff = util.textDiff(String(this.previousValue), String(this.value)); |
| 13097 |
newSelection.range.startOffset = redoDiff.start; |
| 13098 |
newSelection.range.endOffset = redoDiff.end; |
| 13099 |
} |
| 13100 |
|
| 13101 |
this.editor._onAction('editValue', { |
| 13102 |
node: this, |
| 13103 |
oldValue: this.previousValue, |
| 13104 |
newValue: this.value, |
| 13105 |
oldSelection: oldSelection, |
| 13106 |
newSelection: newSelection |
| 13107 |
}); |
| 13108 |
|
| 13109 |
this.previousValue = this.value; |
| 13110 |
}; |
| 13111 |
|
| 13112 |
/** |
| 13113 |
* Handle a changed field |
| 13114 |
* @private |
| 13115 |
*/ |
| 13116 |
Node.prototype._onChangeField = function () { |
| 13117 |
// get current selection, then override the range such that we can select |
| 13118 |
// the added/removed text on undo/redo |
| 13119 |
var oldSelection = this.editor.getSelection(); |
| 13120 |
if (oldSelection.range) { |
| 13121 |
var undoDiff = util.textDiff(this.field, this.previousField); |
| 13122 |
oldSelection.range.startOffset = undoDiff.start; |
| 13123 |
oldSelection.range.endOffset = undoDiff.end; |
| 13124 |
} |
| 13125 |
var newSelection = this.editor.getSelection(); |
| 13126 |
if (newSelection.range) { |
| 13127 |
var redoDiff = util.textDiff(this.previousField, this.field); |
| 13128 |
newSelection.range.startOffset = redoDiff.start; |
| 13129 |
newSelection.range.endOffset = redoDiff.end; |
| 13130 |
} |
| 13131 |
|
| 13132 |
this.editor._onAction('editField', { |
| 13133 |
node: this, |
| 13134 |
oldValue: this.previousField, |
| 13135 |
newValue: this.field, |
| 13136 |
oldSelection: oldSelection, |
| 13137 |
newSelection: newSelection |
| 13138 |
}); |
| 13139 |
|
| 13140 |
this.previousField = this.field; |
| 13141 |
}; |
| 13142 |
|
| 13143 |
/** |
| 13144 |
* Update dom value: |
| 13145 |
* - the text color of the value, depending on the type of the value |
| 13146 |
* - the height of the field, depending on the width |
| 13147 |
* - background color in case it is empty |
| 13148 |
* @private |
| 13149 |
*/ |
| 13150 |
Node.prototype._updateDomValue = function () { |
| 13151 |
var domValue = this.dom.value; |
| 13152 |
if (domValue) { |
| 13153 |
var classNames = ['jsoneditor-value']; |
| 13154 |
|
| 13155 |
|
| 13156 |
// set text color depending on value type |
| 13157 |
var value = this.value; |
| 13158 |
var type = (this.type == 'auto') ? util.type(value) : this.type; |
| 13159 |
var isUrl = type == 'string' && util.isUrl(value); |
| 13160 |
classNames.push('jsoneditor-' + type); |
| 13161 |
if (isUrl) { |
| 13162 |
classNames.push('jsoneditor-url'); |
| 13163 |
} |
| 13164 |
|
| 13165 |
// visual styling when empty |
| 13166 |
var isEmpty = (String(this.value) == '' && this.type != 'array' && this.type != 'object'); |
| 13167 |
if (isEmpty) { |
| 13168 |
classNames.push('jsoneditor-empty'); |
| 13169 |
} |
| 13170 |
|
| 13171 |
// highlight when there is a search result |
| 13172 |
if (this.searchValueActive) { |
| 13173 |
classNames.push('jsoneditor-highlight-active'); |
| 13174 |
} |
| 13175 |
if (this.searchValue) { |
| 13176 |
classNames.push('jsoneditor-highlight'); |
| 13177 |
} |
| 13178 |
|
| 13179 |
domValue.className = classNames.join(' '); |
| 13180 |
|
| 13181 |
// update title |
| 13182 |
if (type == 'array' || type == 'object') { |
| 13183 |
var count = this.childs ? this.childs.length : 0; |
| 13184 |
domValue.title = this.type + ' containing ' + count + ' items'; |
| 13185 |
} |
| 13186 |
else if (isUrl && this.editable.value) { |
| 13187 |
domValue.title = 'Ctrl+Click or Ctrl+Enter to open url in new window'; |
| 13188 |
} |
| 13189 |
else { |
| 13190 |
domValue.title = ''; |
| 13191 |
} |
| 13192 |
|
| 13193 |
// show checkbox when the value is a boolean |
| 13194 |
if (type === 'boolean' && this.editable.value) { |
| 13195 |
if (!this.dom.checkbox) { |
| 13196 |
this.dom.checkbox = document.createElement('input'); |
| 13197 |
this.dom.checkbox.type = 'checkbox'; |
| 13198 |
this.dom.tdCheckbox = document.createElement('td'); |
| 13199 |
this.dom.tdCheckbox.className = 'jsoneditor-tree'; |
| 13200 |
this.dom.tdCheckbox.appendChild(this.dom.checkbox); |
| 13201 |
|
| 13202 |
this.dom.tdValue.parentNode.insertBefore(this.dom.tdCheckbox, this.dom.tdValue); |
| 13203 |
} |
| 13204 |
|
| 13205 |
this.dom.checkbox.checked = this.value; |
| 13206 |
} |
| 13207 |
else { |
| 13208 |
// cleanup checkbox when displayed |
| 13209 |
if (this.dom.tdCheckbox) { |
| 13210 |
this.dom.tdCheckbox.parentNode.removeChild(this.dom.tdCheckbox); |
| 13211 |
delete this.dom.tdCheckbox; |
| 13212 |
delete this.dom.checkbox; |
| 13213 |
} |
| 13214 |
} |
| 13215 |
|
| 13216 |
if (this.enum && this.editable.value) { |
| 13217 |
// create select box when this node has an enum object |
| 13218 |
if (!this.dom.select) { |
| 13219 |
this.dom.select = document.createElement('select'); |
| 13220 |
this.id = this.field + "_" + new Date().getUTCMilliseconds(); |
| 13221 |
this.dom.select.id = this.id; |
| 13222 |
this.dom.select.name = this.dom.select.id; |
| 13223 |
|
| 13224 |
//Create the default empty option |
| 13225 |
this.dom.select.option = document.createElement('option'); |
| 13226 |
this.dom.select.option.value = ''; |
| 13227 |
this.dom.select.option.innerHTML = '--'; |
| 13228 |
this.dom.select.appendChild(this.dom.select.option); |
| 13229 |
|
| 13230 |
//Iterate all enum values and add them as options |
| 13231 |
for(var i = 0; i < this.enum.length; i++) { |
| 13232 |
this.dom.select.option = document.createElement('option'); |
| 13233 |
this.dom.select.option.value = this.enum[i]; |
| 13234 |
this.dom.select.option.innerHTML = this.enum[i]; |
| 13235 |
if(this.dom.select.option.value == this.value){ |
| 13236 |
this.dom.select.option.selected = true; |
| 13237 |
} |
| 13238 |
this.dom.select.appendChild(this.dom.select.option); |
| 13239 |
} |
| 13240 |
|
| 13241 |
this.dom.tdSelect = document.createElement('td'); |
| 13242 |
this.dom.tdSelect.className = 'jsoneditor-tree'; |
| 13243 |
this.dom.tdSelect.appendChild(this.dom.select); |
| 13244 |
this.dom.tdValue.parentNode.insertBefore(this.dom.tdSelect, this.dom.tdValue); |
| 13245 |
} |
| 13246 |
|
| 13247 |
// If the enum is inside a composite type display |
| 13248 |
// both the simple input and the dropdown field |
| 13249 |
if(this.schema && ( |
| 13250 |
!this.schema.hasOwnProperty("oneOf") && |
| 13251 |
!this.schema.hasOwnProperty("anyOf") && |
| 13252 |
!this.schema.hasOwnProperty("allOf")) |
| 13253 |
) { |
| 13254 |
this.valueFieldHTML = this.dom.tdValue.innerHTML; |
| 13255 |
this.dom.tdValue.style.visibility = 'hidden'; |
| 13256 |
this.dom.tdValue.innerHTML = ''; |
| 13257 |
} else { |
| 13258 |
delete this.valueFieldHTML; |
| 13259 |
} |
| 13260 |
} |
| 13261 |
else { |
| 13262 |
// cleanup select box when displayed |
| 13263 |
if (this.dom.tdSelect) { |
| 13264 |
this.dom.tdSelect.parentNode.removeChild(this.dom.tdSelect); |
| 13265 |
delete this.dom.tdSelect; |
| 13266 |
delete this.dom.select; |
| 13267 |
this.dom.tdValue.innerHTML = this.valueFieldHTML; |
| 13268 |
this.dom.tdValue.style.visibility = ''; |
| 13269 |
delete this.valueFieldHTML; |
| 13270 |
} |
| 13271 |
} |
| 13272 |
|
| 13273 |
// strip formatting from the contents of the editable div |
| 13274 |
util.stripFormatting(domValue); |
| 13275 |
} |
| 13276 |
}; |
| 13277 |
|
| 13278 |
/** |
| 13279 |
* Update dom field: |
| 13280 |
* - the text color of the field, depending on the text |
| 13281 |
* - the height of the field, depending on the width |
| 13282 |
* - background color in case it is empty |
| 13283 |
* @private |
| 13284 |
*/ |
| 13285 |
Node.prototype._updateDomField = function () { |
| 13286 |
var domField = this.dom.field; |
| 13287 |
if (domField) { |
| 13288 |
// make backgound color lightgray when empty |
| 13289 |
var isEmpty = (String(this.field) == '' && this.parent.type != 'array'); |
| 13290 |
if (isEmpty) { |
| 13291 |
util.addClassName(domField, 'jsoneditor-empty'); |
| 13292 |
} |
| 13293 |
else { |
| 13294 |
util.removeClassName(domField, 'jsoneditor-empty'); |
| 13295 |
} |
| 13296 |
|
| 13297 |
// highlight when there is a search result |
| 13298 |
if (this.searchFieldActive) { |
| 13299 |
util.addClassName(domField, 'jsoneditor-highlight-active'); |
| 13300 |
} |
| 13301 |
else { |
| 13302 |
util.removeClassName(domField, 'jsoneditor-highlight-active'); |
| 13303 |
} |
| 13304 |
if (this.searchField) { |
| 13305 |
util.addClassName(domField, 'jsoneditor-highlight'); |
| 13306 |
} |
| 13307 |
else { |
| 13308 |
util.removeClassName(domField, 'jsoneditor-highlight'); |
| 13309 |
} |
| 13310 |
|
| 13311 |
// strip formatting from the contents of the editable div |
| 13312 |
util.stripFormatting(domField); |
| 13313 |
} |
| 13314 |
}; |
| 13315 |
|
| 13316 |
/** |
| 13317 |
* Retrieve field from DOM |
| 13318 |
* @param {boolean} [silent] If true (default), no errors will be thrown in |
| 13319 |
* case of invalid data |
| 13320 |
* @private |
| 13321 |
*/ |
| 13322 |
Node.prototype._getDomField = function(silent) { |
| 13323 |
if (this.dom.field && this.fieldEditable) { |
| 13324 |
this.fieldInnerText = util.getInnerText(this.dom.field); |
| 13325 |
} |
| 13326 |
|
| 13327 |
if (this.fieldInnerText != undefined) { |
| 13328 |
try { |
| 13329 |
var field = this._unescapeHTML(this.fieldInnerText); |
| 13330 |
|
| 13331 |
if (field !== this.field) { |
| 13332 |
this.field = field; |
| 13333 |
this._debouncedOnChangeField(); |
| 13334 |
} |
| 13335 |
} |
| 13336 |
catch (err) { |
| 13337 |
this.field = undefined; |
| 13338 |
// TODO: sent an action here, with the new, invalid value? |
| 13339 |
if (silent !== true) { |
| 13340 |
throw err; |
| 13341 |
} |
| 13342 |
} |
| 13343 |
} |
| 13344 |
}; |
| 13345 |
|
| 13346 |
/** |
| 13347 |
* Validate this node and all it's childs |
| 13348 |
* @return {Array.<{node: Node, error: {message: string}}>} Returns a list with duplicates |
| 13349 |
*/ |
| 13350 |
Node.prototype.validate = function () { |
| 13351 |
var errors = []; |
| 13352 |
|
| 13353 |
// find duplicate keys |
| 13354 |
if (this.type === 'object') { |
| 13355 |
var keys = {}; |
| 13356 |
var duplicateKeys = []; |
| 13357 |
for (var i = 0; i < this.childs.length; i++) { |
| 13358 |
var child = this.childs[i]; |
| 13359 |
if (keys.hasOwnProperty(child.field)) { |
| 13360 |
duplicateKeys.push(child.field); |
| 13361 |
} |
| 13362 |
keys[child.field] = true; |
| 13363 |
} |
| 13364 |
|
| 13365 |
if (duplicateKeys.length > 0) { |
| 13366 |
errors = this.childs |
| 13367 |
.filter(function (node) { |
| 13368 |
return duplicateKeys.indexOf(node.field) !== -1; |
| 13369 |
}) |
| 13370 |
.map(function (node) { |
| 13371 |
return { |
| 13372 |
node: node, |
| 13373 |
error: { |
| 13374 |
message: 'duplicate key "' + node.field + '"' |
| 13375 |
} |
| 13376 |
} |
| 13377 |
}); |
| 13378 |
} |
| 13379 |
} |
| 13380 |
|
| 13381 |
// recurse over the childs |
| 13382 |
if (this.childs) { |
| 13383 |
for (var i = 0; i < this.childs.length; i++) { |
| 13384 |
var e = this.childs[i].validate(); |
| 13385 |
if (e.length > 0) { |
| 13386 |
errors = errors.concat(e); |
| 13387 |
} |
| 13388 |
} |
| 13389 |
} |
| 13390 |
|
| 13391 |
return errors; |
| 13392 |
}; |
| 13393 |
|
| 13394 |
/** |
| 13395 |
* Clear the dom of the node |
| 13396 |
*/ |
| 13397 |
Node.prototype.clearDom = function() { |
| 13398 |
// TODO: hide the node first? |
| 13399 |
//this.hide(); |
| 13400 |
// TODO: recursively clear dom? |
| 13401 |
|
| 13402 |
this.dom = {}; |
| 13403 |
}; |
| 13404 |
|
| 13405 |
/** |
| 13406 |
* Get the HTML DOM TR element of the node. |
| 13407 |
* The dom will be generated when not yet created |
| 13408 |
* @return {Element} tr HTML DOM TR Element |
| 13409 |
*/ |
| 13410 |
Node.prototype.getDom = function() { |
| 13411 |
var dom = this.dom; |
| 13412 |
if (dom.tr) { |
| 13413 |
return dom.tr; |
| 13414 |
} |
| 13415 |
|
| 13416 |
this._updateEditability(); |
| 13417 |
|
| 13418 |
// create row |
| 13419 |
dom.tr = document.createElement('tr'); |
| 13420 |
dom.tr.node = this; |
| 13421 |
|
| 13422 |
if (this.editor.options.mode === 'tree') { // note: we take here the global setting |
| 13423 |
var tdDrag = document.createElement('td'); |
| 13424 |
if (this.editable.field) { |
| 13425 |
// create draggable area |
| 13426 |
if (this.parent) { |
| 13427 |
var domDrag = document.createElement('button'); |
| 13428 |
domDrag.type = 'button'; |
| 13429 |
dom.drag = domDrag; |
| 13430 |
domDrag.className = 'jsoneditor-dragarea'; |
| 13431 |
domDrag.title = 'Drag to move this field (Alt+Shift+Arrows)'; |
| 13432 |
tdDrag.appendChild(domDrag); |
| 13433 |
} |
| 13434 |
} |
| 13435 |
dom.tr.appendChild(tdDrag); |
| 13436 |
|
| 13437 |
// create context menu |
| 13438 |
var tdMenu = document.createElement('td'); |
| 13439 |
var menu = document.createElement('button'); |
| 13440 |
menu.type = 'button'; |
| 13441 |
dom.menu = menu; |
| 13442 |
menu.className = 'jsoneditor-contextmenu'; |
| 13443 |
menu.title = 'Click to open the actions menu (Ctrl+M)'; |
| 13444 |
tdMenu.appendChild(dom.menu); |
| 13445 |
dom.tr.appendChild(tdMenu); |
| 13446 |
} |
| 13447 |
|
| 13448 |
// create tree and field |
| 13449 |
var tdField = document.createElement('td'); |
| 13450 |
dom.tr.appendChild(tdField); |
| 13451 |
dom.tree = this._createDomTree(); |
| 13452 |
tdField.appendChild(dom.tree); |
| 13453 |
|
| 13454 |
this.updateDom({'updateIndexes': true}); |
| 13455 |
|
| 13456 |
return dom.tr; |
| 13457 |
}; |
| 13458 |
|
| 13459 |
/** |
| 13460 |
* DragStart event, fired on mousedown on the dragarea at the left side of a Node |
| 13461 |
* @param {Node[] | Node} nodes |
| 13462 |
* @param {Event} event |
| 13463 |
*/ |
| 13464 |
Node.onDragStart = function (nodes, event) { |
| 13465 |
if (!Array.isArray(nodes)) { |
| 13466 |
return Node.onDragStart([nodes], event); |
| 13467 |
} |
| 13468 |
if (nodes.length === 0) { |
| 13469 |
return; |
| 13470 |
} |
| 13471 |
|
| 13472 |
var firstNode = nodes[0]; |
| 13473 |
var lastNode = nodes[nodes.length - 1]; |
| 13474 |
var draggedNode = Node.getNodeFromTarget(event.target); |
| 13475 |
var beforeNode = lastNode._nextSibling(); |
| 13476 |
var editor = firstNode.editor; |
| 13477 |
|
| 13478 |
// in case of multiple selected nodes, offsetY prevents the selection from |
| 13479 |
// jumping when you start dragging one of the lower down nodes in the selection |
| 13480 |
var offsetY = util.getAbsoluteTop(draggedNode.dom.tr) - util.getAbsoluteTop(firstNode.dom.tr); |
| 13481 |
|
| 13482 |
if (!editor.mousemove) { |
| 13483 |
editor.mousemove = util.addEventListener(window, 'mousemove', function (event) { |
| 13484 |
Node.onDrag(nodes, event); |
| 13485 |
}); |
| 13486 |
} |
| 13487 |
|
| 13488 |
if (!editor.mouseup) { |
| 13489 |
editor.mouseup = util.addEventListener(window, 'mouseup',function (event ) { |
| 13490 |
Node.onDragEnd(nodes, event); |
| 13491 |
}); |
| 13492 |
} |
| 13493 |
|
| 13494 |
editor.highlighter.lock(); |
| 13495 |
editor.drag = { |
| 13496 |
oldCursor: document.body.style.cursor, |
| 13497 |
oldSelection: editor.getSelection(), |
| 13498 |
oldBeforeNode: beforeNode, |
| 13499 |
mouseX: event.pageX, |
| 13500 |
offsetY: offsetY, |
| 13501 |
level: firstNode.getLevel() |
| 13502 |
}; |
| 13503 |
document.body.style.cursor = 'move'; |
| 13504 |
|
| 13505 |
event.preventDefault(); |
| 13506 |
}; |
| 13507 |
|
| 13508 |
/** |
| 13509 |
* Drag event, fired when moving the mouse while dragging a Node |
| 13510 |
* @param {Node[] | Node} nodes |
| 13511 |
* @param {Event} event |
| 13512 |
*/ |
| 13513 |
Node.onDrag = function (nodes, event) { |
| 13514 |
if (!Array.isArray(nodes)) { |
| 13515 |
return Node.onDrag([nodes], event); |
| 13516 |
} |
| 13517 |
if (nodes.length === 0) { |
| 13518 |
return; |
| 13519 |
} |
| 13520 |
|
| 13521 |
// TODO: this method has grown too large. Split it in a number of methods |
| 13522 |
var editor = nodes[0].editor; |
| 13523 |
var mouseY = event.pageY - editor.drag.offsetY; |
| 13524 |
var mouseX = event.pageX; |
| 13525 |
var trThis, trPrev, trNext, trFirst, trLast, trRoot; |
| 13526 |
var nodePrev, nodeNext; |
| 13527 |
var topThis, topPrev, topFirst, heightThis, bottomNext, heightNext; |
| 13528 |
var moved = false; |
| 13529 |
|
| 13530 |
// TODO: add an ESC option, which resets to the original position |
| 13531 |
|
| 13532 |
// move up/down |
| 13533 |
var firstNode = nodes[0]; |
| 13534 |
trThis = firstNode.dom.tr; |
| 13535 |
topThis = util.getAbsoluteTop(trThis); |
| 13536 |
heightThis = trThis.offsetHeight; |
| 13537 |
if (mouseY < topThis) { |
| 13538 |
// move up |
| 13539 |
trPrev = trThis; |
| 13540 |
do { |
| 13541 |
trPrev = trPrev.previousSibling; |
| 13542 |
nodePrev = Node.getNodeFromTarget(trPrev); |
| 13543 |
topPrev = trPrev ? util.getAbsoluteTop(trPrev) : 0; |
| 13544 |
} |
| 13545 |
while (trPrev && mouseY < topPrev); |
| 13546 |
|
| 13547 |
if (nodePrev && !nodePrev.parent) { |
| 13548 |
nodePrev = undefined; |
| 13549 |
} |
| 13550 |
|
| 13551 |
if (!nodePrev) { |
| 13552 |
// move to the first node |
| 13553 |
trRoot = trThis.parentNode.firstChild; |
| 13554 |
trPrev = trRoot ? trRoot.nextSibling : undefined; |
| 13555 |
nodePrev = Node.getNodeFromTarget(trPrev); |
| 13556 |
if (nodePrev == firstNode) { |
| 13557 |
nodePrev = undefined; |
| 13558 |
} |
| 13559 |
} |
| 13560 |
|
| 13561 |
if (nodePrev) { |
| 13562 |
// check if mouseY is really inside the found node |
| 13563 |
trPrev = nodePrev.dom.tr; |
| 13564 |
topPrev = trPrev ? util.getAbsoluteTop(trPrev) : 0; |
| 13565 |
if (mouseY > topPrev + heightThis) { |
| 13566 |
nodePrev = undefined; |
| 13567 |
} |
| 13568 |
} |
| 13569 |
|
| 13570 |
if (nodePrev) { |
| 13571 |
nodes.forEach(function (node) { |
| 13572 |
nodePrev.parent.moveBefore(node, nodePrev); |
| 13573 |
}); |
| 13574 |
moved = true; |
| 13575 |
} |
| 13576 |
} |
| 13577 |
else { |
| 13578 |
// move down |
| 13579 |
var lastNode = nodes[nodes.length - 1]; |
| 13580 |
trLast = (lastNode.expanded && lastNode.append) ? lastNode.append.getDom() : lastNode.dom.tr; |
| 13581 |
trFirst = trLast ? trLast.nextSibling : undefined; |
| 13582 |
if (trFirst) { |
| 13583 |
topFirst = util.getAbsoluteTop(trFirst); |
| 13584 |
trNext = trFirst; |
| 13585 |
do { |
| 13586 |
nodeNext = Node.getNodeFromTarget(trNext); |
| 13587 |
if (trNext) { |
| 13588 |
bottomNext = trNext.nextSibling ? |
| 13589 |
util.getAbsoluteTop(trNext.nextSibling) : 0; |
| 13590 |
heightNext = trNext ? (bottomNext - topFirst) : 0; |
| 13591 |
|
| 13592 |
if (nodeNext.parent.childs.length == nodes.length && |
| 13593 |
nodeNext.parent.childs[nodes.length - 1] == lastNode) { |
| 13594 |
// We are about to remove the last child of this parent, |
| 13595 |
// which will make the parents appendNode visible. |
| 13596 |
topThis += 27; |
| 13597 |
// TODO: dangerous to suppose the height of the appendNode a constant of 27 px. |
| 13598 |
} |
| 13599 |
} |
| 13600 |
|
| 13601 |
trNext = trNext.nextSibling; |
| 13602 |
} |
| 13603 |
while (trNext && mouseY > topThis + heightNext); |
| 13604 |
|
| 13605 |
if (nodeNext && nodeNext.parent) { |
| 13606 |
// calculate the desired level |
| 13607 |
var diffX = (mouseX - editor.drag.mouseX); |
| 13608 |
var diffLevel = Math.round(diffX / 24 / 2); |
| 13609 |
var level = editor.drag.level + diffLevel; // desired level |
| 13610 |
var levelNext = nodeNext.getLevel(); // level to be |
| 13611 |
|
| 13612 |
// find the best fitting level (move upwards over the append nodes) |
| 13613 |
trPrev = nodeNext.dom.tr.previousSibling; |
| 13614 |
while (levelNext < level && trPrev) { |
| 13615 |
nodePrev = Node.getNodeFromTarget(trPrev); |
| 13616 |
|
| 13617 |
var isDraggedNode = nodes.some(function (node) { |
| 13618 |
return node === nodePrev || nodePrev._isChildOf(node); |
| 13619 |
}); |
| 13620 |
|
| 13621 |
if (isDraggedNode) { |
| 13622 |
// neglect the dragged nodes themselves and their childs |
| 13623 |
} |
| 13624 |
else if (nodePrev instanceof AppendNode) { |
| 13625 |
var childs = nodePrev.parent.childs; |
| 13626 |
if (childs.length != nodes.length || childs[nodes.length - 1] != lastNode) { |
| 13627 |
// non-visible append node of a list of childs |
| 13628 |
// consisting of not only this node (else the |
| 13629 |
// append node will change into a visible "empty" |
| 13630 |
// text when removing this node). |
| 13631 |
nodeNext = Node.getNodeFromTarget(trPrev); |
| 13632 |
levelNext = nodeNext.getLevel(); |
| 13633 |
} |
| 13634 |
else { |
| 13635 |
break; |
| 13636 |
} |
| 13637 |
} |
| 13638 |
else { |
| 13639 |
break; |
| 13640 |
} |
| 13641 |
|
| 13642 |
trPrev = trPrev.previousSibling; |
| 13643 |
} |
| 13644 |
|
| 13645 |
// move the node when its position is changed |
| 13646 |
if (trLast.nextSibling != nodeNext.dom.tr) { |
| 13647 |
nodes.forEach(function (node) { |
| 13648 |
nodeNext.parent.moveBefore(node, nodeNext); |
| 13649 |
}); |
| 13650 |
moved = true; |
| 13651 |
} |
| 13652 |
} |
| 13653 |
} |
| 13654 |
} |
| 13655 |
|
| 13656 |
if (moved) { |
| 13657 |
// update the dragging parameters when moved |
| 13658 |
editor.drag.mouseX = mouseX; |
| 13659 |
editor.drag.level = firstNode.getLevel(); |
| 13660 |
} |
| 13661 |
|
| 13662 |
// auto scroll when hovering around the top of the editor |
| 13663 |
editor.startAutoScroll(mouseY); |
| 13664 |
|
| 13665 |
event.preventDefault(); |
| 13666 |
}; |
| 13667 |
|
| 13668 |
/** |
| 13669 |
* Drag event, fired on mouseup after having dragged a node |
| 13670 |
* @param {Node[] | Node} nodes |
| 13671 |
* @param {Event} event |
| 13672 |
*/ |
| 13673 |
Node.onDragEnd = function (nodes, event) { |
| 13674 |
if (!Array.isArray(nodes)) { |
| 13675 |
return Node.onDrag([nodes], event); |
| 13676 |
} |
| 13677 |
if (nodes.length === 0) { |
| 13678 |
return; |
| 13679 |
} |
| 13680 |
|
| 13681 |
var firstNode = nodes[0]; |
| 13682 |
var editor = firstNode.editor; |
| 13683 |
var parent = firstNode.parent; |
| 13684 |
var firstIndex = parent.childs.indexOf(firstNode); |
| 13685 |
var beforeNode = parent.childs[firstIndex + nodes.length] || parent.append; |
| 13686 |
|
| 13687 |
// set focus to the context menu button of the first node |
| 13688 |
if (nodes[0]) { |
| 13689 |
nodes[0].dom.menu.focus(); |
| 13690 |
} |
| 13691 |
|
| 13692 |
var params = { |
| 13693 |
nodes: nodes, |
| 13694 |
oldSelection: editor.drag.oldSelection, |
| 13695 |
newSelection: editor.getSelection(), |
| 13696 |
oldBeforeNode: editor.drag.oldBeforeNode, |
| 13697 |
newBeforeNode: beforeNode |
| 13698 |
}; |
| 13699 |
|
| 13700 |
if (params.oldBeforeNode != params.newBeforeNode) { |
| 13701 |
// only register this action if the node is actually moved to another place |
| 13702 |
editor._onAction('moveNodes', params); |
| 13703 |
} |
| 13704 |
|
| 13705 |
document.body.style.cursor = editor.drag.oldCursor; |
| 13706 |
editor.highlighter.unlock(); |
| 13707 |
nodes.forEach(function (node) { |
| 13708 |
if (event.target !== node.dom.drag && event.target !== node.dom.menu) { |
| 13709 |
editor.highlighter.unhighlight(); |
| 13710 |
} |
| 13711 |
}); |
| 13712 |
delete editor.drag; |
| 13713 |
|
| 13714 |
if (editor.mousemove) { |
| 13715 |
util.removeEventListener(window, 'mousemove', editor.mousemove); |
| 13716 |
delete editor.mousemove; |
| 13717 |
} |
| 13718 |
if (editor.mouseup) { |
| 13719 |
util.removeEventListener(window, 'mouseup', editor.mouseup); |
| 13720 |
delete editor.mouseup; |
| 13721 |
} |
| 13722 |
|
| 13723 |
// Stop any running auto scroll |
| 13724 |
editor.stopAutoScroll(); |
| 13725 |
|
| 13726 |
event.preventDefault(); |
| 13727 |
}; |
| 13728 |
|
| 13729 |
/** |
| 13730 |
* Test if this node is a child of an other node |
| 13731 |
* @param {Node} node |
| 13732 |
* @return {boolean} isChild |
| 13733 |
* @private |
| 13734 |
*/ |
| 13735 |
Node.prototype._isChildOf = function (node) { |
| 13736 |
var n = this.parent; |
| 13737 |
while (n) { |
| 13738 |
if (n == node) { |
| 13739 |
return true; |
| 13740 |
} |
| 13741 |
n = n.parent; |
| 13742 |
} |
| 13743 |
|
| 13744 |
return false; |
| 13745 |
}; |
| 13746 |
|
| 13747 |
/** |
| 13748 |
* Create an editable field |
| 13749 |
* @return {Element} domField |
| 13750 |
* @private |
| 13751 |
*/ |
| 13752 |
Node.prototype._createDomField = function () { |
| 13753 |
return document.createElement('div'); |
| 13754 |
}; |
| 13755 |
|
| 13756 |
/** |
| 13757 |
* Set highlighting for this node and all its childs. |
| 13758 |
* Only applied to the currently visible (expanded childs) |
| 13759 |
* @param {boolean} highlight |
| 13760 |
*/ |
| 13761 |
Node.prototype.setHighlight = function (highlight) { |
| 13762 |
if (this.dom.tr) { |
| 13763 |
if (highlight) { |
| 13764 |
util.addClassName(this.dom.tr, 'jsoneditor-highlight'); |
| 13765 |
} |
| 13766 |
else { |
| 13767 |
util.removeClassName(this.dom.tr, 'jsoneditor-highlight'); |
| 13768 |
} |
| 13769 |
|
| 13770 |
if (this.append) { |
| 13771 |
this.append.setHighlight(highlight); |
| 13772 |
} |
| 13773 |
|
| 13774 |
if (this.childs) { |
| 13775 |
this.childs.forEach(function (child) { |
| 13776 |
child.setHighlight(highlight); |
| 13777 |
}); |
| 13778 |
} |
| 13779 |
} |
| 13780 |
}; |
| 13781 |
|
| 13782 |
/** |
| 13783 |
* Select or deselect a node |
| 13784 |
* @param {boolean} selected |
| 13785 |
* @param {boolean} [isFirst] |
| 13786 |
*/ |
| 13787 |
Node.prototype.setSelected = function (selected, isFirst) { |
| 13788 |
this.selected = selected; |
| 13789 |
|
| 13790 |
if (this.dom.tr) { |
| 13791 |
if (selected) { |
| 13792 |
util.addClassName(this.dom.tr, 'jsoneditor-selected'); |
| 13793 |
} |
| 13794 |
else { |
| 13795 |
util.removeClassName(this.dom.tr, 'jsoneditor-selected'); |
| 13796 |
} |
| 13797 |
|
| 13798 |
if (isFirst) { |
| 13799 |
util.addClassName(this.dom.tr, 'jsoneditor-first'); |
| 13800 |
} |
| 13801 |
else { |
| 13802 |
util.removeClassName(this.dom.tr, 'jsoneditor-first'); |
| 13803 |
} |
| 13804 |
|
| 13805 |
if (this.append) { |
| 13806 |
this.append.setSelected(selected); |
| 13807 |
} |
| 13808 |
|
| 13809 |
if (this.childs) { |
| 13810 |
this.childs.forEach(function (child) { |
| 13811 |
child.setSelected(selected); |
| 13812 |
}); |
| 13813 |
} |
| 13814 |
} |
| 13815 |
}; |
| 13816 |
|
| 13817 |
/** |
| 13818 |
* Update the value of the node. Only primitive types are allowed, no Object |
| 13819 |
* or Array is allowed. |
| 13820 |
* @param {String | Number | Boolean | null} value |
| 13821 |
*/ |
| 13822 |
Node.prototype.updateValue = function (value) { |
| 13823 |
this.value = value; |
| 13824 |
this.updateDom(); |
| 13825 |
}; |
| 13826 |
|
| 13827 |
/** |
| 13828 |
* Update the field of the node. |
| 13829 |
* @param {String} field |
| 13830 |
*/ |
| 13831 |
Node.prototype.updateField = function (field) { |
| 13832 |
this.field = field; |
| 13833 |
this.updateDom(); |
| 13834 |
}; |
| 13835 |
|
| 13836 |
/** |
| 13837 |
* Update the HTML DOM, optionally recursing through the childs |
| 13838 |
* @param {Object} [options] Available parameters: |
| 13839 |
* {boolean} [recurse] If true, the |
| 13840 |
* DOM of the childs will be updated recursively. |
| 13841 |
* False by default. |
| 13842 |
* {boolean} [updateIndexes] If true, the childs |
| 13843 |
* indexes of the node will be updated too. False by |
| 13844 |
* default. |
| 13845 |
*/ |
| 13846 |
Node.prototype.updateDom = function (options) { |
| 13847 |
// update level indentation |
| 13848 |
var domTree = this.dom.tree; |
| 13849 |
if (domTree) { |
| 13850 |
domTree.style.marginLeft = this.getLevel() * 24 + 'px'; |
| 13851 |
} |
| 13852 |
|
| 13853 |
// apply field to DOM |
| 13854 |
var domField = this.dom.field; |
| 13855 |
if (domField) { |
| 13856 |
if (this.fieldEditable) { |
| 13857 |
// parent is an object |
| 13858 |
domField.contentEditable = this.editable.field; |
| 13859 |
domField.spellcheck = false; |
| 13860 |
domField.className = 'jsoneditor-field'; |
| 13861 |
} |
| 13862 |
else { |
| 13863 |
// parent is an array this is the root node |
| 13864 |
domField.className = 'jsoneditor-readonly'; |
| 13865 |
} |
| 13866 |
|
| 13867 |
var fieldText; |
| 13868 |
if (this.index != undefined) { |
| 13869 |
fieldText = this.index; |
| 13870 |
} |
| 13871 |
else if (this.field != undefined) { |
| 13872 |
fieldText = this.field; |
| 13873 |
} |
| 13874 |
else if (this._hasChilds()) { |
| 13875 |
fieldText = this.type; |
| 13876 |
} |
| 13877 |
else { |
| 13878 |
fieldText = ''; |
| 13879 |
} |
| 13880 |
domField.innerHTML = this._escapeHTML(fieldText); |
| 13881 |
|
| 13882 |
this._updateSchema(); |
| 13883 |
} |
| 13884 |
|
| 13885 |
// apply value to DOM |
| 13886 |
var domValue = this.dom.value; |
| 13887 |
if (domValue) { |
| 13888 |
var count = this.childs ? this.childs.length : 0; |
| 13889 |
if (this.type == 'array') { |
| 13890 |
domValue.innerHTML = '[' + count + ']'; |
| 13891 |
util.addClassName(this.dom.tr, 'jsoneditor-expandable'); |
| 13892 |
} |
| 13893 |
else if (this.type == 'object') { |
| 13894 |
domValue.innerHTML = '{' + count + '}'; |
| 13895 |
util.addClassName(this.dom.tr, 'jsoneditor-expandable'); |
| 13896 |
} |
| 13897 |
else { |
| 13898 |
domValue.innerHTML = this._escapeHTML(this.value); |
| 13899 |
util.removeClassName(this.dom.tr, 'jsoneditor-expandable'); |
| 13900 |
} |
| 13901 |
} |
| 13902 |
|
| 13903 |
// update field and value |
| 13904 |
this._updateDomField(); |
| 13905 |
this._updateDomValue(); |
| 13906 |
|
| 13907 |
// update childs indexes |
| 13908 |
if (options && options.updateIndexes === true) { |
| 13909 |
// updateIndexes is true or undefined |
| 13910 |
this._updateDomIndexes(); |
| 13911 |
} |
| 13912 |
|
| 13913 |
if (options && options.recurse === true) { |
| 13914 |
// recurse is true or undefined. update childs recursively |
| 13915 |
if (this.childs) { |
| 13916 |
this.childs.forEach(function (child) { |
| 13917 |
child.updateDom(options); |
| 13918 |
}); |
| 13919 |
} |
| 13920 |
} |
| 13921 |
|
| 13922 |
// update row with append button |
| 13923 |
if (this.append) { |
| 13924 |
this.append.updateDom(); |
| 13925 |
} |
| 13926 |
}; |
| 13927 |
|
| 13928 |
/** |
| 13929 |
* Locate the JSON schema of the node and check for any enum type |
| 13930 |
* @private |
| 13931 |
*/ |
| 13932 |
Node.prototype._updateSchema = function () { |
| 13933 |
//Locating the schema of the node and checking for any enum type |
| 13934 |
if(this.editor && this.editor.options) { |
| 13935 |
// find the part of the json schema matching this nodes path |
| 13936 |
this.schema = Node._findSchema(this.editor.options.schema, this.getPath()); |
| 13937 |
if (this.schema) { |
| 13938 |
this.enum = Node._findEnum(this.schema); |
| 13939 |
} |
| 13940 |
else { |
| 13941 |
delete this.enum; |
| 13942 |
} |
| 13943 |
} |
| 13944 |
}; |
| 13945 |
|
| 13946 |
/** |
| 13947 |
* find an enum definition in a JSON schema, as property `enum` or inside |
| 13948 |
* one of the schemas composites (`oneOf`, `anyOf`, `allOf`) |
| 13949 |
* @param {Object} schema |
| 13950 |
* @return {Array | null} Returns the enum when found, null otherwise. |
| 13951 |
* @private |
| 13952 |
*/ |
| 13953 |
Node._findEnum = function (schema) { |
| 13954 |
if (schema.enum) { |
| 13955 |
return schema.enum; |
| 13956 |
} |
| 13957 |
|
| 13958 |
var composite = schema.oneOf || schema.anyOf || schema.allOf; |
| 13959 |
if (composite) { |
| 13960 |
var match = composite.filter(function (entry) {return entry.enum}); |
| 13961 |
if (match.length > 0) { |
| 13962 |
return match[0].enum; |
| 13963 |
} |
| 13964 |
} |
| 13965 |
|
| 13966 |
return null |
| 13967 |
}; |
| 13968 |
|
| 13969 |
/** |
| 13970 |
* Return the part of a JSON schema matching given path. |
| 13971 |
* @param {Object} schema |
| 13972 |
* @param {Array.<string | number>} path |
| 13973 |
* @return {Object | null} |
| 13974 |
* @private |
| 13975 |
*/ |
| 13976 |
Node._findSchema = function (schema, path) { |
| 13977 |
var childSchema = schema; |
| 13978 |
|
| 13979 |
for (var i = 0; i < path.length && childSchema; i++) { |
| 13980 |
var key = path[i]; |
| 13981 |
if (typeof key === 'string' && childSchema.properties) { |
| 13982 |
childSchema = childSchema.properties[key] || null |
| 13983 |
} |
| 13984 |
else if (typeof key === 'number' && childSchema.items) { |
| 13985 |
childSchema = childSchema.items |
| 13986 |
} |
| 13987 |
} |
| 13988 |
|
| 13989 |
return childSchema |
| 13990 |
}; |
| 13991 |
|
| 13992 |
/** |
| 13993 |
* Update the DOM of the childs of a node: update indexes and undefined field |
| 13994 |
* names. |
| 13995 |
* Only applicable when structure is an array or object |
| 13996 |
* @private |
| 13997 |
*/ |
| 13998 |
Node.prototype._updateDomIndexes = function () { |
| 13999 |
var domValue = this.dom.value; |
| 14000 |
var childs = this.childs; |
| 14001 |
if (domValue && childs) { |
| 14002 |
if (this.type == 'array') { |
| 14003 |
childs.forEach(function (child, index) { |
| 14004 |
child.index = index; |
| 14005 |
var childField = child.dom.field; |
| 14006 |
if (childField) { |
| 14007 |
childField.innerHTML = index; |
| 14008 |
} |
| 14009 |
}); |
| 14010 |
} |
| 14011 |
else if (this.type == 'object') { |
| 14012 |
childs.forEach(function (child) { |
| 14013 |
if (child.index != undefined) { |
| 14014 |
delete child.index; |
| 14015 |
|
| 14016 |
if (child.field == undefined) { |
| 14017 |
child.field = ''; |
| 14018 |
} |
| 14019 |
} |
| 14020 |
}); |
| 14021 |
} |
| 14022 |
} |
| 14023 |
}; |
| 14024 |
|
| 14025 |
/** |
| 14026 |
* Create an editable value |
| 14027 |
* @private |
| 14028 |
*/ |
| 14029 |
Node.prototype._createDomValue = function () { |
| 14030 |
var domValue; |
| 14031 |
|
| 14032 |
if (this.type == 'array') { |
| 14033 |
domValue = document.createElement('div'); |
| 14034 |
domValue.innerHTML = '[...]'; |
| 14035 |
} |
| 14036 |
else if (this.type == 'object') { |
| 14037 |
domValue = document.createElement('div'); |
| 14038 |
domValue.innerHTML = '{...}'; |
| 14039 |
} |
| 14040 |
else { |
| 14041 |
if (!this.editable.value && util.isUrl(this.value)) { |
| 14042 |
// create a link in case of read-only editor and value containing an url |
| 14043 |
domValue = document.createElement('a'); |
| 14044 |
domValue.href = this.value; |
| 14045 |
domValue.target = '_blank'; |
| 14046 |
domValue.innerHTML = this._escapeHTML(this.value); |
| 14047 |
} |
| 14048 |
else { |
| 14049 |
// create an editable or read-only div |
| 14050 |
domValue = document.createElement('div'); |
| 14051 |
domValue.contentEditable = this.editable.value; |
| 14052 |
domValue.spellcheck = false; |
| 14053 |
domValue.innerHTML = this._escapeHTML(this.value); |
| 14054 |
} |
| 14055 |
} |
| 14056 |
|
| 14057 |
return domValue; |
| 14058 |
}; |
| 14059 |
|
| 14060 |
/** |
| 14061 |
* Create an expand/collapse button |
| 14062 |
* @return {Element} expand |
| 14063 |
* @private |
| 14064 |
*/ |
| 14065 |
Node.prototype._createDomExpandButton = function () { |
| 14066 |
// create expand button |
| 14067 |
var expand = document.createElement('button'); |
| 14068 |
expand.type = 'button'; |
| 14069 |
if (this._hasChilds()) { |
| 14070 |
expand.className = this.expanded ? 'jsoneditor-expanded' : 'jsoneditor-collapsed'; |
| 14071 |
expand.title = |
| 14072 |
'Click to expand/collapse this field (Ctrl+E). \n' + |
| 14073 |
'Ctrl+Click to expand/collapse including all childs.'; |
| 14074 |
} |
| 14075 |
else { |
| 14076 |
expand.className = 'jsoneditor-invisible'; |
| 14077 |
expand.title = ''; |
| 14078 |
} |
| 14079 |
|
| 14080 |
return expand; |
| 14081 |
}; |
| 14082 |
|
| 14083 |
|
| 14084 |
/** |
| 14085 |
* Create a DOM tree element, containing the expand/collapse button |
| 14086 |
* @return {Element} domTree |
| 14087 |
* @private |
| 14088 |
*/ |
| 14089 |
Node.prototype._createDomTree = function () { |
| 14090 |
var dom = this.dom; |
| 14091 |
var domTree = document.createElement('table'); |
| 14092 |
var tbody = document.createElement('tbody'); |
| 14093 |
domTree.style.borderCollapse = 'collapse'; // TODO: put in css |
| 14094 |
domTree.className = 'jsoneditor-values'; |
| 14095 |
domTree.appendChild(tbody); |
| 14096 |
var tr = document.createElement('tr'); |
| 14097 |
tbody.appendChild(tr); |
| 14098 |
|
| 14099 |
// create expand button |
| 14100 |
var tdExpand = document.createElement('td'); |
| 14101 |
tdExpand.className = 'jsoneditor-tree'; |
| 14102 |
tr.appendChild(tdExpand); |
| 14103 |
dom.expand = this._createDomExpandButton(); |
| 14104 |
tdExpand.appendChild(dom.expand); |
| 14105 |
dom.tdExpand = tdExpand; |
| 14106 |
|
| 14107 |
// create the field |
| 14108 |
var tdField = document.createElement('td'); |
| 14109 |
tdField.className = 'jsoneditor-tree'; |
| 14110 |
tr.appendChild(tdField); |
| 14111 |
dom.field = this._createDomField(); |
| 14112 |
tdField.appendChild(dom.field); |
| 14113 |
dom.tdField = tdField; |
| 14114 |
|
| 14115 |
// create a separator |
| 14116 |
var tdSeparator = document.createElement('td'); |
| 14117 |
tdSeparator.className = 'jsoneditor-tree'; |
| 14118 |
tr.appendChild(tdSeparator); |
| 14119 |
if (this.type != 'object' && this.type != 'array') { |
| 14120 |
tdSeparator.appendChild(document.createTextNode(':')); |
| 14121 |
tdSeparator.className = 'jsoneditor-separator'; |
| 14122 |
} |
| 14123 |
dom.tdSeparator = tdSeparator; |
| 14124 |
|
| 14125 |
// create the value |
| 14126 |
var tdValue = document.createElement('td'); |
| 14127 |
tdValue.className = 'jsoneditor-tree'; |
| 14128 |
tr.appendChild(tdValue); |
| 14129 |
dom.value = this._createDomValue(); |
| 14130 |
tdValue.appendChild(dom.value); |
| 14131 |
dom.tdValue = tdValue; |
| 14132 |
|
| 14133 |
return domTree; |
| 14134 |
}; |
| 14135 |
|
| 14136 |
/** |
| 14137 |
* Handle an event. The event is caught centrally by the editor |
| 14138 |
* @param {Event} event |
| 14139 |
*/ |
| 14140 |
Node.prototype.onEvent = function (event) { |
| 14141 |
var type = event.type, |
| 14142 |
target = event.target || event.srcElement, |
| 14143 |
dom = this.dom, |
| 14144 |
node = this, |
| 14145 |
expandable = this._hasChilds(); |
| 14146 |
|
| 14147 |
// check if mouse is on menu or on dragarea. |
| 14148 |
// If so, highlight current row and its childs |
| 14149 |
if (target == dom.drag || target == dom.menu) { |
| 14150 |
if (type == 'mouseover') { |
| 14151 |
this.editor.highlighter.highlight(this); |
| 14152 |
} |
| 14153 |
else if (type == 'mouseout') { |
| 14154 |
this.editor.highlighter.unhighlight(); |
| 14155 |
} |
| 14156 |
} |
| 14157 |
|
| 14158 |
// context menu events |
| 14159 |
if (type == 'click' && target == dom.menu) { |
| 14160 |
var highlighter = node.editor.highlighter; |
| 14161 |
highlighter.highlight(node); |
| 14162 |
highlighter.lock(); |
| 14163 |
util.addClassName(dom.menu, 'jsoneditor-selected'); |
| 14164 |
this.showContextMenu(dom.menu, function () { |
| 14165 |
util.removeClassName(dom.menu, 'jsoneditor-selected'); |
| 14166 |
highlighter.unlock(); |
| 14167 |
highlighter.unhighlight(); |
| 14168 |
}); |
| 14169 |
} |
| 14170 |
|
| 14171 |
// expand events |
| 14172 |
if (type == 'click') { |
| 14173 |
if (target == dom.expand || |
| 14174 |
((node.editor.options.mode === 'view' || node.editor.options.mode === 'form') && target.nodeName === 'DIV')) { |
| 14175 |
if (expandable) { |
| 14176 |
var recurse = event.ctrlKey; // with ctrl-key, expand/collapse all |
| 14177 |
this._onExpand(recurse); |
| 14178 |
} |
| 14179 |
} |
| 14180 |
} |
| 14181 |
|
| 14182 |
// swap the value of a boolean when the checkbox displayed left is clicked |
| 14183 |
if (type == 'change' && target == dom.checkbox) { |
| 14184 |
this.dom.value.innerHTML = !this.value; |
| 14185 |
this._getDomValue(); |
| 14186 |
} |
| 14187 |
|
| 14188 |
// update the value of the node based on the selected option |
| 14189 |
if (type == 'change' && target == dom.select) { |
| 14190 |
this.dom.value.innerHTML = dom.select.value; |
| 14191 |
this._getDomValue(); |
| 14192 |
this._updateDomValue(); |
| 14193 |
} |
| 14194 |
|
| 14195 |
// value events |
| 14196 |
var domValue = dom.value; |
| 14197 |
if (target == domValue) { |
| 14198 |
//noinspection FallthroughInSwitchStatementJS |
| 14199 |
switch (type) { |
| 14200 |
case 'blur': |
| 14201 |
case 'change': |
| 14202 |
this._getDomValue(true); |
| 14203 |
this._updateDomValue(); |
| 14204 |
if (this.value) { |
| 14205 |
domValue.innerHTML = this._escapeHTML(this.value); |
| 14206 |
} |
| 14207 |
break; |
| 14208 |
|
| 14209 |
case 'input': |
| 14210 |
//this._debouncedGetDomValue(true); // TODO |
| 14211 |
this._getDomValue(true); |
| 14212 |
this._updateDomValue(); |
| 14213 |
break; |
| 14214 |
|
| 14215 |
case 'keydown': |
| 14216 |
case 'mousedown': |
| 14217 |
// TODO: cleanup |
| 14218 |
this.editor.selection = this.editor.getSelection(); |
| 14219 |
break; |
| 14220 |
|
| 14221 |
case 'click': |
| 14222 |
if (event.ctrlKey || !this.editable.value) { |
| 14223 |
if (util.isUrl(this.value)) { |
| 14224 |
window.open(this.value, '_blank'); |
| 14225 |
} |
| 14226 |
} |
| 14227 |
break; |
| 14228 |
|
| 14229 |
case 'keyup': |
| 14230 |
//this._debouncedGetDomValue(true); // TODO |
| 14231 |
this._getDomValue(true); |
| 14232 |
this._updateDomValue(); |
| 14233 |
break; |
| 14234 |
|
| 14235 |
case 'cut': |
| 14236 |
case 'paste': |
| 14237 |
setTimeout(function () { |
| 14238 |
node._getDomValue(true); |
| 14239 |
node._updateDomValue(); |
| 14240 |
}, 1); |
| 14241 |
break; |
| 14242 |
} |
| 14243 |
} |
| 14244 |
|
| 14245 |
// field events |
| 14246 |
var domField = dom.field; |
| 14247 |
if (target == domField) { |
| 14248 |
switch (type) { |
| 14249 |
case 'blur': |
| 14250 |
case 'change': |
| 14251 |
this._getDomField(true); |
| 14252 |
this._updateDomField(); |
| 14253 |
if (this.field) { |
| 14254 |
domField.innerHTML = this._escapeHTML(this.field); |
| 14255 |
} |
| 14256 |
break; |
| 14257 |
|
| 14258 |
case 'input': |
| 14259 |
this._getDomField(true); |
| 14260 |
this._updateSchema(); |
| 14261 |
this._updateDomField(); |
| 14262 |
this._updateDomValue(); |
| 14263 |
break; |
| 14264 |
|
| 14265 |
case 'keydown': |
| 14266 |
case 'mousedown': |
| 14267 |
this.editor.selection = this.editor.getSelection(); |
| 14268 |
break; |
| 14269 |
|
| 14270 |
case 'keyup': |
| 14271 |
this._getDomField(true); |
| 14272 |
this._updateDomField(); |
| 14273 |
break; |
| 14274 |
|
| 14275 |
case 'cut': |
| 14276 |
case 'paste': |
| 14277 |
setTimeout(function () { |
| 14278 |
node._getDomField(true); |
| 14279 |
node._updateDomField(); |
| 14280 |
}, 1); |
| 14281 |
break; |
| 14282 |
} |
| 14283 |
} |
| 14284 |
|
| 14285 |
// focus |
| 14286 |
// when clicked in whitespace left or right from the field or value, set focus |
| 14287 |
var domTree = dom.tree; |
| 14288 |
if (target == domTree.parentNode && type == 'click' && !event.hasMoved) { |
| 14289 |
var left = (event.offsetX != undefined) ? |
| 14290 |
(event.offsetX < (this.getLevel() + 1) * 24) : |
| 14291 |
(event.pageX < util.getAbsoluteLeft(dom.tdSeparator));// for FF |
| 14292 |
if (left || expandable) { |
| 14293 |
// node is expandable when it is an object or array |
| 14294 |
if (domField) { |
| 14295 |
util.setEndOfContentEditable(domField); |
| 14296 |
domField.focus(); |
| 14297 |
} |
| 14298 |
} |
| 14299 |
else { |
| 14300 |
if (domValue && !this.enum) { |
| 14301 |
util.setEndOfContentEditable(domValue); |
| 14302 |
domValue.focus(); |
| 14303 |
} |
| 14304 |
} |
| 14305 |
} |
| 14306 |
if (((target == dom.tdExpand && !expandable) || target == dom.tdField || target == dom.tdSeparator) && |
| 14307 |
(type == 'click' && !event.hasMoved)) { |
| 14308 |
if (domField) { |
| 14309 |
util.setEndOfContentEditable(domField); |
| 14310 |
domField.focus(); |
| 14311 |
} |
| 14312 |
} |
| 14313 |
|
| 14314 |
if (type == 'keydown') { |
| 14315 |
this.onKeyDown(event); |
| 14316 |
} |
| 14317 |
}; |
| 14318 |
|
| 14319 |
/** |
| 14320 |
* Key down event handler |
| 14321 |
* @param {Event} event |
| 14322 |
*/ |
| 14323 |
Node.prototype.onKeyDown = function (event) { |
| 14324 |
var keynum = event.which || event.keyCode; |
| 14325 |
var target = event.target || event.srcElement; |
| 14326 |
var ctrlKey = event.ctrlKey; |
| 14327 |
var shiftKey = event.shiftKey; |
| 14328 |
var altKey = event.altKey; |
| 14329 |
var handled = false; |
| 14330 |
var prevNode, nextNode, nextDom, nextDom2; |
| 14331 |
var editable = this.editor.options.mode === 'tree'; |
| 14332 |
var oldSelection; |
| 14333 |
var oldBeforeNode; |
| 14334 |
var nodes; |
| 14335 |
var multiselection; |
| 14336 |
var selectedNodes = this.editor.multiselection.nodes.length > 0 |
| 14337 |
? this.editor.multiselection.nodes |
| 14338 |
: [this]; |
| 14339 |
var firstNode = selectedNodes[0]; |
| 14340 |
var lastNode = selectedNodes[selectedNodes.length - 1]; |
| 14341 |
|
| 14342 |
// console.log(ctrlKey, keynum, event.charCode); // TODO: cleanup |
| 14343 |
if (keynum == 13) { // Enter |
| 14344 |
if (target == this.dom.value) { |
| 14345 |
if (!this.editable.value || event.ctrlKey) { |
| 14346 |
if (util.isUrl(this.value)) { |
| 14347 |
window.open(this.value, '_blank'); |
| 14348 |
handled = true; |
| 14349 |
} |
| 14350 |
} |
| 14351 |
} |
| 14352 |
else if (target == this.dom.expand) { |
| 14353 |
var expandable = this._hasChilds(); |
| 14354 |
if (expandable) { |
| 14355 |
var recurse = event.ctrlKey; // with ctrl-key, expand/collapse all |
| 14356 |
this._onExpand(recurse); |
| 14357 |
target.focus(); |
| 14358 |
handled = true; |
| 14359 |
} |
| 14360 |
} |
| 14361 |
} |
| 14362 |
else if (keynum == 68) { // D |
| 14363 |
if (ctrlKey && editable) { // Ctrl+D |
| 14364 |
Node.onDuplicate(selectedNodes); |
| 14365 |
handled = true; |
| 14366 |
} |
| 14367 |
} |
| 14368 |
else if (keynum == 69) { // E |
| 14369 |
if (ctrlKey) { // Ctrl+E and Ctrl+Shift+E |
| 14370 |
this._onExpand(shiftKey); // recurse = shiftKey |
| 14371 |
target.focus(); // TODO: should restore focus in case of recursing expand (which takes DOM offline) |
| 14372 |
handled = true; |
| 14373 |
} |
| 14374 |
} |
| 14375 |
else if (keynum == 77 && editable) { // M |
| 14376 |
if (ctrlKey) { // Ctrl+M |
| 14377 |
this.showContextMenu(target); |
| 14378 |
handled = true; |
| 14379 |
} |
| 14380 |
} |
| 14381 |
else if (keynum == 46 && editable) { // Del |
| 14382 |
if (ctrlKey) { // Ctrl+Del |
| 14383 |
Node.onRemove(selectedNodes); |
| 14384 |
handled = true; |
| 14385 |
} |
| 14386 |
} |
| 14387 |
else if (keynum == 45 && editable) { // Ins |
| 14388 |
if (ctrlKey && !shiftKey) { // Ctrl+Ins |
| 14389 |
this._onInsertBefore(); |
| 14390 |
handled = true; |
| 14391 |
} |
| 14392 |
else if (ctrlKey && shiftKey) { // Ctrl+Shift+Ins |
| 14393 |
this._onInsertAfter(); |
| 14394 |
handled = true; |
| 14395 |
} |
| 14396 |
} |
| 14397 |
else if (keynum == 35) { // End |
| 14398 |
if (altKey) { // Alt+End |
| 14399 |
// find the last node |
| 14400 |
var endNode = this._lastNode(); |
| 14401 |
if (endNode) { |
| 14402 |
endNode.focus(Node.focusElement || this._getElementName(target)); |
| 14403 |
} |
| 14404 |
handled = true; |
| 14405 |
} |
| 14406 |
} |
| 14407 |
else if (keynum == 36) { // Home |
| 14408 |
if (altKey) { // Alt+Home |
| 14409 |
// find the first node |
| 14410 |
var homeNode = this._firstNode(); |
| 14411 |
if (homeNode) { |
| 14412 |
homeNode.focus(Node.focusElement || this._getElementName(target)); |
| 14413 |
} |
| 14414 |
handled = true; |
| 14415 |
} |
| 14416 |
} |
| 14417 |
else if (keynum == 37) { // Arrow Left |
| 14418 |
if (altKey && !shiftKey) { // Alt + Arrow Left |
| 14419 |
// move to left element |
| 14420 |
var prevElement = this._previousElement(target); |
| 14421 |
if (prevElement) { |
| 14422 |
this.focus(this._getElementName(prevElement)); |
| 14423 |
} |
| 14424 |
handled = true; |
| 14425 |
} |
| 14426 |
else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow left |
| 14427 |
if (lastNode.expanded) { |
| 14428 |
var appendDom = lastNode.getAppend(); |
| 14429 |
nextDom = appendDom ? appendDom.nextSibling : undefined; |
| 14430 |
} |
| 14431 |
else { |
| 14432 |
var dom = lastNode.getDom(); |
| 14433 |
nextDom = dom.nextSibling; |
| 14434 |
} |
| 14435 |
if (nextDom) { |
| 14436 |
nextNode = Node.getNodeFromTarget(nextDom); |
| 14437 |
nextDom2 = nextDom.nextSibling; |
| 14438 |
nextNode2 = Node.getNodeFromTarget(nextDom2); |
| 14439 |
if (nextNode && nextNode instanceof AppendNode && |
| 14440 |
!(lastNode.parent.childs.length == 1) && |
| 14441 |
nextNode2 && nextNode2.parent) { |
| 14442 |
oldSelection = this.editor.getSelection(); |
| 14443 |
oldBeforeNode = lastNode._nextSibling(); |
| 14444 |
|
| 14445 |
selectedNodes.forEach(function (node) { |
| 14446 |
nextNode2.parent.moveBefore(node, nextNode2); |
| 14447 |
}); |
| 14448 |
this.focus(Node.focusElement || this._getElementName(target)); |
| 14449 |
|
| 14450 |
this.editor._onAction('moveNodes', { |
| 14451 |
nodes: selectedNodes, |
| 14452 |
oldBeforeNode: oldBeforeNode, |
| 14453 |
newBeforeNode: nextNode2, |
| 14454 |
oldSelection: oldSelection, |
| 14455 |
newSelection: this.editor.getSelection() |
| 14456 |
}); |
| 14457 |
} |
| 14458 |
} |
| 14459 |
} |
| 14460 |
} |
| 14461 |
else if (keynum == 38) { // Arrow Up |
| 14462 |
if (altKey && !shiftKey) { // Alt + Arrow Up |
| 14463 |
// find the previous node |
| 14464 |
prevNode = this._previousNode(); |
| 14465 |
if (prevNode) { |
| 14466 |
this.editor.deselect(true); |
| 14467 |
prevNode.focus(Node.focusElement || this._getElementName(target)); |
| 14468 |
} |
| 14469 |
handled = true; |
| 14470 |
} |
| 14471 |
else if (!altKey && ctrlKey && shiftKey && editable) { // Ctrl + Shift + Arrow Up |
| 14472 |
// select multiple nodes |
| 14473 |
prevNode = this._previousNode(); |
| 14474 |
if (prevNode) { |
| 14475 |
multiselection = this.editor.multiselection; |
| 14476 |
multiselection.start = multiselection.start || this; |
| 14477 |
multiselection.end = prevNode; |
| 14478 |
nodes = this.editor._findTopLevelNodes(multiselection.start, multiselection.end); |
| 14479 |
|
| 14480 |
this.editor.select(nodes); |
| 14481 |
prevNode.focus('field'); // select field as we know this always exists |
| 14482 |
} |
| 14483 |
handled = true; |
| 14484 |
} |
| 14485 |
else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow Up |
| 14486 |
// find the previous node |
| 14487 |
prevNode = firstNode._previousNode(); |
| 14488 |
if (prevNode && prevNode.parent) { |
| 14489 |
oldSelection = this.editor.getSelection(); |
| 14490 |
oldBeforeNode = lastNode._nextSibling(); |
| 14491 |
|
| 14492 |
selectedNodes.forEach(function (node) { |
| 14493 |
prevNode.parent.moveBefore(node, prevNode); |
| 14494 |
}); |
| 14495 |
this.focus(Node.focusElement || this._getElementName(target)); |
| 14496 |
|
| 14497 |
this.editor._onAction('moveNodes', { |
| 14498 |
nodes: selectedNodes, |
| 14499 |
oldBeforeNode: oldBeforeNode, |
| 14500 |
newBeforeNode: prevNode, |
| 14501 |
oldSelection: oldSelection, |
| 14502 |
newSelection: this.editor.getSelection() |
| 14503 |
}); |
| 14504 |
} |
| 14505 |
handled = true; |
| 14506 |
} |
| 14507 |
} |
| 14508 |
else if (keynum == 39) { // Arrow Right |
| 14509 |
if (altKey && !shiftKey) { // Alt + Arrow Right |
| 14510 |
// move to right element |
| 14511 |
var nextElement = this._nextElement(target); |
| 14512 |
if (nextElement) { |
| 14513 |
this.focus(this._getElementName(nextElement)); |
| 14514 |
} |
| 14515 |
handled = true; |
| 14516 |
} |
| 14517 |
else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow Right |
| 14518 |
dom = firstNode.getDom(); |
| 14519 |
var prevDom = dom.previousSibling; |
| 14520 |
if (prevDom) { |
| 14521 |
prevNode = Node.getNodeFromTarget(prevDom); |
| 14522 |
if (prevNode && prevNode.parent && |
| 14523 |
(prevNode instanceof AppendNode) |
| 14524 |
&& !prevNode.isVisible()) { |
| 14525 |
oldSelection = this.editor.getSelection(); |
| 14526 |
oldBeforeNode = lastNode._nextSibling(); |
| 14527 |
|
| 14528 |
selectedNodes.forEach(function (node) { |
| 14529 |
prevNode.parent.moveBefore(node, prevNode); |
| 14530 |
}); |
| 14531 |
this.focus(Node.focusElement || this._getElementName(target)); |
| 14532 |
|
| 14533 |
this.editor._onAction('moveNodes', { |
| 14534 |
nodes: selectedNodes, |
| 14535 |
oldBeforeNode: oldBeforeNode, |
| 14536 |
newBeforeNode: prevNode, |
| 14537 |
oldSelection: oldSelection, |
| 14538 |
newSelection: this.editor.getSelection() |
| 14539 |
}); |
| 14540 |
} |
| 14541 |
} |
| 14542 |
} |
| 14543 |
} |
| 14544 |
else if (keynum == 40) { // Arrow Down |
| 14545 |
if (altKey && !shiftKey) { // Alt + Arrow Down |
| 14546 |
// find the next node |
| 14547 |
nextNode = this._nextNode(); |
| 14548 |
if (nextNode) { |
| 14549 |
this.editor.deselect(true); |
| 14550 |
nextNode.focus(Node.focusElement || this._getElementName(target)); |
| 14551 |
} |
| 14552 |
handled = true; |
| 14553 |
} |
| 14554 |
else if (!altKey && ctrlKey && shiftKey && editable) { // Ctrl + Shift + Arrow Down |
| 14555 |
// select multiple nodes |
| 14556 |
nextNode = this._nextNode(); |
| 14557 |
if (nextNode) { |
| 14558 |
multiselection = this.editor.multiselection; |
| 14559 |
multiselection.start = multiselection.start || this; |
| 14560 |
multiselection.end = nextNode; |
| 14561 |
nodes = this.editor._findTopLevelNodes(multiselection.start, multiselection.end); |
| 14562 |
|
| 14563 |
this.editor.select(nodes); |
| 14564 |
nextNode.focus('field'); // select field as we know this always exists |
| 14565 |
} |
| 14566 |
handled = true; |
| 14567 |
} |
| 14568 |
else if (altKey && shiftKey && editable) { // Alt + Shift + Arrow Down |
| 14569 |
// find the 2nd next node and move before that one |
| 14570 |
if (lastNode.expanded) { |
| 14571 |
nextNode = lastNode.append ? lastNode.append._nextNode() : undefined; |
| 14572 |
} |
| 14573 |
else { |
| 14574 |
nextNode = lastNode._nextNode(); |
| 14575 |
} |
| 14576 |
var nextNode2 = nextNode && (nextNode._nextNode() || nextNode.parent.append); |
| 14577 |
if (nextNode2 && nextNode2.parent) { |
| 14578 |
oldSelection = this.editor.getSelection(); |
| 14579 |
oldBeforeNode = lastNode._nextSibling(); |
| 14580 |
|
| 14581 |
selectedNodes.forEach(function (node) { |
| 14582 |
nextNode2.parent.moveBefore(node, nextNode2); |
| 14583 |
}); |
| 14584 |
this.focus(Node.focusElement || this._getElementName(target)); |
| 14585 |
|
| 14586 |
this.editor._onAction('moveNodes', { |
| 14587 |
nodes: selectedNodes, |
| 14588 |
oldBeforeNode: oldBeforeNode, |
| 14589 |
newBeforeNode: nextNode2, |
| 14590 |
oldSelection: oldSelection, |
| 14591 |
newSelection: this.editor.getSelection() |
| 14592 |
}); |
| 14593 |
} |
| 14594 |
handled = true; |
| 14595 |
} |
| 14596 |
} |
| 14597 |
|
| 14598 |
if (handled) { |
| 14599 |
event.preventDefault(); |
| 14600 |
event.stopPropagation(); |
| 14601 |
} |
| 14602 |
}; |
| 14603 |
|
| 14604 |
/** |
| 14605 |
* Handle the expand event, when clicked on the expand button |
| 14606 |
* @param {boolean} recurse If true, child nodes will be expanded too |
| 14607 |
* @private |
| 14608 |
*/ |
| 14609 |
Node.prototype._onExpand = function (recurse) { |
| 14610 |
if (recurse) { |
| 14611 |
// Take the table offline |
| 14612 |
var table = this.dom.tr.parentNode; // TODO: not nice to access the main table like this |
| 14613 |
var frame = table.parentNode; |
| 14614 |
var scrollTop = frame.scrollTop; |
| 14615 |
frame.removeChild(table); |
| 14616 |
} |
| 14617 |
|
| 14618 |
if (this.expanded) { |
| 14619 |
this.collapse(recurse); |
| 14620 |
} |
| 14621 |
else { |
| 14622 |
this.expand(recurse); |
| 14623 |
} |
| 14624 |
|
| 14625 |
if (recurse) { |
| 14626 |
// Put the table online again |
| 14627 |
frame.appendChild(table); |
| 14628 |
frame.scrollTop = scrollTop; |
| 14629 |
} |
| 14630 |
}; |
| 14631 |
|
| 14632 |
/** |
| 14633 |
* Remove nodes |
| 14634 |
* @param {Node[] | Node} nodes |
| 14635 |
*/ |
| 14636 |
Node.onRemove = function(nodes) { |
| 14637 |
if (!Array.isArray(nodes)) { |
| 14638 |
return Node.onRemove([nodes]); |
| 14639 |
} |
| 14640 |
|
| 14641 |
if (nodes && nodes.length > 0) { |
| 14642 |
var firstNode = nodes[0]; |
| 14643 |
var parent = firstNode.parent; |
| 14644 |
var editor = firstNode.editor; |
| 14645 |
var firstIndex = firstNode.getIndex(); |
| 14646 |
editor.highlighter.unhighlight(); |
| 14647 |
|
| 14648 |
// adjust the focus |
| 14649 |
var oldSelection = editor.getSelection(); |
| 14650 |
Node.blurNodes(nodes); |
| 14651 |
var newSelection = editor.getSelection(); |
| 14652 |
|
| 14653 |
// remove the nodes |
| 14654 |
nodes.forEach(function (node) { |
| 14655 |
node.parent._remove(node); |
| 14656 |
}); |
| 14657 |
|
| 14658 |
// store history action |
| 14659 |
editor._onAction('removeNodes', { |
| 14660 |
nodes: nodes.slice(0), // store a copy of the array! |
| 14661 |
parent: parent, |
| 14662 |
index: firstIndex, |
| 14663 |
oldSelection: oldSelection, |
| 14664 |
newSelection: newSelection |
| 14665 |
}); |
| 14666 |
} |
| 14667 |
}; |
| 14668 |
|
| 14669 |
|
| 14670 |
/** |
| 14671 |
* Duplicate nodes |
| 14672 |
* duplicated nodes will be added right after the original nodes |
| 14673 |
* @param {Node[] | Node} nodes |
| 14674 |
*/ |
| 14675 |
Node.onDuplicate = function(nodes) { |
| 14676 |
if (!Array.isArray(nodes)) { |
| 14677 |
return Node.onDuplicate([nodes]); |
| 14678 |
} |
| 14679 |
|
| 14680 |
if (nodes && nodes.length > 0) { |
| 14681 |
var lastNode = nodes[nodes.length - 1]; |
| 14682 |
var parent = lastNode.parent; |
| 14683 |
var editor = lastNode.editor; |
| 14684 |
|
| 14685 |
editor.deselect(editor.multiselection.nodes); |
| 14686 |
|
| 14687 |
// duplicate the nodes |
| 14688 |
var oldSelection = editor.getSelection(); |
| 14689 |
var afterNode = lastNode; |
| 14690 |
var clones = nodes.map(function (node) { |
| 14691 |
var clone = node.clone(); |
| 14692 |
parent.insertAfter(clone, afterNode); |
| 14693 |
afterNode = clone; |
| 14694 |
return clone; |
| 14695 |
}); |
| 14696 |
|
| 14697 |
// set selection to the duplicated nodes |
| 14698 |
if (nodes.length === 1) { |
| 14699 |
clones[0].focus(); |
| 14700 |
} |
| 14701 |
else { |
| 14702 |
editor.select(clones); |
| 14703 |
} |
| 14704 |
var newSelection = editor.getSelection(); |
| 14705 |
|
| 14706 |
editor._onAction('duplicateNodes', { |
| 14707 |
afterNode: lastNode, |
| 14708 |
nodes: clones, |
| 14709 |
parent: parent, |
| 14710 |
oldSelection: oldSelection, |
| 14711 |
newSelection: newSelection |
| 14712 |
}); |
| 14713 |
} |
| 14714 |
}; |
| 14715 |
|
| 14716 |
/** |
| 14717 |
* Handle insert before event |
| 14718 |
* @param {String} [field] |
| 14719 |
* @param {*} [value] |
| 14720 |
* @param {String} [type] Can be 'auto', 'array', 'object', or 'string' |
| 14721 |
* @private |
| 14722 |
*/ |
| 14723 |
Node.prototype._onInsertBefore = function (field, value, type) { |
| 14724 |
var oldSelection = this.editor.getSelection(); |
| 14725 |
|
| 14726 |
var newNode = new Node(this.editor, { |
| 14727 |
field: (field != undefined) ? field : '', |
| 14728 |
value: (value != undefined) ? value : '', |
| 14729 |
type: type |
| 14730 |
}); |
| 14731 |
newNode.expand(true); |
| 14732 |
this.parent.insertBefore(newNode, this); |
| 14733 |
this.editor.highlighter.unhighlight(); |
| 14734 |
newNode.focus('field'); |
| 14735 |
var newSelection = this.editor.getSelection(); |
| 14736 |
|
| 14737 |
this.editor._onAction('insertBeforeNodes', { |
| 14738 |
nodes: [newNode], |
| 14739 |
beforeNode: this, |
| 14740 |
parent: this.parent, |
| 14741 |
oldSelection: oldSelection, |
| 14742 |
newSelection: newSelection |
| 14743 |
}); |
| 14744 |
}; |
| 14745 |
|
| 14746 |
/** |
| 14747 |
* Handle insert after event |
| 14748 |
* @param {String} [field] |
| 14749 |
* @param {*} [value] |
| 14750 |
* @param {String} [type] Can be 'auto', 'array', 'object', or 'string' |
| 14751 |
* @private |
| 14752 |
*/ |
| 14753 |
Node.prototype._onInsertAfter = function (field, value, type) { |
| 14754 |
var oldSelection = this.editor.getSelection(); |
| 14755 |
|
| 14756 |
var newNode = new Node(this.editor, { |
| 14757 |
field: (field != undefined) ? field : '', |
| 14758 |
value: (value != undefined) ? value : '', |
| 14759 |
type: type |
| 14760 |
}); |
| 14761 |
newNode.expand(true); |
| 14762 |
this.parent.insertAfter(newNode, this); |
| 14763 |
this.editor.highlighter.unhighlight(); |
| 14764 |
newNode.focus('field'); |
| 14765 |
var newSelection = this.editor.getSelection(); |
| 14766 |
|
| 14767 |
this.editor._onAction('insertAfterNodes', { |
| 14768 |
nodes: [newNode], |
| 14769 |
afterNode: this, |
| 14770 |
parent: this.parent, |
| 14771 |
oldSelection: oldSelection, |
| 14772 |
newSelection: newSelection |
| 14773 |
}); |
| 14774 |
}; |
| 14775 |
|
| 14776 |
/** |
| 14777 |
* Handle append event |
| 14778 |
* @param {String} [field] |
| 14779 |
* @param {*} [value] |
| 14780 |
* @param {String} [type] Can be 'auto', 'array', 'object', or 'string' |
| 14781 |
* @private |
| 14782 |
*/ |
| 14783 |
Node.prototype._onAppend = function (field, value, type) { |
| 14784 |
var oldSelection = this.editor.getSelection(); |
| 14785 |
|
| 14786 |
var newNode = new Node(this.editor, { |
| 14787 |
field: (field != undefined) ? field : '', |
| 14788 |
value: (value != undefined) ? value : '', |
| 14789 |
type: type |
| 14790 |
}); |
| 14791 |
newNode.expand(true); |
| 14792 |
this.parent.appendChild(newNode); |
| 14793 |
this.editor.highlighter.unhighlight(); |
| 14794 |
newNode.focus('field'); |
| 14795 |
var newSelection = this.editor.getSelection(); |
| 14796 |
|
| 14797 |
this.editor._onAction('appendNodes', { |
| 14798 |
nodes: [newNode], |
| 14799 |
parent: this.parent, |
| 14800 |
oldSelection: oldSelection, |
| 14801 |
newSelection: newSelection |
| 14802 |
}); |
| 14803 |
}; |
| 14804 |
|
| 14805 |
/** |
| 14806 |
* Change the type of the node's value |
| 14807 |
* @param {String} newType |
| 14808 |
* @private |
| 14809 |
*/ |
| 14810 |
Node.prototype._onChangeType = function (newType) { |
| 14811 |
var oldType = this.type; |
| 14812 |
if (newType != oldType) { |
| 14813 |
var oldSelection = this.editor.getSelection(); |
| 14814 |
this.changeType(newType); |
| 14815 |
var newSelection = this.editor.getSelection(); |
| 14816 |
|
| 14817 |
this.editor._onAction('changeType', { |
| 14818 |
node: this, |
| 14819 |
oldType: oldType, |
| 14820 |
newType: newType, |
| 14821 |
oldSelection: oldSelection, |
| 14822 |
newSelection: newSelection |
| 14823 |
}); |
| 14824 |
} |
| 14825 |
}; |
| 14826 |
|
| 14827 |
/** |
| 14828 |
* Sort the child's of the node. Only applicable when the node has type 'object' |
| 14829 |
* or 'array'. |
| 14830 |
* @param {String} direction Sorting direction. Available values: "asc", "desc" |
| 14831 |
* @private |
| 14832 |
*/ |
| 14833 |
Node.prototype.sort = function (direction) { |
| 14834 |
if (!this._hasChilds()) { |
| 14835 |
return; |
| 14836 |
} |
| 14837 |
|
| 14838 |
var order = (direction == 'desc') ? -1 : 1; |
| 14839 |
var prop = (this.type == 'array') ? 'value': 'field'; |
| 14840 |
this.hideChilds(); |
| 14841 |
|
| 14842 |
var oldChilds = this.childs; |
| 14843 |
var oldSortOrder = this.sortOrder; |
| 14844 |
|
| 14845 |
// copy the array (the old one will be kept for an undo action |
| 14846 |
this.childs = this.childs.concat(); |
| 14847 |
|
| 14848 |
// sort the arrays |
| 14849 |
this.childs.sort(function (a, b) { |
| 14850 |
return order * naturalSort(a[prop], b[prop]); |
| 14851 |
}); |
| 14852 |
this.sortOrder = (order == 1) ? 'asc' : 'desc'; |
| 14853 |
|
| 14854 |
this.editor._onAction('sort', { |
| 14855 |
node: this, |
| 14856 |
oldChilds: oldChilds, |
| 14857 |
oldSort: oldSortOrder, |
| 14858 |
newChilds: this.childs, |
| 14859 |
newSort: this.sortOrder |
| 14860 |
}); |
| 14861 |
|
| 14862 |
this.showChilds(); |
| 14863 |
}; |
| 14864 |
|
| 14865 |
/** |
| 14866 |
* Create a table row with an append button. |
| 14867 |
* @return {HTMLElement | undefined} buttonAppend or undefined when inapplicable |
| 14868 |
*/ |
| 14869 |
Node.prototype.getAppend = function () { |
| 14870 |
if (!this.append) { |
| 14871 |
this.append = new AppendNode(this.editor); |
| 14872 |
this.append.setParent(this); |
| 14873 |
} |
| 14874 |
return this.append.getDom(); |
| 14875 |
}; |
| 14876 |
|
| 14877 |
/** |
| 14878 |
* Find the node from an event target |
| 14879 |
* @param {Node} target |
| 14880 |
* @return {Node | undefined} node or undefined when not found |
| 14881 |
* @static |
| 14882 |
*/ |
| 14883 |
Node.getNodeFromTarget = function (target) { |
| 14884 |
while (target) { |
| 14885 |
if (target.node) { |
| 14886 |
return target.node; |
| 14887 |
} |
| 14888 |
target = target.parentNode; |
| 14889 |
} |
| 14890 |
|
| 14891 |
return undefined; |
| 14892 |
}; |
| 14893 |
|
| 14894 |
/** |
| 14895 |
* Remove the focus of given nodes, and move the focus to the (a) node before, |
| 14896 |
* (b) the node after, or (c) the parent node. |
| 14897 |
* @param {Array.<Node> | Node} nodes |
| 14898 |
*/ |
| 14899 |
Node.blurNodes = function (nodes) { |
| 14900 |
if (!Array.isArray(nodes)) { |
| 14901 |
Node.blurNodes([nodes]); |
| 14902 |
return; |
| 14903 |
} |
| 14904 |
|
| 14905 |
var firstNode = nodes[0]; |
| 14906 |
var parent = firstNode.parent; |
| 14907 |
var firstIndex = firstNode.getIndex(); |
| 14908 |
|
| 14909 |
if (parent.childs[firstIndex + nodes.length]) { |
| 14910 |
parent.childs[firstIndex + nodes.length].focus(); |
| 14911 |
} |
| 14912 |
else if (parent.childs[firstIndex - 1]) { |
| 14913 |
parent.childs[firstIndex - 1].focus(); |
| 14914 |
} |
| 14915 |
else { |
| 14916 |
parent.focus(); |
| 14917 |
} |
| 14918 |
}; |
| 14919 |
|
| 14920 |
/** |
| 14921 |
* Get the next sibling of current node |
| 14922 |
* @return {Node} nextSibling |
| 14923 |
* @private |
| 14924 |
*/ |
| 14925 |
Node.prototype._nextSibling = function () { |
| 14926 |
var index = this.parent.childs.indexOf(this); |
| 14927 |
return this.parent.childs[index + 1] || this.parent.append; |
| 14928 |
}; |
| 14929 |
|
| 14930 |
/** |
| 14931 |
* Get the previously rendered node |
| 14932 |
* @return {Node | null} previousNode |
| 14933 |
* @private |
| 14934 |
*/ |
| 14935 |
Node.prototype._previousNode = function () { |
| 14936 |
var prevNode = null; |
| 14937 |
var dom = this.getDom(); |
| 14938 |
if (dom && dom.parentNode) { |
| 14939 |
// find the previous field |
| 14940 |
var prevDom = dom; |
| 14941 |
do { |
| 14942 |
prevDom = prevDom.previousSibling; |
| 14943 |
prevNode = Node.getNodeFromTarget(prevDom); |
| 14944 |
} |
| 14945 |
while (prevDom && (prevNode instanceof AppendNode && !prevNode.isVisible())); |
| 14946 |
} |
| 14947 |
return prevNode; |
| 14948 |
}; |
| 14949 |
|
| 14950 |
/** |
| 14951 |
* Get the next rendered node |
| 14952 |
* @return {Node | null} nextNode |
| 14953 |
* @private |
| 14954 |
*/ |
| 14955 |
Node.prototype._nextNode = function () { |
| 14956 |
var nextNode = null; |
| 14957 |
var dom = this.getDom(); |
| 14958 |
if (dom && dom.parentNode) { |
| 14959 |
// find the previous field |
| 14960 |
var nextDom = dom; |
| 14961 |
do { |
| 14962 |
nextDom = nextDom.nextSibling; |
| 14963 |
nextNode = Node.getNodeFromTarget(nextDom); |
| 14964 |
} |
| 14965 |
while (nextDom && (nextNode instanceof AppendNode && !nextNode.isVisible())); |
| 14966 |
} |
| 14967 |
|
| 14968 |
return nextNode; |
| 14969 |
}; |
| 14970 |
|
| 14971 |
/** |
| 14972 |
* Get the first rendered node |
| 14973 |
* @return {Node | null} firstNode |
| 14974 |
* @private |
| 14975 |
*/ |
| 14976 |
Node.prototype._firstNode = function () { |
| 14977 |
var firstNode = null; |
| 14978 |
var dom = this.getDom(); |
| 14979 |
if (dom && dom.parentNode) { |
| 14980 |
var firstDom = dom.parentNode.firstChild; |
| 14981 |
firstNode = Node.getNodeFromTarget(firstDom); |
| 14982 |
} |
| 14983 |
|
| 14984 |
return firstNode; |
| 14985 |
}; |
| 14986 |
|
| 14987 |
/** |
| 14988 |
* Get the last rendered node |
| 14989 |
* @return {Node | null} lastNode |
| 14990 |
* @private |
| 14991 |
*/ |
| 14992 |
Node.prototype._lastNode = function () { |
| 14993 |
var lastNode = null; |
| 14994 |
var dom = this.getDom(); |
| 14995 |
if (dom && dom.parentNode) { |
| 14996 |
var lastDom = dom.parentNode.lastChild; |
| 14997 |
lastNode = Node.getNodeFromTarget(lastDom); |
| 14998 |
while (lastDom && (lastNode instanceof AppendNode && !lastNode.isVisible())) { |
| 14999 |
lastDom = lastDom.previousSibling; |
| 15000 |
lastNode = Node.getNodeFromTarget(lastDom); |
| 15001 |
} |
| 15002 |
} |
| 15003 |
return lastNode; |
| 15004 |
}; |
| 15005 |
|
| 15006 |
/** |
| 15007 |
* Get the next element which can have focus. |
| 15008 |
* @param {Element} elem |
| 15009 |
* @return {Element | null} nextElem |
| 15010 |
* @private |
| 15011 |
*/ |
| 15012 |
Node.prototype._previousElement = function (elem) { |
| 15013 |
var dom = this.dom; |
| 15014 |
// noinspection FallthroughInSwitchStatementJS |
| 15015 |
switch (elem) { |
| 15016 |
case dom.value: |
| 15017 |
if (this.fieldEditable) { |
| 15018 |
return dom.field; |
| 15019 |
} |
| 15020 |
// intentional fall through |
| 15021 |
case dom.field: |
| 15022 |
if (this._hasChilds()) { |
| 15023 |
return dom.expand; |
| 15024 |
} |
| 15025 |
// intentional fall through |
| 15026 |
case dom.expand: |
| 15027 |
return dom.menu; |
| 15028 |
case dom.menu: |
| 15029 |
if (dom.drag) { |
| 15030 |
return dom.drag; |
| 15031 |
} |
| 15032 |
// intentional fall through |
| 15033 |
default: |
| 15034 |
return null; |
| 15035 |
} |
| 15036 |
}; |
| 15037 |
|
| 15038 |
/** |
| 15039 |
* Get the next element which can have focus. |
| 15040 |
* @param {Element} elem |
| 15041 |
* @return {Element | null} nextElem |
| 15042 |
* @private |
| 15043 |
*/ |
| 15044 |
Node.prototype._nextElement = function (elem) { |
| 15045 |
var dom = this.dom; |
| 15046 |
// noinspection FallthroughInSwitchStatementJS |
| 15047 |
switch (elem) { |
| 15048 |
case dom.drag: |
| 15049 |
return dom.menu; |
| 15050 |
case dom.menu: |
| 15051 |
if (this._hasChilds()) { |
| 15052 |
return dom.expand; |
| 15053 |
} |
| 15054 |
// intentional fall through |
| 15055 |
case dom.expand: |
| 15056 |
if (this.fieldEditable) { |
| 15057 |
return dom.field; |
| 15058 |
} |
| 15059 |
// intentional fall through |
| 15060 |
case dom.field: |
| 15061 |
if (!this._hasChilds()) { |
| 15062 |
return dom.value; |
| 15063 |
} |
| 15064 |
default: |
| 15065 |
return null; |
| 15066 |
} |
| 15067 |
}; |
| 15068 |
|
| 15069 |
/** |
| 15070 |
* Get the dom name of given element. returns null if not found. |
| 15071 |
* For example when element == dom.field, "field" is returned. |
| 15072 |
* @param {Element} element |
| 15073 |
* @return {String | null} elementName Available elements with name: 'drag', |
| 15074 |
* 'menu', 'expand', 'field', 'value' |
| 15075 |
* @private |
| 15076 |
*/ |
| 15077 |
Node.prototype._getElementName = function (element) { |
| 15078 |
var dom = this.dom; |
| 15079 |
for (var name in dom) { |
| 15080 |
if (dom.hasOwnProperty(name)) { |
| 15081 |
if (dom[name] == element) { |
| 15082 |
return name; |
| 15083 |
} |
| 15084 |
} |
| 15085 |
} |
| 15086 |
return null; |
| 15087 |
}; |
| 15088 |
|
| 15089 |
/** |
| 15090 |
* Test if this node has childs. This is the case when the node is an object |
| 15091 |
* or array. |
| 15092 |
* @return {boolean} hasChilds |
| 15093 |
* @private |
| 15094 |
*/ |
| 15095 |
Node.prototype._hasChilds = function () { |
| 15096 |
return this.type == 'array' || this.type == 'object'; |
| 15097 |
}; |
| 15098 |
|
| 15099 |
// titles with explanation for the different types |
| 15100 |
Node.TYPE_TITLES = { |
| 15101 |
'auto': 'Field type "auto". ' + |
| 15102 |
'The field type is automatically determined from the value ' + |
| 15103 |
'and can be a string, number, boolean, or null.', |
| 15104 |
'object': 'Field type "object". ' + |
| 15105 |
'An object contains an unordered set of key/value pairs.', |
| 15106 |
'array': 'Field type "array". ' + |
| 15107 |
'An array contains an ordered collection of values.', |
| 15108 |
'string': 'Field type "string". ' + |
| 15109 |
'Field type is not determined from the value, ' + |
| 15110 |
'but always returned as string.' |
| 15111 |
}; |
| 15112 |
|
| 15113 |
/** |
| 15114 |
* Show a contextmenu for this node |
| 15115 |
* @param {HTMLElement} anchor Anchor element to attach the context menu to |
| 15116 |
* as sibling. |
| 15117 |
* @param {function} [onClose] Callback method called when the context menu |
| 15118 |
* is being closed. |
| 15119 |
*/ |
| 15120 |
Node.prototype.showContextMenu = function (anchor, onClose) { |
| 15121 |
var node = this; |
| 15122 |
var titles = Node.TYPE_TITLES; |
| 15123 |
var items = []; |
| 15124 |
|
| 15125 |
if (this.editable.value) { |
| 15126 |
items.push({ |
| 15127 |
text: 'Type', |
| 15128 |
title: 'Change the type of this field', |
| 15129 |
className: 'jsoneditor-type-' + this.type, |
| 15130 |
submenu: [ |
| 15131 |
{ |
| 15132 |
text: 'Auto', |
| 15133 |
className: 'jsoneditor-type-auto' + |
| 15134 |
(this.type == 'auto' ? ' jsoneditor-selected' : ''), |
| 15135 |
title: titles.auto, |
| 15136 |
click: function () { |
| 15137 |
node._onChangeType('auto'); |
| 15138 |
} |
| 15139 |
}, |
| 15140 |
{ |
| 15141 |
text: 'Array', |
| 15142 |
className: 'jsoneditor-type-array' + |
| 15143 |
(this.type == 'array' ? ' jsoneditor-selected' : ''), |
| 15144 |
title: titles.array, |
| 15145 |
click: function () { |
| 15146 |
node._onChangeType('array'); |
| 15147 |
} |
| 15148 |
}, |
| 15149 |
{ |
| 15150 |
text: 'Object', |
| 15151 |
className: 'jsoneditor-type-object' + |
| 15152 |
(this.type == 'object' ? ' jsoneditor-selected' : ''), |
| 15153 |
title: titles.object, |
| 15154 |
click: function () { |
| 15155 |
node._onChangeType('object'); |
| 15156 |
} |
| 15157 |
}, |
| 15158 |
{ |
| 15159 |
text: 'String', |
| 15160 |
className: 'jsoneditor-type-string' + |
| 15161 |
(this.type == 'string' ? ' jsoneditor-selected' : ''), |
| 15162 |
title: titles.string, |
| 15163 |
click: function () { |
| 15164 |
node._onChangeType('string'); |
| 15165 |
} |
| 15166 |
} |
| 15167 |
] |
| 15168 |
}); |
| 15169 |
} |
| 15170 |
|
| 15171 |
if (this._hasChilds()) { |
| 15172 |
var direction = ((this.sortOrder == 'asc') ? 'desc': 'asc'); |
| 15173 |
items.push({ |
| 15174 |
text: 'Sort', |
| 15175 |
title: 'Sort the childs of this ' + this.type, |
| 15176 |
className: 'jsoneditor-sort-' + direction, |
| 15177 |
click: function () { |
| 15178 |
node.sort(direction); |
| 15179 |
}, |
| 15180 |
submenu: [ |
| 15181 |
{ |
| 15182 |
text: 'Ascending', |
| 15183 |
className: 'jsoneditor-sort-asc', |
| 15184 |
title: 'Sort the childs of this ' + this.type + ' in ascending order', |
| 15185 |
click: function () { |
| 15186 |
node.sort('asc'); |
| 15187 |
} |
| 15188 |
}, |
| 15189 |
{ |
| 15190 |
text: 'Descending', |
| 15191 |
className: 'jsoneditor-sort-desc', |
| 15192 |
title: 'Sort the childs of this ' + this.type +' in descending order', |
| 15193 |
click: function () { |
| 15194 |
node.sort('desc'); |
| 15195 |
} |
| 15196 |
} |
| 15197 |
] |
| 15198 |
}); |
| 15199 |
} |
| 15200 |
|
| 15201 |
if (this.parent && this.parent._hasChilds()) { |
| 15202 |
if (items.length) { |
| 15203 |
// create a separator |
| 15204 |
items.push({ |
| 15205 |
'type': 'separator' |
| 15206 |
}); |
| 15207 |
} |
| 15208 |
|
| 15209 |
// create append button (for last child node only) |
| 15210 |
var childs = node.parent.childs; |
| 15211 |
if (node == childs[childs.length - 1]) { |
| 15212 |
items.push({ |
| 15213 |
text: 'Append', |
| 15214 |
title: 'Append a new field with type \'auto\' after this field (Ctrl+Shift+Ins)', |
| 15215 |
submenuTitle: 'Select the type of the field to be appended', |
| 15216 |
className: 'jsoneditor-append', |
| 15217 |
click: function () { |
| 15218 |
node._onAppend('', '', 'auto'); |
| 15219 |
}, |
| 15220 |
submenu: [ |
| 15221 |
{ |
| 15222 |
text: 'Auto', |
| 15223 |
className: 'jsoneditor-type-auto', |
| 15224 |
title: titles.auto, |
| 15225 |
click: function () { |
| 15226 |
node._onAppend('', '', 'auto'); |
| 15227 |
} |
| 15228 |
}, |
| 15229 |
{ |
| 15230 |
text: 'Array', |
| 15231 |
className: 'jsoneditor-type-array', |
| 15232 |
title: titles.array, |
| 15233 |
click: function () { |
| 15234 |
node._onAppend('', []); |
| 15235 |
} |
| 15236 |
}, |
| 15237 |
{ |
| 15238 |
text: 'Object', |
| 15239 |
className: 'jsoneditor-type-object', |
| 15240 |
title: titles.object, |
| 15241 |
click: function () { |
| 15242 |
node._onAppend('', {}); |
| 15243 |
} |
| 15244 |
}, |
| 15245 |
{ |
| 15246 |
text: 'String', |
| 15247 |
className: 'jsoneditor-type-string', |
| 15248 |
title: titles.string, |
| 15249 |
click: function () { |
| 15250 |
node._onAppend('', '', 'string'); |
| 15251 |
} |
| 15252 |
} |
| 15253 |
] |
| 15254 |
}); |
| 15255 |
} |
| 15256 |
|
| 15257 |
// create insert button |
| 15258 |
items.push({ |
| 15259 |
text: 'Insert', |
| 15260 |
title: 'Insert a new field with type \'auto\' before this field (Ctrl+Ins)', |
| 15261 |
submenuTitle: 'Select the type of the field to be inserted', |
| 15262 |
className: 'jsoneditor-insert', |
| 15263 |
click: function () { |
| 15264 |
node._onInsertBefore('', '', 'auto'); |
| 15265 |
}, |
| 15266 |
submenu: [ |
| 15267 |
{ |
| 15268 |
text: 'Auto', |
| 15269 |
className: 'jsoneditor-type-auto', |
| 15270 |
title: titles.auto, |
| 15271 |
click: function () { |
| 15272 |
node._onInsertBefore('', '', 'auto'); |
| 15273 |
} |
| 15274 |
}, |
| 15275 |
{ |
| 15276 |
text: 'Array', |
| 15277 |
className: 'jsoneditor-type-array', |
| 15278 |
title: titles.array, |
| 15279 |
click: function () { |
| 15280 |
node._onInsertBefore('', []); |
| 15281 |
} |
| 15282 |
}, |
| 15283 |
{ |
| 15284 |
text: 'Object', |
| 15285 |
className: 'jsoneditor-type-object', |
| 15286 |
title: titles.object, |
| 15287 |
click: function () { |
| 15288 |
node._onInsertBefore('', {}); |
| 15289 |
} |
| 15290 |
}, |
| 15291 |
{ |
| 15292 |
text: 'String', |
| 15293 |
className: 'jsoneditor-type-string', |
| 15294 |
title: titles.string, |
| 15295 |
click: function () { |
| 15296 |
node._onInsertBefore('', '', 'string'); |
| 15297 |
} |
| 15298 |
} |
| 15299 |
] |
| 15300 |
}); |
| 15301 |
|
| 15302 |
if (this.editable.field) { |
| 15303 |
// create duplicate button |
| 15304 |
items.push({ |
| 15305 |
text: 'Duplicate', |
| 15306 |
title: 'Duplicate this field (Ctrl+D)', |
| 15307 |
className: 'jsoneditor-duplicate', |
| 15308 |
click: function () { |
| 15309 |
Node.onDuplicate(node); |
| 15310 |
} |
| 15311 |
}); |
| 15312 |
|
| 15313 |
// create remove button |
| 15314 |
items.push({ |
| 15315 |
text: 'Remove', |
| 15316 |
title: 'Remove this field (Ctrl+Del)', |
| 15317 |
className: 'jsoneditor-remove', |
| 15318 |
click: function () { |
| 15319 |
Node.onRemove(node); |
| 15320 |
} |
| 15321 |
}); |
| 15322 |
} |
| 15323 |
} |
| 15324 |
|
| 15325 |
var menu = new ContextMenu(items, {close: onClose}); |
| 15326 |
menu.show(anchor, this.editor.content); |
| 15327 |
}; |
| 15328 |
|
| 15329 |
/** |
| 15330 |
* get the type of a value |
| 15331 |
* @param {*} value |
| 15332 |
* @return {String} type Can be 'object', 'array', 'string', 'auto' |
| 15333 |
* @private |
| 15334 |
*/ |
| 15335 |
Node.prototype._getType = function(value) { |
| 15336 |
if (value instanceof Array) { |
| 15337 |
return 'array'; |
| 15338 |
} |
| 15339 |
if (value instanceof Object) { |
| 15340 |
return 'object'; |
| 15341 |
} |
| 15342 |
if (typeof(value) == 'string' && typeof(this._stringCast(value)) != 'string') { |
| 15343 |
return 'string'; |
| 15344 |
} |
| 15345 |
|
| 15346 |
return 'auto'; |
| 15347 |
}; |
| 15348 |
|
| 15349 |
/** |
| 15350 |
* cast contents of a string to the correct type. This can be a string, |
| 15351 |
* a number, a boolean, etc |
| 15352 |
* @param {String} str |
| 15353 |
* @return {*} castedStr |
| 15354 |
* @private |
| 15355 |
*/ |
| 15356 |
Node.prototype._stringCast = function(str) { |
| 15357 |
var lower = str.toLowerCase(), |
| 15358 |
num = Number(str), // will nicely fail with '123ab' |
| 15359 |
numFloat = parseFloat(str); // will nicely fail with ' ' |
| 15360 |
|
| 15361 |
if (str == '') { |
| 15362 |
return ''; |
| 15363 |
} |
| 15364 |
else if (lower == 'null') { |
| 15365 |
return null; |
| 15366 |
} |
| 15367 |
else if (lower == 'true') { |
| 15368 |
return true; |
| 15369 |
} |
| 15370 |
else if (lower == 'false') { |
| 15371 |
return false; |
| 15372 |
} |
| 15373 |
else if (!isNaN(num) && !isNaN(numFloat)) { |
| 15374 |
return num; |
| 15375 |
} |
| 15376 |
else { |
| 15377 |
return str; |
| 15378 |
} |
| 15379 |
}; |
| 15380 |
|
| 15381 |
/** |
| 15382 |
* escape a text, such that it can be displayed safely in an HTML element |
| 15383 |
* @param {String} text |
| 15384 |
* @return {String} escapedText |
| 15385 |
* @private |
| 15386 |
*/ |
| 15387 |
Node.prototype._escapeHTML = function (text) { |
| 15388 |
if (typeof text !== 'string') { |
| 15389 |
return String(text); |
| 15390 |
} |
| 15391 |
else { |
| 15392 |
var htmlEscaped = String(text) |
| 15393 |
.replace(/&/g, '&') // must be replaced first! |
| 15394 |
.replace(/</g, '<') |
| 15395 |
.replace(/>/g, '>') |
| 15396 |
.replace(/ /g, ' ') // replace double space with an nbsp and space |
| 15397 |
.replace(/^ /, ' ') // space at start |
| 15398 |
.replace(/ $/, ' '); // space at end |
| 15399 |
|
| 15400 |
var json = JSON.stringify(htmlEscaped); |
| 15401 |
var html = json.substring(1, json.length - 1); |
| 15402 |
if (this.editor.options.escapeUnicode === true) { |
| 15403 |
html = util.escapeUnicodeChars(html); |
| 15404 |
} |
| 15405 |
return html; |
| 15406 |
} |
| 15407 |
}; |
| 15408 |
|
| 15409 |
/** |
| 15410 |
* unescape a string. |
| 15411 |
* @param {String} escapedText |
| 15412 |
* @return {String} text |
| 15413 |
* @private |
| 15414 |
*/ |
| 15415 |
Node.prototype._unescapeHTML = function (escapedText) { |
| 15416 |
var json = '"' + this._escapeJSON(escapedText) + '"'; |
| 15417 |
var htmlEscaped = util.parse(json); |
| 15418 |
|
| 15419 |
return htmlEscaped |
| 15420 |
.replace(/</g, '<') |
| 15421 |
.replace(/>/g, '>') |
| 15422 |
.replace(/ |\u00A0/g, ' ') |
| 15423 |
.replace(/&/g, '&'); // must be replaced last |
| 15424 |
}; |
| 15425 |
|
| 15426 |
/** |
| 15427 |
* escape a text to make it a valid JSON string. The method will: |
| 15428 |
* - replace unescaped double quotes with '\"' |
| 15429 |
* - replace unescaped backslash with '\\' |
| 15430 |
* - replace returns with '\n' |
| 15431 |
* @param {String} text |
| 15432 |
* @return {String} escapedText |
| 15433 |
* @private |
| 15434 |
*/ |
| 15435 |
Node.prototype._escapeJSON = function (text) { |
| 15436 |
// TODO: replace with some smart regex (only when a new solution is faster!) |
| 15437 |
var escaped = ''; |
| 15438 |
var i = 0; |
| 15439 |
while (i < text.length) { |
| 15440 |
var c = text.charAt(i); |
| 15441 |
if (c == '\n') { |
| 15442 |
escaped += '\\n'; |
| 15443 |
} |
| 15444 |
else if (c == '\\') { |
| 15445 |
escaped += c; |
| 15446 |
i++; |
| 15447 |
|
| 15448 |
c = text.charAt(i); |
| 15449 |
if (c === '' || '"\\/bfnrtu'.indexOf(c) == -1) { |
| 15450 |
escaped += '\\'; // no valid escape character |
| 15451 |
} |
| 15452 |
escaped += c; |
| 15453 |
} |
| 15454 |
else if (c == '"') { |
| 15455 |
escaped += '\\"'; |
| 15456 |
} |
| 15457 |
else { |
| 15458 |
escaped += c; |
| 15459 |
} |
| 15460 |
i++; |
| 15461 |
} |
| 15462 |
|
| 15463 |
return escaped; |
| 15464 |
}; |
| 15465 |
|
| 15466 |
// TODO: find a nicer solution to resolve this circular dependency between Node and AppendNode |
| 15467 |
var AppendNode = appendNodeFactory(Node); |
| 15468 |
|
| 15469 |
module.exports = Node; |
| 15470 |
|
| 15471 |
|
| 15472 |
/***/ }, |
| 15473 |
/* 59 */ |
| 15474 |
/***/ function(module, exports) { |
| 15475 |
|
| 15476 |
/* |
| 15477 |
* Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license |
| 15478 |
* Author: Jim Palmer (based on chunking idea from Dave Koelle) |
| 15479 |
*/ |
| 15480 |
/*jshint unused:false */ |
| 15481 |
module.exports = function naturalSort (a, b) { |
| 15482 |
"use strict"; |
| 15483 |
var re = /(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi, |
| 15484 |
sre = /(^[ ]*|[ ]*$)/g, |
| 15485 |
dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/, |
| 15486 |
hre = /^0x[0-9a-f]+$/i, |
| 15487 |
ore = /^0/, |
| 15488 |
i = function(s) { return naturalSort.insensitive && ('' + s).toLowerCase() || '' + s; }, |
| 15489 |
// convert all to strings strip whitespace |
| 15490 |
x = i(a).replace(sre, '') || '', |
| 15491 |
y = i(b).replace(sre, '') || '', |
| 15492 |
// chunk/tokenize |
| 15493 |
xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), |
| 15494 |
yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'), |
| 15495 |
// numeric, hex or date detection |
| 15496 |
xD = parseInt(x.match(hre), 16) || (xN.length !== 1 && x.match(dre) && Date.parse(x)), |
| 15497 |
yD = parseInt(y.match(hre), 16) || xD && y.match(dre) && Date.parse(y) || null, |
| 15498 |
oFxNcL, oFyNcL; |
| 15499 |
// first try and sort Hex codes or Dates |
| 15500 |
if (yD) { |
| 15501 |
if ( xD < yD ) { return -1; } |
| 15502 |
else if ( xD > yD ) { return 1; } |
| 15503 |
} |
| 15504 |
// natural sorting through split numeric strings and default strings |
| 15505 |
for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) { |
| 15506 |
// find floats not starting with '0', string or 0 if not defined (Clint Priest) |
| 15507 |
oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0; |
| 15508 |
oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; |
| 15509 |
// handle numeric vs string comparison - number < string - (Kyle Adams) |
| 15510 |
if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { return (isNaN(oFxNcL)) ? 1 : -1; } |
| 15511 |
// rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' |
| 15512 |
else if (typeof oFxNcL !== typeof oFyNcL) { |
| 15513 |
oFxNcL += ''; |
| 15514 |
oFyNcL += ''; |
| 15515 |
} |
| 15516 |
if (oFxNcL < oFyNcL) { return -1; } |
| 15517 |
if (oFxNcL > oFyNcL) { return 1; } |
| 15518 |
} |
| 15519 |
return 0; |
| 15520 |
}; |
| 15521 |
|
| 15522 |
|
| 15523 |
/***/ }, |
| 15524 |
/* 60 */ |
| 15525 |
/***/ function(module, exports, __webpack_require__) { |
| 15526 |
|
| 15527 |
'use strict'; |
| 15528 |
|
| 15529 |
var util = __webpack_require__(54); |
| 15530 |
var ContextMenu = __webpack_require__(57); |
| 15531 |
|
| 15532 |
/** |
| 15533 |
* A factory function to create an AppendNode, which depends on a Node |
| 15534 |
* @param {Node} Node |
| 15535 |
*/ |
| 15536 |
function appendNodeFactory(Node) { |
| 15537 |
/** |
| 15538 |
* @constructor AppendNode |
| 15539 |
* @extends Node |
| 15540 |
* @param {TreeEditor} editor |
| 15541 |
* Create a new AppendNode. This is a special node which is created at the |
| 15542 |
* end of the list with childs for an object or array |
| 15543 |
*/ |
| 15544 |
function AppendNode (editor) { |
| 15545 |
/** @type {TreeEditor} */ |
| 15546 |
this.editor = editor; |
| 15547 |
this.dom = {}; |
| 15548 |
} |
| 15549 |
|
| 15550 |
AppendNode.prototype = new Node(); |
| 15551 |
|
| 15552 |
/** |
| 15553 |
* Return a table row with an append button. |
| 15554 |
* @return {Element} dom TR element |
| 15555 |
*/ |
| 15556 |
AppendNode.prototype.getDom = function () { |
| 15557 |
// TODO: implement a new solution for the append node |
| 15558 |
var dom = this.dom; |
| 15559 |
|
| 15560 |
if (dom.tr) { |
| 15561 |
return dom.tr; |
| 15562 |
} |
| 15563 |
|
| 15564 |
this._updateEditability(); |
| 15565 |
|
| 15566 |
// a row for the append button |
| 15567 |
var trAppend = document.createElement('tr'); |
| 15568 |
trAppend.node = this; |
| 15569 |
dom.tr = trAppend; |
| 15570 |
|
| 15571 |
// TODO: consistent naming |
| 15572 |
|
| 15573 |
if (this.editor.options.mode === 'tree') { |
| 15574 |
// a cell for the dragarea column |
| 15575 |
dom.tdDrag = document.createElement('td'); |
| 15576 |
|
| 15577 |
// create context menu |
| 15578 |
var tdMenu = document.createElement('td'); |
| 15579 |
dom.tdMenu = tdMenu; |
| 15580 |
var menu = document.createElement('button'); |
| 15581 |
menu.type = 'button'; |
| 15582 |
menu.className = 'jsoneditor-contextmenu'; |
| 15583 |
menu.title = 'Click to open the actions menu (Ctrl+M)'; |
| 15584 |
dom.menu = menu; |
| 15585 |
tdMenu.appendChild(dom.menu); |
| 15586 |
} |
| 15587 |
|
| 15588 |
// a cell for the contents (showing text 'empty') |
| 15589 |
var tdAppend = document.createElement('td'); |
| 15590 |
var domText = document.createElement('div'); |
| 15591 |
domText.innerHTML = '(empty)'; |
| 15592 |
domText.className = 'jsoneditor-readonly'; |
| 15593 |
tdAppend.appendChild(domText); |
| 15594 |
dom.td = tdAppend; |
| 15595 |
dom.text = domText; |
| 15596 |
|
| 15597 |
this.updateDom(); |
| 15598 |
|
| 15599 |
return trAppend; |
| 15600 |
}; |
| 15601 |
|
| 15602 |
/** |
| 15603 |
* Update the HTML dom of the Node |
| 15604 |
*/ |
| 15605 |
AppendNode.prototype.updateDom = function () { |
| 15606 |
var dom = this.dom; |
| 15607 |
var tdAppend = dom.td; |
| 15608 |
if (tdAppend) { |
| 15609 |
tdAppend.style.paddingLeft = (this.getLevel() * 24 + 26) + 'px'; |
| 15610 |
// TODO: not so nice hard coded offset |
| 15611 |
} |
| 15612 |
|
| 15613 |
var domText = dom.text; |
| 15614 |
if (domText) { |
| 15615 |
domText.innerHTML = '(empty ' + this.parent.type + ')'; |
| 15616 |
} |
| 15617 |
|
| 15618 |
// attach or detach the contents of the append node: |
| 15619 |
// hide when the parent has childs, show when the parent has no childs |
| 15620 |
var trAppend = dom.tr; |
| 15621 |
if (!this.isVisible()) { |
| 15622 |
if (dom.tr.firstChild) { |
| 15623 |
if (dom.tdDrag) { |
| 15624 |
trAppend.removeChild(dom.tdDrag); |
| 15625 |
} |
| 15626 |
if (dom.tdMenu) { |
| 15627 |
trAppend.removeChild(dom.tdMenu); |
| 15628 |
} |
| 15629 |
trAppend.removeChild(tdAppend); |
| 15630 |
} |
| 15631 |
} |
| 15632 |
else { |
| 15633 |
if (!dom.tr.firstChild) { |
| 15634 |
if (dom.tdDrag) { |
| 15635 |
trAppend.appendChild(dom.tdDrag); |
| 15636 |
} |
| 15637 |
if (dom.tdMenu) { |
| 15638 |
trAppend.appendChild(dom.tdMenu); |
| 15639 |
} |
| 15640 |
trAppend.appendChild(tdAppend); |
| 15641 |
} |
| 15642 |
} |
| 15643 |
}; |
| 15644 |
|
| 15645 |
/** |
| 15646 |
* Check whether the AppendNode is currently visible. |
| 15647 |
* the AppendNode is visible when its parent has no childs (i.e. is empty). |
| 15648 |
* @return {boolean} isVisible |
| 15649 |
*/ |
| 15650 |
AppendNode.prototype.isVisible = function () { |
| 15651 |
return (this.parent.childs.length == 0); |
| 15652 |
}; |
| 15653 |
|
| 15654 |
/** |
| 15655 |
* Show a contextmenu for this node |
| 15656 |
* @param {HTMLElement} anchor The element to attach the menu to. |
| 15657 |
* @param {function} [onClose] Callback method called when the context menu |
| 15658 |
* is being closed. |
| 15659 |
*/ |
| 15660 |
AppendNode.prototype.showContextMenu = function (anchor, onClose) { |
| 15661 |
var node = this; |
| 15662 |
var titles = Node.TYPE_TITLES; |
| 15663 |
var items = [ |
| 15664 |
// create append button |
| 15665 |
{ |
| 15666 |
'text': 'Append', |
| 15667 |
'title': 'Append a new field with type \'auto\' (Ctrl+Shift+Ins)', |
| 15668 |
'submenuTitle': 'Select the type of the field to be appended', |
| 15669 |
'className': 'jsoneditor-insert', |
| 15670 |
'click': function () { |
| 15671 |
node._onAppend('', '', 'auto'); |
| 15672 |
}, |
| 15673 |
'submenu': [ |
| 15674 |
{ |
| 15675 |
'text': 'Auto', |
| 15676 |
'className': 'jsoneditor-type-auto', |
| 15677 |
'title': titles.auto, |
| 15678 |
'click': function () { |
| 15679 |
node._onAppend('', '', 'auto'); |
| 15680 |
} |
| 15681 |
}, |
| 15682 |
{ |
| 15683 |
'text': 'Array', |
| 15684 |
'className': 'jsoneditor-type-array', |
| 15685 |
'title': titles.array, |
| 15686 |
'click': function () { |
| 15687 |
node._onAppend('', []); |
| 15688 |
} |
| 15689 |
}, |
| 15690 |
{ |
| 15691 |
'text': 'Object', |
| 15692 |
'className': 'jsoneditor-type-object', |
| 15693 |
'title': titles.object, |
| 15694 |
'click': function () { |
| 15695 |
node._onAppend('', {}); |
| 15696 |
} |
| 15697 |
}, |
| 15698 |
{ |
| 15699 |
'text': 'String', |
| 15700 |
'className': 'jsoneditor-type-string', |
| 15701 |
'title': titles.string, |
| 15702 |
'click': function () { |
| 15703 |
node._onAppend('', '', 'string'); |
| 15704 |
} |
| 15705 |
} |
| 15706 |
] |
| 15707 |
} |
| 15708 |
]; |
| 15709 |
|
| 15710 |
var menu = new ContextMenu(items, {close: onClose}); |
| 15711 |
menu.show(anchor, this.editor.content); |
| 15712 |
}; |
| 15713 |
|
| 15714 |
/** |
| 15715 |
* Handle an event. The event is catched centrally by the editor |
| 15716 |
* @param {Event} event |
| 15717 |
*/ |
| 15718 |
AppendNode.prototype.onEvent = function (event) { |
| 15719 |
var type = event.type; |
| 15720 |
var target = event.target || event.srcElement; |
| 15721 |
var dom = this.dom; |
| 15722 |
|
| 15723 |
// highlight the append nodes parent |
| 15724 |
var menu = dom.menu; |
| 15725 |
if (target == menu) { |
| 15726 |
if (type == 'mouseover') { |
| 15727 |
this.editor.highlighter.highlight(this.parent); |
| 15728 |
} |
| 15729 |
else if (type == 'mouseout') { |
| 15730 |
this.editor.highlighter.unhighlight(); |
| 15731 |
} |
| 15732 |
} |
| 15733 |
|
| 15734 |
// context menu events |
| 15735 |
if (type == 'click' && target == dom.menu) { |
| 15736 |
var highlighter = this.editor.highlighter; |
| 15737 |
highlighter.highlight(this.parent); |
| 15738 |
highlighter.lock(); |
| 15739 |
util.addClassName(dom.menu, 'jsoneditor-selected'); |
| 15740 |
this.showContextMenu(dom.menu, function () { |
| 15741 |
util.removeClassName(dom.menu, 'jsoneditor-selected'); |
| 15742 |
highlighter.unlock(); |
| 15743 |
highlighter.unhighlight(); |
| 15744 |
}); |
| 15745 |
} |
| 15746 |
|
| 15747 |
if (type == 'keydown') { |
| 15748 |
this.onKeyDown(event); |
| 15749 |
} |
| 15750 |
}; |
| 15751 |
|
| 15752 |
return AppendNode; |
| 15753 |
} |
| 15754 |
|
| 15755 |
module.exports = appendNodeFactory; |
| 15756 |
|
| 15757 |
|
| 15758 |
/***/ }, |
| 15759 |
/* 61 */ |
| 15760 |
/***/ function(module, exports, __webpack_require__) { |
| 15761 |
|
| 15762 |
'use strict'; |
| 15763 |
|
| 15764 |
var ContextMenu = __webpack_require__(57); |
| 15765 |
|
| 15766 |
/** |
| 15767 |
* Create a select box to be used in the editor menu's, which allows to switch mode |
| 15768 |
* @param {HTMLElement} container |
| 15769 |
* @param {String[]} modes Available modes: 'code', 'form', 'text', 'tree', 'view' |
| 15770 |
* @param {String} current Available modes: 'code', 'form', 'text', 'tree', 'view' |
| 15771 |
* @param {function(mode: string)} onSwitch Callback invoked on switch |
| 15772 |
* @constructor |
| 15773 |
*/ |
| 15774 |
function ModeSwitcher(container, modes, current, onSwitch) { |
| 15775 |
// available modes |
| 15776 |
var availableModes = { |
| 15777 |
code: { |
| 15778 |
'text': 'Code', |
| 15779 |
'title': 'Switch to code highlighter', |
| 15780 |
'click': function () { |
| 15781 |
onSwitch('code') |
| 15782 |
} |
| 15783 |
}, |
| 15784 |
form: { |
| 15785 |
'text': 'Form', |
| 15786 |
'title': 'Switch to form editor', |
| 15787 |
'click': function () { |
| 15788 |
onSwitch('form'); |
| 15789 |
} |
| 15790 |
}, |
| 15791 |
text: { |
| 15792 |
'text': 'Text', |
| 15793 |
'title': 'Switch to plain text editor', |
| 15794 |
'click': function () { |
| 15795 |
onSwitch('text'); |
| 15796 |
} |
| 15797 |
}, |
| 15798 |
tree: { |
| 15799 |
'text': 'Tree', |
| 15800 |
'title': 'Switch to tree editor', |
| 15801 |
'click': function () { |
| 15802 |
onSwitch('tree'); |
| 15803 |
} |
| 15804 |
}, |
| 15805 |
view: { |
| 15806 |
'text': 'View', |
| 15807 |
'title': 'Switch to tree view', |
| 15808 |
'click': function () { |
| 15809 |
onSwitch('view'); |
| 15810 |
} |
| 15811 |
} |
| 15812 |
}; |
| 15813 |
|
| 15814 |
// list the selected modes |
| 15815 |
var items = []; |
| 15816 |
for (var i = 0; i < modes.length; i++) { |
| 15817 |
var mode = modes[i]; |
| 15818 |
var item = availableModes[mode]; |
| 15819 |
if (!item) { |
| 15820 |
throw new Error('Unknown mode "' + mode + '"'); |
| 15821 |
} |
| 15822 |
|
| 15823 |
item.className = 'jsoneditor-type-modes' + ((current == mode) ? ' jsoneditor-selected' : ''); |
| 15824 |
items.push(item); |
| 15825 |
} |
| 15826 |
|
| 15827 |
// retrieve the title of current mode |
| 15828 |
var currentMode = availableModes[current]; |
| 15829 |
if (!currentMode) { |
| 15830 |
throw new Error('Unknown mode "' + current + '"'); |
| 15831 |
} |
| 15832 |
var currentTitle = currentMode.text; |
| 15833 |
|
| 15834 |
// create the html element |
| 15835 |
var box = document.createElement('button'); |
| 15836 |
box.type = 'button'; |
| 15837 |
box.className = 'jsoneditor-modes jsoneditor-separator'; |
| 15838 |
box.innerHTML = currentTitle + ' ▾'; |
| 15839 |
box.title = 'Switch editor mode'; |
| 15840 |
box.onclick = function () { |
| 15841 |
var menu = new ContextMenu(items); |
| 15842 |
menu.show(box); |
| 15843 |
}; |
| 15844 |
|
| 15845 |
var frame = document.createElement('div'); |
| 15846 |
frame.className = 'jsoneditor-modes'; |
| 15847 |
frame.style.position = 'relative'; |
| 15848 |
frame.appendChild(box); |
| 15849 |
|
| 15850 |
container.appendChild(frame); |
| 15851 |
|
| 15852 |
this.dom = { |
| 15853 |
container: container, |
| 15854 |
box: box, |
| 15855 |
frame: frame |
| 15856 |
}; |
| 15857 |
} |
| 15858 |
|
| 15859 |
/** |
| 15860 |
* Set focus to switcher |
| 15861 |
*/ |
| 15862 |
ModeSwitcher.prototype.focus = function () { |
| 15863 |
this.dom.box.focus(); |
| 15864 |
}; |
| 15865 |
|
| 15866 |
/** |
| 15867 |
* Destroy the ModeSwitcher, remove from DOM |
| 15868 |
*/ |
| 15869 |
ModeSwitcher.prototype.destroy = function () { |
| 15870 |
if (this.dom && this.dom.frame && this.dom.frame.parentNode) { |
| 15871 |
this.dom.frame.parentNode.removeChild(this.dom.frame); |
| 15872 |
} |
| 15873 |
this.dom = null; |
| 15874 |
}; |
| 15875 |
|
| 15876 |
module.exports = ModeSwitcher; |
| 15877 |
|
| 15878 |
|
| 15879 |
/***/ }, |
| 15880 |
/* 62 */ |
| 15881 |
/***/ function(module, exports, __webpack_require__) { |
| 15882 |
|
| 15883 |
'use strict'; |
| 15884 |
|
| 15885 |
var ace; |
| 15886 |
try { |
| 15887 |
ace = __webpack_require__(63); |
| 15888 |
} |
| 15889 |
catch (err) { |
| 15890 |
// failed to load ace, no problem, we will fall back to plain text |
| 15891 |
} |
| 15892 |
|
| 15893 |
var ModeSwitcher = __webpack_require__(61); |
| 15894 |
var util = __webpack_require__(54); |
| 15895 |
|
| 15896 |
// create a mixin with the functions for text mode |
| 15897 |
var textmode = {}; |
| 15898 |
|
| 15899 |
var MAX_ERRORS = 3; // maximum number of displayed errors at the bottom |
| 15900 |
|
| 15901 |
var DEFAULT_THEME = 'ace/theme/jsoneditor'; |
| 15902 |
|
| 15903 |
/** |
| 15904 |
* Create a text editor |
| 15905 |
* @param {Element} container |
| 15906 |
* @param {Object} [options] Object with options. available options: |
| 15907 |
* {String} mode Available values: |
| 15908 |
* "text" (default) |
| 15909 |
* or "code". |
| 15910 |
* {Number} indentation Number of indentation |
| 15911 |
* spaces. 2 by default. |
| 15912 |
* {function} onChange Callback method |
| 15913 |
* triggered on change |
| 15914 |
* {function} onModeChange Callback method |
| 15915 |
* triggered after setMode |
| 15916 |
* {Object} ace A custom instance of |
| 15917 |
* Ace editor. |
| 15918 |
* {boolean} escapeUnicode If true, unicode |
| 15919 |
* characters are escaped. |
| 15920 |
* false by default. |
| 15921 |
* @private |
| 15922 |
*/ |
| 15923 |
textmode.create = function (container, options) { |
| 15924 |
// read options |
| 15925 |
options = options || {}; |
| 15926 |
this.options = options; |
| 15927 |
|
| 15928 |
// indentation |
| 15929 |
if (options.indentation) { |
| 15930 |
this.indentation = Number(options.indentation); |
| 15931 |
} |
| 15932 |
else { |
| 15933 |
this.indentation = 2; // number of spaces |
| 15934 |
} |
| 15935 |
|
| 15936 |
// grab ace from options if provided |
| 15937 |
var _ace = options.ace ? options.ace : ace; |
| 15938 |
|
| 15939 |
// determine mode |
| 15940 |
this.mode = (options.mode == 'code') ? 'code' : 'text'; |
| 15941 |
if (this.mode == 'code') { |
| 15942 |
// verify whether Ace editor is available and supported |
| 15943 |
if (typeof _ace === 'undefined') { |
| 15944 |
this.mode = 'text'; |
| 15945 |
console.warn('Failed to load Ace editor, falling back to plain text mode. Please use a JSONEditor bundle including Ace, or pass Ace as via the configuration option `ace`.'); |
| 15946 |
} |
| 15947 |
} |
| 15948 |
|
| 15949 |
// determine theme |
| 15950 |
this.theme = options.theme || DEFAULT_THEME; |
| 15951 |
if (this.theme === DEFAULT_THEME && window.ace) { |
| 15952 |
__webpack_require__(70); |
| 15953 |
} |
| 15954 |
|
| 15955 |
var me = this; |
| 15956 |
this.container = container; |
| 15957 |
this.dom = {}; |
| 15958 |
this.aceEditor = undefined; // ace code editor |
| 15959 |
this.textarea = undefined; // plain text editor (fallback when Ace is not available) |
| 15960 |
this.validateSchema = null; |
| 15961 |
|
| 15962 |
// create a debounced validate function |
| 15963 |
this._debouncedValidate = util.debounce(this.validate.bind(this), this.DEBOUNCE_INTERVAL); |
| 15964 |
|
| 15965 |
this.width = container.clientWidth; |
| 15966 |
this.height = container.clientHeight; |
| 15967 |
|
| 15968 |
this.frame = document.createElement('div'); |
| 15969 |
this.frame.className = 'jsoneditor jsoneditor-mode-' + this.options.mode; |
| 15970 |
this.frame.onclick = function (event) { |
| 15971 |
// prevent default submit action when the editor is located inside a form |
| 15972 |
event.preventDefault(); |
| 15973 |
}; |
| 15974 |
this.frame.onkeydown = function (event) { |
| 15975 |
me._onKeyDown(event); |
| 15976 |
}; |
| 15977 |
|
| 15978 |
// create menu |
| 15979 |
this.menu = document.createElement('div'); |
| 15980 |
this.menu.className = 'jsoneditor-menu'; |
| 15981 |
this.frame.appendChild(this.menu); |
| 15982 |
|
| 15983 |
// create format button |
| 15984 |
var buttonFormat = document.createElement('button'); |
| 15985 |
buttonFormat.type = 'button'; |
| 15986 |
buttonFormat.className = 'jsoneditor-format'; |
| 15987 |
buttonFormat.title = 'Format JSON data, with proper indentation and line feeds (Ctrl+\\)'; |
| 15988 |
this.menu.appendChild(buttonFormat); |
| 15989 |
buttonFormat.onclick = function () { |
| 15990 |
try { |
| 15991 |
me.format(); |
| 15992 |
me._onChange(); |
| 15993 |
} |
| 15994 |
catch (err) { |
| 15995 |
me._onError(err); |
| 15996 |
} |
| 15997 |
}; |
| 15998 |
|
| 15999 |
// create compact button |
| 16000 |
var buttonCompact = document.createElement('button'); |
| 16001 |
buttonCompact.type = 'button'; |
| 16002 |
buttonCompact.className = 'jsoneditor-compact'; |
| 16003 |
buttonCompact.title = 'Compact JSON data, remove all whitespaces (Ctrl+Shift+\\)'; |
| 16004 |
this.menu.appendChild(buttonCompact); |
| 16005 |
buttonCompact.onclick = function () { |
| 16006 |
try { |
| 16007 |
me.compact(); |
| 16008 |
me._onChange(); |
| 16009 |
} |
| 16010 |
catch (err) { |
| 16011 |
me._onError(err); |
| 16012 |
} |
| 16013 |
}; |
| 16014 |
|
| 16015 |
// create mode box |
| 16016 |
if (this.options && this.options.modes && this.options.modes.length) { |
| 16017 |
this.modeSwitcher = new ModeSwitcher(this.menu, this.options.modes, this.options.mode, function onSwitch(mode) { |
| 16018 |
// switch mode and restore focus |
| 16019 |
me.setMode(mode); |
| 16020 |
me.modeSwitcher.focus(); |
| 16021 |
}); |
| 16022 |
} |
| 16023 |
|
| 16024 |
this.content = document.createElement('div'); |
| 16025 |
this.content.className = 'jsoneditor-outer'; |
| 16026 |
this.frame.appendChild(this.content); |
| 16027 |
|
| 16028 |
this.container.appendChild(this.frame); |
| 16029 |
|
| 16030 |
if (this.mode == 'code') { |
| 16031 |
this.editorDom = document.createElement('div'); |
| 16032 |
this.editorDom.style.height = '100%'; // TODO: move to css |
| 16033 |
this.editorDom.style.width = '100%'; // TODO: move to css |
| 16034 |
this.content.appendChild(this.editorDom); |
| 16035 |
|
| 16036 |
var aceEditor = _ace.edit(this.editorDom); |
| 16037 |
aceEditor.$blockScrolling = Infinity; |
| 16038 |
aceEditor.setTheme(this.theme); |
| 16039 |
aceEditor.setShowPrintMargin(false); |
| 16040 |
aceEditor.setFontSize(13); |
| 16041 |
aceEditor.getSession().setMode('ace/mode/json'); |
| 16042 |
aceEditor.getSession().setTabSize(this.indentation); |
| 16043 |
aceEditor.getSession().setUseSoftTabs(true); |
| 16044 |
aceEditor.getSession().setUseWrapMode(true); |
| 16045 |
aceEditor.commands.bindKey('Ctrl-L', null); // disable Ctrl+L (is used by the browser to select the address bar) |
| 16046 |
aceEditor.commands.bindKey('Command-L', null); // disable Ctrl+L (is used by the browser to select the address bar) |
| 16047 |
this.aceEditor = aceEditor; |
| 16048 |
|
| 16049 |
// TODO: deprecated since v5.0.0. Cleanup backward compatibility some day |
| 16050 |
if (!this.hasOwnProperty('editor')) { |
| 16051 |
Object.defineProperty(this, 'editor', { |
| 16052 |
get: function () { |
| 16053 |
console.warn('Property "editor" has been renamed to "aceEditor".'); |
| 16054 |
return me.aceEditor; |
| 16055 |
}, |
| 16056 |
set: function (aceEditor) { |
| 16057 |
console.warn('Property "editor" has been renamed to "aceEditor".'); |
| 16058 |
me.aceEditor = aceEditor; |
| 16059 |
} |
| 16060 |
}); |
| 16061 |
} |
| 16062 |
|
| 16063 |
var poweredBy = document.createElement('a'); |
| 16064 |
poweredBy.appendChild(document.createTextNode('powered by ace')); |
| 16065 |
poweredBy.href = 'http://ace.ajax.org'; |
| 16066 |
poweredBy.target = '_blank'; |
| 16067 |
poweredBy.className = 'jsoneditor-poweredBy'; |
| 16068 |
poweredBy.onclick = function () { |
| 16069 |
// TODO: this anchor falls below the margin of the content, |
| 16070 |
// therefore the normal a.href does not work. We use a click event |
| 16071 |
// for now, but this should be fixed. |
| 16072 |
window.open(poweredBy.href, poweredBy.target); |
| 16073 |
}; |
| 16074 |
this.menu.appendChild(poweredBy); |
| 16075 |
|
| 16076 |
// register onchange event |
| 16077 |
aceEditor.on('change', this._onChange.bind(this)); |
| 16078 |
} |
| 16079 |
else { |
| 16080 |
// load a plain text textarea |
| 16081 |
var textarea = document.createElement('textarea'); |
| 16082 |
textarea.className = 'jsoneditor-text'; |
| 16083 |
textarea.spellcheck = false; |
| 16084 |
this.content.appendChild(textarea); |
| 16085 |
this.textarea = textarea; |
| 16086 |
|
| 16087 |
// register onchange event |
| 16088 |
if (this.textarea.oninput === null) { |
| 16089 |
this.textarea.oninput = this._onChange.bind(this); |
| 16090 |
} |
| 16091 |
else { |
| 16092 |
// oninput is undefined. For IE8- |
| 16093 |
this.textarea.onchange = this._onChange.bind(this); |
| 16094 |
} |
| 16095 |
} |
| 16096 |
|
| 16097 |
this.setSchema(this.options.schema); |
| 16098 |
}; |
| 16099 |
|
| 16100 |
/** |
| 16101 |
* Handle a change: |
| 16102 |
* - Validate JSON schema |
| 16103 |
* - Send a callback to the onChange listener if provided |
| 16104 |
* @private |
| 16105 |
*/ |
| 16106 |
textmode._onChange = function () { |
| 16107 |
// validate JSON schema (if configured) |
| 16108 |
this._debouncedValidate(); |
| 16109 |
|
| 16110 |
// trigger the onChange callback |
| 16111 |
if (this.options.onChange) { |
| 16112 |
try { |
| 16113 |
this.options.onChange(); |
| 16114 |
} |
| 16115 |
catch (err) { |
| 16116 |
console.error('Error in onChange callback: ', err); |
| 16117 |
} |
| 16118 |
} |
| 16119 |
}; |
| 16120 |
|
| 16121 |
/** |
| 16122 |
* Event handler for keydown. Handles shortcut keys |
| 16123 |
* @param {Event} event |
| 16124 |
* @private |
| 16125 |
*/ |
| 16126 |
textmode._onKeyDown = function (event) { |
| 16127 |
var keynum = event.which || event.keyCode; |
| 16128 |
var handled = false; |
| 16129 |
|
| 16130 |
if (keynum == 220 && event.ctrlKey) { |
| 16131 |
if (event.shiftKey) { // Ctrl+Shift+\ |
| 16132 |
this.compact(); |
| 16133 |
this._onChange(); |
| 16134 |
} |
| 16135 |
else { // Ctrl+\ |
| 16136 |
this.format(); |
| 16137 |
this._onChange(); |
| 16138 |
} |
| 16139 |
handled = true; |
| 16140 |
} |
| 16141 |
|
| 16142 |
if (handled) { |
| 16143 |
event.preventDefault(); |
| 16144 |
event.stopPropagation(); |
| 16145 |
} |
| 16146 |
}; |
| 16147 |
|
| 16148 |
/** |
| 16149 |
* Destroy the editor. Clean up DOM, event listeners, and web workers. |
| 16150 |
*/ |
| 16151 |
textmode.destroy = function () { |
| 16152 |
// remove old ace editor |
| 16153 |
if (this.aceEditor) { |
| 16154 |
this.aceEditor.destroy(); |
| 16155 |
this.aceEditor = null; |
| 16156 |
} |
| 16157 |
|
| 16158 |
if (this.frame && this.container && this.frame.parentNode == this.container) { |
| 16159 |
this.container.removeChild(this.frame); |
| 16160 |
} |
| 16161 |
|
| 16162 |
if (this.modeSwitcher) { |
| 16163 |
this.modeSwitcher.destroy(); |
| 16164 |
this.modeSwitcher = null; |
| 16165 |
} |
| 16166 |
|
| 16167 |
this.textarea = null; |
| 16168 |
|
| 16169 |
this._debouncedValidate = null; |
| 16170 |
}; |
| 16171 |
|
| 16172 |
/** |
| 16173 |
* Compact the code in the formatter |
| 16174 |
*/ |
| 16175 |
textmode.compact = function () { |
| 16176 |
var json = this.get(); |
| 16177 |
var text = JSON.stringify(json); |
| 16178 |
this.setText(text); |
| 16179 |
}; |
| 16180 |
|
| 16181 |
/** |
| 16182 |
* Format the code in the formatter |
| 16183 |
*/ |
| 16184 |
textmode.format = function () { |
| 16185 |
var json = this.get(); |
| 16186 |
var text = JSON.stringify(json, null, this.indentation); |
| 16187 |
this.setText(text); |
| 16188 |
}; |
| 16189 |
|
| 16190 |
/** |
| 16191 |
* Set focus to the formatter |
| 16192 |
*/ |
| 16193 |
textmode.focus = function () { |
| 16194 |
if (this.textarea) { |
| 16195 |
this.textarea.focus(); |
| 16196 |
} |
| 16197 |
if (this.aceEditor) { |
| 16198 |
this.aceEditor.focus(); |
| 16199 |
} |
| 16200 |
}; |
| 16201 |
|
| 16202 |
/** |
| 16203 |
* Resize the formatter |
| 16204 |
*/ |
| 16205 |
textmode.resize = function () { |
| 16206 |
if (this.aceEditor) { |
| 16207 |
var force = false; |
| 16208 |
this.aceEditor.resize(force); |
| 16209 |
} |
| 16210 |
}; |
| 16211 |
|
| 16212 |
/** |
| 16213 |
* Set json data in the formatter |
| 16214 |
* @param {Object} json |
| 16215 |
*/ |
| 16216 |
textmode.set = function(json) { |
| 16217 |
this.setText(JSON.stringify(json, null, this.indentation)); |
| 16218 |
}; |
| 16219 |
|
| 16220 |
/** |
| 16221 |
* Get json data from the formatter |
| 16222 |
* @return {Object} json |
| 16223 |
*/ |
| 16224 |
textmode.get = function() { |
| 16225 |
var text = this.getText(); |
| 16226 |
var json; |
| 16227 |
|
| 16228 |
try { |
| 16229 |
json = util.parse(text); // this can throw an error |
| 16230 |
} |
| 16231 |
catch (err) { |
| 16232 |
// try to sanitize json, replace JavaScript notation with JSON notation |
| 16233 |
text = util.sanitize(text); |
| 16234 |
|
| 16235 |
// try to parse again |
| 16236 |
json = util.parse(text); // this can throw an error |
| 16237 |
} |
| 16238 |
|
| 16239 |
return json; |
| 16240 |
}; |
| 16241 |
|
| 16242 |
/** |
| 16243 |
* Get the text contents of the editor |
| 16244 |
* @return {String} jsonText |
| 16245 |
*/ |
| 16246 |
textmode.getText = function() { |
| 16247 |
if (this.textarea) { |
| 16248 |
return this.textarea.value; |
| 16249 |
} |
| 16250 |
if (this.aceEditor) { |
| 16251 |
return this.aceEditor.getValue(); |
| 16252 |
} |
| 16253 |
return ''; |
| 16254 |
}; |
| 16255 |
|
| 16256 |
/** |
| 16257 |
* Set the text contents of the editor |
| 16258 |
* @param {String} jsonText |
| 16259 |
*/ |
| 16260 |
textmode.setText = function(jsonText) { |
| 16261 |
var text; |
| 16262 |
|
| 16263 |
if (this.options.escapeUnicode === true) { |
| 16264 |
text = util.escapeUnicodeChars(jsonText); |
| 16265 |
} |
| 16266 |
else { |
| 16267 |
text = jsonText; |
| 16268 |
} |
| 16269 |
|
| 16270 |
if (this.textarea) { |
| 16271 |
this.textarea.value = text; |
| 16272 |
} |
| 16273 |
if (this.aceEditor) { |
| 16274 |
// prevent emitting onChange events while setting new text |
| 16275 |
var originalOnChange = this.options.onChange; |
| 16276 |
this.options.onChange = null; |
| 16277 |
|
| 16278 |
this.aceEditor.setValue(text, -1); |
| 16279 |
|
| 16280 |
this.options.onChange = originalOnChange; |
| 16281 |
} |
| 16282 |
|
| 16283 |
// validate JSON schema |
| 16284 |
this.validate(); |
| 16285 |
}; |
| 16286 |
|
| 16287 |
/** |
| 16288 |
* Validate current JSON object against the configured JSON schema |
| 16289 |
* Throws an exception when no JSON schema is configured |
| 16290 |
*/ |
| 16291 |
textmode.validate = function () { |
| 16292 |
// clear all current errors |
| 16293 |
if (this.dom.validationErrors) { |
| 16294 |
this.dom.validationErrors.parentNode.removeChild(this.dom.validationErrors); |
| 16295 |
this.dom.validationErrors = null; |
| 16296 |
|
| 16297 |
this.content.style.marginBottom = ''; |
| 16298 |
this.content.style.paddingBottom = ''; |
| 16299 |
} |
| 16300 |
|
| 16301 |
var doValidate = false; |
| 16302 |
var errors = []; |
| 16303 |
var json; |
| 16304 |
try { |
| 16305 |
json = this.get(); // this can fail when there is no valid json |
| 16306 |
doValidate = true; |
| 16307 |
} |
| 16308 |
catch (err) { |
| 16309 |
// no valid JSON, don't validate |
| 16310 |
} |
| 16311 |
|
| 16312 |
// only validate the JSON when parsing the JSON succeeded |
| 16313 |
if (doValidate && this.validateSchema) { |
| 16314 |
var valid = this.validateSchema(json); |
| 16315 |
if (!valid) { |
| 16316 |
errors = this.validateSchema.errors.map(function (error) { |
| 16317 |
return util.improveSchemaError(error); |
| 16318 |
}); |
| 16319 |
} |
| 16320 |
} |
| 16321 |
|
| 16322 |
if (errors.length > 0) { |
| 16323 |
// limit the number of displayed errors |
| 16324 |
var limit = errors.length > MAX_ERRORS; |
| 16325 |
if (limit) { |
| 16326 |
errors = errors.slice(0, MAX_ERRORS); |
| 16327 |
var hidden = this.validateSchema.errors.length - MAX_ERRORS; |
| 16328 |
errors.push('(' + hidden + ' more errors...)') |
| 16329 |
} |
| 16330 |
|
| 16331 |
var validationErrors = document.createElement('div'); |
| 16332 |
validationErrors.innerHTML = '<table class="jsoneditor-text-errors">' + |
| 16333 |
'<tbody>' + |
| 16334 |
errors.map(function (error) { |
| 16335 |
var message; |
| 16336 |
if (typeof error === 'string') { |
| 16337 |
message = '<td colspan="2"><pre>' + error + '</pre></td>'; |
| 16338 |
} |
| 16339 |
else { |
| 16340 |
message = '<td>' + error.dataPath + '</td>' + |
| 16341 |
'<td>' + error.message + '</td>'; |
| 16342 |
} |
| 16343 |
|
| 16344 |
return '<tr><td><button class="jsoneditor-schema-error"></button></td>' + message + '</tr>' |
| 16345 |
}).join('') + |
| 16346 |
'</tbody>' + |
| 16347 |
'</table>'; |
| 16348 |
|
| 16349 |
this.dom.validationErrors = validationErrors; |
| 16350 |
this.frame.appendChild(validationErrors); |
| 16351 |
|
| 16352 |
var height = validationErrors.clientHeight; |
| 16353 |
this.content.style.marginBottom = (-height) + 'px'; |
| 16354 |
this.content.style.paddingBottom = height + 'px'; |
| 16355 |
} |
| 16356 |
|
| 16357 |
// update the height of the ace editor |
| 16358 |
if (this.aceEditor) { |
| 16359 |
var force = false; |
| 16360 |
this.aceEditor.resize(force); |
| 16361 |
} |
| 16362 |
}; |
| 16363 |
|
| 16364 |
// define modes |
| 16365 |
module.exports = [ |
| 16366 |
{ |
| 16367 |
mode: 'text', |
| 16368 |
mixin: textmode, |
| 16369 |
data: 'text', |
| 16370 |
load: textmode.format |
| 16371 |
}, |
| 16372 |
{ |
| 16373 |
mode: 'code', |
| 16374 |
mixin: textmode, |
| 16375 |
data: 'text', |
| 16376 |
load: textmode.format |
| 16377 |
} |
| 16378 |
]; |
| 16379 |
|
| 16380 |
|
| 16381 |
/***/ }, |
| 16382 |
/* 63 */ |
| 16383 |
/***/ function(module, exports, __webpack_require__) { |
| 16384 |
|
| 16385 |
// load brace |
| 16386 |
var ace = __webpack_require__(64); |
| 16387 |
|
| 16388 |
// load required ace modules |
| 16389 |
__webpack_require__(67); |
| 16390 |
__webpack_require__(69); |
| 16391 |
|
| 16392 |
module.exports = ace; |
| 16393 |
|
| 16394 |
|
| 16395 |
/***/ }, |
| 16396 |
/* 64 */ |
| 16397 |
/***/ function(module, exports, __webpack_require__) { |
| 16398 |
|
| 16399 |
/* ***** BEGIN LICENSE BLOCK ***** |
| 16400 |
* Distributed under the BSD license: |
| 16401 |
* |
| 16402 |
* Copyright (c) 2010, Ajax.org B.V. |
| 16403 |
* All rights reserved. |
| 16404 |
* |
| 16405 |
* Redistribution and use in source and binary forms, with or without |
| 16406 |
* modification, are permitted provided that the following conditions are met: |
| 16407 |
* * Redistributions of source code must retain the above copyright |
| 16408 |
* notice, this list of conditions and the following disclaimer. |
| 16409 |
* * Redistributions in binary form must reproduce the above copyright |
| 16410 |
* notice, this list of conditions and the following disclaimer in the |
| 16411 |
* documentation and/or other materials provided with the distribution. |
| 16412 |
* * Neither the name of Ajax.org B.V. nor the |
| 16413 |
* names of its contributors may be used to endorse or promote products |
| 16414 |
* derived from this software without specific prior written permission. |
| 16415 |
* |
| 16416 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 16417 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16418 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16419 |
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY |
| 16420 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 16421 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 16422 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 16423 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 16424 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 16425 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 16426 |
* |
| 16427 |
* ***** END LICENSE BLOCK ***** */ |
| 16428 |
|
| 16429 |
/** |
| 16430 |
* Define a module along with a payload |
| 16431 |
* @param module a name for the payload |
| 16432 |
* @param payload a function to call with (acequire, exports, module) params |
| 16433 |
*/ |
| 16434 |
|
| 16435 |
(function() { |
| 16436 |
|
| 16437 |
var ACE_NAMESPACE = "ace"; |
| 16438 |
|
| 16439 |
var global = (function() { return this; })(); |
| 16440 |
if (!global && typeof window != "undefined") global = window; // strict mode |
| 16441 |
|
| 16442 |
|
| 16443 |
if (!ACE_NAMESPACE && typeof acequirejs !== "undefined") |
| 16444 |
return; |
| 16445 |
|
| 16446 |
|
| 16447 |
var define = function(module, deps, payload) { |
| 16448 |
if (typeof module !== "string") { |
| 16449 |
if (define.original) |
| 16450 |
define.original.apply(this, arguments); |
| 16451 |
else { |
| 16452 |
console.error("dropping module because define wasn\'t a string."); |
| 16453 |
console.trace(); |
| 16454 |
} |
| 16455 |
return; |
| 16456 |
} |
| 16457 |
if (arguments.length == 2) |
| 16458 |
payload = deps; |
| 16459 |
if (!define.modules[module]) { |
| 16460 |
define.payloads[module] = payload; |
| 16461 |
define.modules[module] = null; |
| 16462 |
} |
| 16463 |
}; |
| 16464 |
|
| 16465 |
define.modules = {}; |
| 16466 |
define.payloads = {}; |
| 16467 |
|
| 16468 |
/** |
| 16469 |
* Get at functionality define()ed using the function above |
| 16470 |
*/ |
| 16471 |
var _acequire = function(parentId, module, callback) { |
| 16472 |
if (typeof module === "string") { |
| 16473 |
var payload = lookup(parentId, module); |
| 16474 |
if (payload != undefined) { |
| 16475 |
callback && callback(); |
| 16476 |
return payload; |
| 16477 |
} |
| 16478 |
} else if (Object.prototype.toString.call(module) === "[object Array]") { |
| 16479 |
var params = []; |
| 16480 |
for (var i = 0, l = module.length; i < l; ++i) { |
| 16481 |
var dep = lookup(parentId, module[i]); |
| 16482 |
if (dep == undefined && acequire.original) |
| 16483 |
return; |
| 16484 |
params.push(dep); |
| 16485 |
} |
| 16486 |
return callback && callback.apply(null, params) || true; |
| 16487 |
} |
| 16488 |
}; |
| 16489 |
|
| 16490 |
var acequire = function(module, callback) { |
| 16491 |
var packagedModule = _acequire("", module, callback); |
| 16492 |
if (packagedModule == undefined && acequire.original) |
| 16493 |
return acequire.original.apply(this, arguments); |
| 16494 |
return packagedModule; |
| 16495 |
}; |
| 16496 |
|
| 16497 |
var normalizeModule = function(parentId, moduleName) { |
| 16498 |
// normalize plugin acequires |
| 16499 |
if (moduleName.indexOf("!") !== -1) { |
| 16500 |
var chunks = moduleName.split("!"); |
| 16501 |
return normalizeModule(parentId, chunks[0]) + "!" + normalizeModule(parentId, chunks[1]); |
| 16502 |
} |
| 16503 |
// normalize relative acequires |
| 16504 |
if (moduleName.charAt(0) == ".") { |
| 16505 |
var base = parentId.split("/").slice(0, -1).join("/"); |
| 16506 |
moduleName = base + "/" + moduleName; |
| 16507 |
|
| 16508 |
while(moduleName.indexOf(".") !== -1 && previous != moduleName) { |
| 16509 |
var previous = moduleName; |
| 16510 |
moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, ""); |
| 16511 |
} |
| 16512 |
} |
| 16513 |
return moduleName; |
| 16514 |
}; |
| 16515 |
|
| 16516 |
/** |
| 16517 |
* Internal function to lookup moduleNames and resolve them by calling the |
| 16518 |
* definition function if needed. |
| 16519 |
*/ |
| 16520 |
var lookup = function(parentId, moduleName) { |
| 16521 |
moduleName = normalizeModule(parentId, moduleName); |
| 16522 |
|
| 16523 |
var module = define.modules[moduleName]; |
| 16524 |
if (!module) { |
| 16525 |
module = define.payloads[moduleName]; |
| 16526 |
if (typeof module === 'function') { |
| 16527 |
var exports = {}; |
| 16528 |
var mod = { |
| 16529 |
id: moduleName, |
| 16530 |
uri: '', |
| 16531 |
exports: exports, |
| 16532 |
packaged: true |
| 16533 |
}; |
| 16534 |
|
| 16535 |
var req = function(module, callback) { |
| 16536 |
return _acequire(moduleName, module, callback); |
| 16537 |
}; |
| 16538 |
|
| 16539 |
var returnValue = module(req, exports, mod); |
| 16540 |
exports = returnValue || mod.exports; |
| 16541 |
define.modules[moduleName] = exports; |
| 16542 |
delete define.payloads[moduleName]; |
| 16543 |
} |
| 16544 |
module = define.modules[moduleName] = exports || module; |
| 16545 |
} |
| 16546 |
return module; |
| 16547 |
}; |
| 16548 |
|
| 16549 |
function exportAce(ns) { |
| 16550 |
var root = global; |
| 16551 |
if (ns) { |
| 16552 |
if (!global[ns]) |
| 16553 |
global[ns] = {}; |
| 16554 |
root = global[ns]; |
| 16555 |
} |
| 16556 |
|
| 16557 |
if (!root.define || !root.define.packaged) { |
| 16558 |
define.original = root.define; |
| 16559 |
root.define = define; |
| 16560 |
root.define.packaged = true; |
| 16561 |
} |
| 16562 |
|
| 16563 |
if (!root.acequire || !root.acequire.packaged) { |
| 16564 |
acequire.original = root.acequire; |
| 16565 |
root.acequire = acequire; |
| 16566 |
root.acequire.packaged = true; |
| 16567 |
} |
| 16568 |
} |
| 16569 |
|
| 16570 |
exportAce(ACE_NAMESPACE); |
| 16571 |
|
| 16572 |
})(); |
| 16573 |
|
| 16574 |
ace.define("ace/lib/regexp",["require","exports","module"], function(acequire, exports, module) { |
| 16575 |
"use strict"; |
| 16576 |
|
| 16577 |
var real = { |
| 16578 |
exec: RegExp.prototype.exec, |
| 16579 |
test: RegExp.prototype.test, |
| 16580 |
match: String.prototype.match, |
| 16581 |
replace: String.prototype.replace, |
| 16582 |
split: String.prototype.split |
| 16583 |
}, |
| 16584 |
compliantExecNpcg = real.exec.call(/()??/, "")[1] === undefined, // check `exec` handling of nonparticipating capturing groups |
| 16585 |
compliantLastIndexIncrement = function () { |
| 16586 |
var x = /^/g; |
| 16587 |
real.test.call(x, ""); |
| 16588 |
return !x.lastIndex; |
| 16589 |
}(); |
| 16590 |
|
| 16591 |
if (compliantLastIndexIncrement && compliantExecNpcg) |
| 16592 |
return; |
| 16593 |
RegExp.prototype.exec = function (str) { |
| 16594 |
var match = real.exec.apply(this, arguments), |
| 16595 |
name, r2; |
| 16596 |
if ( typeof(str) == 'string' && match) { |
| 16597 |
if (!compliantExecNpcg && match.length > 1 && indexOf(match, "") > -1) { |
| 16598 |
r2 = RegExp(this.source, real.replace.call(getNativeFlags(this), "g", "")); |
| 16599 |
real.replace.call(str.slice(match.index), r2, function () { |
| 16600 |
for (var i = 1; i < arguments.length - 2; i++) { |
| 16601 |
if (arguments[i] === undefined) |
| 16602 |
match[i] = undefined; |
| 16603 |
} |
| 16604 |
}); |
| 16605 |
} |
| 16606 |
if (this._xregexp && this._xregexp.captureNames) { |
| 16607 |
for (var i = 1; i < match.length; i++) { |
| 16608 |
name = this._xregexp.captureNames[i - 1]; |
| 16609 |
if (name) |
| 16610 |
match[name] = match[i]; |
| 16611 |
} |
| 16612 |
} |
| 16613 |
if (!compliantLastIndexIncrement && this.global && !match[0].length && (this.lastIndex > match.index)) |
| 16614 |
this.lastIndex--; |
| 16615 |
} |
| 16616 |
return match; |
| 16617 |
}; |
| 16618 |
if (!compliantLastIndexIncrement) { |
| 16619 |
RegExp.prototype.test = function (str) { |
| 16620 |
var match = real.exec.call(this, str); |
| 16621 |
if (match && this.global && !match[0].length && (this.lastIndex > match.index)) |
| 16622 |
this.lastIndex--; |
| 16623 |
return !!match; |
| 16624 |
}; |
| 16625 |
} |
| 16626 |
|
| 16627 |
function getNativeFlags (regex) { |
| 16628 |
return (regex.global ? "g" : "") + |
| 16629 |
(regex.ignoreCase ? "i" : "") + |
| 16630 |
(regex.multiline ? "m" : "") + |
| 16631 |
(regex.extended ? "x" : "") + // Proposed for ES4; included in AS3 |
| 16632 |
(regex.sticky ? "y" : ""); |
| 16633 |
} |
| 16634 |
|
| 16635 |
function indexOf (array, item, from) { |
| 16636 |
if (Array.prototype.indexOf) // Use the native array method if available |
| 16637 |
return array.indexOf(item, from); |
| 16638 |
for (var i = from || 0; i < array.length; i++) { |
| 16639 |
if (array[i] === item) |
| 16640 |
return i; |
| 16641 |
} |
| 16642 |
return -1; |
| 16643 |
} |
| 16644 |
|
| 16645 |
}); |
| 16646 |
|
| 16647 |
ace.define("ace/lib/es5-shim",["require","exports","module"], function(acequire, exports, module) { |
| 16648 |
|
| 16649 |
function Empty() {} |
| 16650 |
|
| 16651 |
if (!Function.prototype.bind) { |
| 16652 |
Function.prototype.bind = function bind(that) { // .length is 1 |
| 16653 |
var target = this; |
| 16654 |
if (typeof target != "function") { |
| 16655 |
throw new TypeError("Function.prototype.bind called on incompatible " + target); |
| 16656 |
} |
| 16657 |
var args = slice.call(arguments, 1); // for normal call |
| 16658 |
var bound = function () { |
| 16659 |
|
| 16660 |
if (this instanceof bound) { |
| 16661 |
|
| 16662 |
var result = target.apply( |
| 16663 |
this, |
| 16664 |
args.concat(slice.call(arguments)) |
| 16665 |
); |
| 16666 |
if (Object(result) === result) { |
| 16667 |
return result; |
| 16668 |
} |
| 16669 |
return this; |
| 16670 |
|
| 16671 |
} else { |
| 16672 |
return target.apply( |
| 16673 |
that, |
| 16674 |
args.concat(slice.call(arguments)) |
| 16675 |
); |
| 16676 |
|
| 16677 |
} |
| 16678 |
|
| 16679 |
}; |
| 16680 |
if(target.prototype) { |
| 16681 |
Empty.prototype = target.prototype; |
| 16682 |
bound.prototype = new Empty(); |
| 16683 |
Empty.prototype = null; |
| 16684 |
} |
| 16685 |
return bound; |
| 16686 |
}; |
| 16687 |
} |
| 16688 |
var call = Function.prototype.call; |
| 16689 |
var prototypeOfArray = Array.prototype; |
| 16690 |
var prototypeOfObject = Object.prototype; |
| 16691 |
var slice = prototypeOfArray.slice; |
| 16692 |
var _toString = call.bind(prototypeOfObject.toString); |
| 16693 |
var owns = call.bind(prototypeOfObject.hasOwnProperty); |
| 16694 |
var defineGetter; |
| 16695 |
var defineSetter; |
| 16696 |
var lookupGetter; |
| 16697 |
var lookupSetter; |
| 16698 |
var supportsAccessors; |
| 16699 |
if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) { |
| 16700 |
defineGetter = call.bind(prototypeOfObject.__defineGetter__); |
| 16701 |
defineSetter = call.bind(prototypeOfObject.__defineSetter__); |
| 16702 |
lookupGetter = call.bind(prototypeOfObject.__lookupGetter__); |
| 16703 |
lookupSetter = call.bind(prototypeOfObject.__lookupSetter__); |
| 16704 |
} |
| 16705 |
if ([1,2].splice(0).length != 2) { |
| 16706 |
if(function() { // test IE < 9 to splice bug - see issue #138 |
| 16707 |
function makeArray(l) { |
| 16708 |
var a = new Array(l+2); |
| 16709 |
a[0] = a[1] = 0; |
| 16710 |
return a; |
| 16711 |
} |
| 16712 |
var array = [], lengthBefore; |
| 16713 |
|
| 16714 |
array.splice.apply(array, makeArray(20)); |
| 16715 |
array.splice.apply(array, makeArray(26)); |
| 16716 |
|
| 16717 |
lengthBefore = array.length; //46 |
| 16718 |
array.splice(5, 0, "XXX"); // add one element |
| 16719 |
|
| 16720 |
lengthBefore + 1 == array.length |
| 16721 |
|
| 16722 |
if (lengthBefore + 1 == array.length) { |
| 16723 |
return true;// has right splice implementation without bugs |
| 16724 |
} |
| 16725 |
}()) {//IE 6/7 |
| 16726 |
var array_splice = Array.prototype.splice; |
| 16727 |
Array.prototype.splice = function(start, deleteCount) { |
| 16728 |
if (!arguments.length) { |
| 16729 |
return []; |
| 16730 |
} else { |
| 16731 |
return array_splice.apply(this, [ |
| 16732 |
start === void 0 ? 0 : start, |
| 16733 |
deleteCount === void 0 ? (this.length - start) : deleteCount |
| 16734 |
].concat(slice.call(arguments, 2))) |
| 16735 |
} |
| 16736 |
}; |
| 16737 |
} else {//IE8 |
| 16738 |
Array.prototype.splice = function(pos, removeCount){ |
| 16739 |
var length = this.length; |
| 16740 |
if (pos > 0) { |
| 16741 |
if (pos > length) |
| 16742 |
pos = length; |
| 16743 |
} else if (pos == void 0) { |
| 16744 |
pos = 0; |
| 16745 |
} else if (pos < 0) { |
| 16746 |
pos = Math.max(length + pos, 0); |
| 16747 |
} |
| 16748 |
|
| 16749 |
if (!(pos+removeCount < length)) |
| 16750 |
removeCount = length - pos; |
| 16751 |
|
| 16752 |
var removed = this.slice(pos, pos+removeCount); |
| 16753 |
var insert = slice.call(arguments, 2); |
| 16754 |
var add = insert.length; |
| 16755 |
if (pos === length) { |
| 16756 |
if (add) { |
| 16757 |
this.push.apply(this, insert); |
| 16758 |
} |
| 16759 |
} else { |
| 16760 |
var remove = Math.min(removeCount, length - pos); |
| 16761 |
var tailOldPos = pos + remove; |
| 16762 |
var tailNewPos = tailOldPos + add - remove; |
| 16763 |
var tailCount = length - tailOldPos; |
| 16764 |
var lengthAfterRemove = length - remove; |
| 16765 |
|
| 16766 |
if (tailNewPos < tailOldPos) { // case A |
| 16767 |
for (var i = 0; i < tailCount; ++i) { |
| 16768 |
this[tailNewPos+i] = this[tailOldPos+i]; |
| 16769 |
} |
| 16770 |
} else if (tailNewPos > tailOldPos) { // case B |
| 16771 |
for (i = tailCount; i--; ) { |
| 16772 |
this[tailNewPos+i] = this[tailOldPos+i]; |
| 16773 |
} |
| 16774 |
} // else, add == remove (nothing to do) |
| 16775 |
|
| 16776 |
if (add && pos === lengthAfterRemove) { |
| 16777 |
this.length = lengthAfterRemove; // truncate array |
| 16778 |
this.push.apply(this, insert); |
| 16779 |
} else { |
| 16780 |
this.length = lengthAfterRemove + add; // reserves space |
| 16781 |
for (i = 0; i < add; ++i) { |
| 16782 |
this[pos+i] = insert[i]; |
| 16783 |
} |
| 16784 |
} |
| 16785 |
} |
| 16786 |
return removed; |
| 16787 |
}; |
| 16788 |
} |
| 16789 |
} |
| 16790 |
if (!Array.isArray) { |
| 16791 |
Array.isArray = function isArray(obj) { |
| 16792 |
return _toString(obj) == "[object Array]"; |
| 16793 |
}; |
| 16794 |
} |
| 16795 |
var boxedString = Object("a"), |
| 16796 |
splitString = boxedString[0] != "a" || !(0 in boxedString); |
| 16797 |
|
| 16798 |
if (!Array.prototype.forEach) { |
| 16799 |
Array.prototype.forEach = function forEach(fun /*, thisp*/) { |
| 16800 |
var object = toObject(this), |
| 16801 |
self = splitString && _toString(this) == "[object String]" ? |
| 16802 |
this.split("") : |
| 16803 |
object, |
| 16804 |
thisp = arguments[1], |
| 16805 |
i = -1, |
| 16806 |
length = self.length >>> 0; |
| 16807 |
if (_toString(fun) != "[object Function]") { |
| 16808 |
throw new TypeError(); // TODO message |
| 16809 |
} |
| 16810 |
|
| 16811 |
while (++i < length) { |
| 16812 |
if (i in self) { |
| 16813 |
fun.call(thisp, self[i], i, object); |
| 16814 |
} |
| 16815 |
} |
| 16816 |
}; |
| 16817 |
} |
| 16818 |
if (!Array.prototype.map) { |
| 16819 |
Array.prototype.map = function map(fun /*, thisp*/) { |
| 16820 |
var object = toObject(this), |
| 16821 |
self = splitString && _toString(this) == "[object String]" ? |
| 16822 |
this.split("") : |
| 16823 |
object, |
| 16824 |
length = self.length >>> 0, |
| 16825 |
result = Array(length), |
| 16826 |
thisp = arguments[1]; |
| 16827 |
if (_toString(fun) != "[object Function]") { |
| 16828 |
throw new TypeError(fun + " is not a function"); |
| 16829 |
} |
| 16830 |
|
| 16831 |
for (var i = 0; i < length; i++) { |
| 16832 |
if (i in self) |
| 16833 |
result[i] = fun.call(thisp, self[i], i, object); |
| 16834 |
} |
| 16835 |
return result; |
| 16836 |
}; |
| 16837 |
} |
| 16838 |
if (!Array.prototype.filter) { |
| 16839 |
Array.prototype.filter = function filter(fun /*, thisp */) { |
| 16840 |
var object = toObject(this), |
| 16841 |
self = splitString && _toString(this) == "[object String]" ? |
| 16842 |
this.split("") : |
| 16843 |
object, |
| 16844 |
length = self.length >>> 0, |
| 16845 |
result = [], |
| 16846 |
value, |
| 16847 |
thisp = arguments[1]; |
| 16848 |
if (_toString(fun) != "[object Function]") { |
| 16849 |
throw new TypeError(fun + " is not a function"); |
| 16850 |
} |
| 16851 |
|
| 16852 |
for (var i = 0; i < length; i++) { |
| 16853 |
if (i in self) { |
| 16854 |
value = self[i]; |
| 16855 |
if (fun.call(thisp, value, i, object)) { |
| 16856 |
result.push(value); |
| 16857 |
} |
| 16858 |
} |
| 16859 |
} |
| 16860 |
return result; |
| 16861 |
}; |
| 16862 |
} |
| 16863 |
if (!Array.prototype.every) { |
| 16864 |
Array.prototype.every = function every(fun /*, thisp */) { |
| 16865 |
var object = toObject(this), |
| 16866 |
self = splitString && _toString(this) == "[object String]" ? |
| 16867 |
this.split("") : |
| 16868 |
object, |
| 16869 |
length = self.length >>> 0, |
| 16870 |
thisp = arguments[1]; |
| 16871 |
if (_toString(fun) != "[object Function]") { |
| 16872 |
throw new TypeError(fun + " is not a function"); |
| 16873 |
} |
| 16874 |
|
| 16875 |
for (var i = 0; i < length; i++) { |
| 16876 |
if (i in self && !fun.call(thisp, self[i], i, object)) { |
| 16877 |
return false; |
| 16878 |
} |
| 16879 |
} |
| 16880 |
return true; |
| 16881 |
}; |
| 16882 |
} |
| 16883 |
if (!Array.prototype.some) { |
| 16884 |
Array.prototype.some = function some(fun /*, thisp */) { |
| 16885 |
var object = toObject(this), |
| 16886 |
self = splitString && _toString(this) == "[object String]" ? |
| 16887 |
this.split("") : |
| 16888 |
object, |
| 16889 |
length = self.length >>> 0, |
| 16890 |
thisp = arguments[1]; |
| 16891 |
if (_toString(fun) != "[object Function]") { |
| 16892 |
throw new TypeError(fun + " is not a function"); |
| 16893 |
} |
| 16894 |
|
| 16895 |
for (var i = 0; i < length; i++) { |
| 16896 |
if (i in self && fun.call(thisp, self[i], i, object)) { |
| 16897 |
return true; |
| 16898 |
} |
| 16899 |
} |
| 16900 |
return false; |
| 16901 |
}; |
| 16902 |
} |
| 16903 |
if (!Array.prototype.reduce) { |
| 16904 |
Array.prototype.reduce = function reduce(fun /*, initial*/) { |
| 16905 |
var object = toObject(this), |
| 16906 |
self = splitString && _toString(this) == "[object String]" ? |
| 16907 |
this.split("") : |
| 16908 |
object, |
| 16909 |
length = self.length >>> 0; |
| 16910 |
if (_toString(fun) != "[object Function]") { |
| 16911 |
throw new TypeError(fun + " is not a function"); |
| 16912 |
} |
| 16913 |
if (!length && arguments.length == 1) { |
| 16914 |
throw new TypeError("reduce of empty array with no initial value"); |
| 16915 |
} |
| 16916 |
|
| 16917 |
var i = 0; |
| 16918 |
var result; |
| 16919 |
if (arguments.length >= 2) { |
| 16920 |
result = arguments[1]; |
| 16921 |
} else { |
| 16922 |
do { |
| 16923 |
if (i in self) { |
| 16924 |
result = self[i++]; |
| 16925 |
break; |
| 16926 |
} |
| 16927 |
if (++i >= length) { |
| 16928 |
throw new TypeError("reduce of empty array with no initial value"); |
| 16929 |
} |
| 16930 |
} while (true); |
| 16931 |
} |
| 16932 |
|
| 16933 |
for (; i < length; i++) { |
| 16934 |
if (i in self) { |
| 16935 |
result = fun.call(void 0, result, self[i], i, object); |
| 16936 |
} |
| 16937 |
} |
| 16938 |
|
| 16939 |
return result; |
| 16940 |
}; |
| 16941 |
} |
| 16942 |
if (!Array.prototype.reduceRight) { |
| 16943 |
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) { |
| 16944 |
var object = toObject(this), |
| 16945 |
self = splitString && _toString(this) == "[object String]" ? |
| 16946 |
this.split("") : |
| 16947 |
object, |
| 16948 |
length = self.length >>> 0; |
| 16949 |
if (_toString(fun) != "[object Function]") { |
| 16950 |
throw new TypeError(fun + " is not a function"); |
| 16951 |
} |
| 16952 |
if (!length && arguments.length == 1) { |
| 16953 |
throw new TypeError("reduceRight of empty array with no initial value"); |
| 16954 |
} |
| 16955 |
|
| 16956 |
var result, i = length - 1; |
| 16957 |
if (arguments.length >= 2) { |
| 16958 |
result = arguments[1]; |
| 16959 |
} else { |
| 16960 |
do { |
| 16961 |
if (i in self) { |
| 16962 |
result = self[i--]; |
| 16963 |
break; |
| 16964 |
} |
| 16965 |
if (--i < 0) { |
| 16966 |
throw new TypeError("reduceRight of empty array with no initial value"); |
| 16967 |
} |
| 16968 |
} while (true); |
| 16969 |
} |
| 16970 |
|
| 16971 |
do { |
| 16972 |
if (i in this) { |
| 16973 |
result = fun.call(void 0, result, self[i], i, object); |
| 16974 |
} |
| 16975 |
} while (i--); |
| 16976 |
|
| 16977 |
return result; |
| 16978 |
}; |
| 16979 |
} |
| 16980 |
if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) { |
| 16981 |
Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) { |
| 16982 |
var self = splitString && _toString(this) == "[object String]" ? |
| 16983 |
this.split("") : |
| 16984 |
toObject(this), |
| 16985 |
length = self.length >>> 0; |
| 16986 |
|
| 16987 |
if (!length) { |
| 16988 |
return -1; |
| 16989 |
} |
| 16990 |
|
| 16991 |
var i = 0; |
| 16992 |
if (arguments.length > 1) { |
| 16993 |
i = toInteger(arguments[1]); |
| 16994 |
} |
| 16995 |
i = i >= 0 ? i : Math.max(0, length + i); |
| 16996 |
for (; i < length; i++) { |
| 16997 |
if (i in self && self[i] === sought) { |
| 16998 |
return i; |
| 16999 |
} |
| 17000 |
} |
| 17001 |
return -1; |
| 17002 |
}; |
| 17003 |
} |
| 17004 |
if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) { |
| 17005 |
Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) { |
| 17006 |
var self = splitString && _toString(this) == "[object String]" ? |
| 17007 |
this.split("") : |
| 17008 |
toObject(this), |
| 17009 |
length = self.length >>> 0; |
| 17010 |
|
| 17011 |
if (!length) { |
| 17012 |
return -1; |
| 17013 |
} |
| 17014 |
var i = length - 1; |
| 17015 |
if (arguments.length > 1) { |
| 17016 |
i = Math.min(i, toInteger(arguments[1])); |
| 17017 |
} |
| 17018 |
i = i >= 0 ? i : length - Math.abs(i); |
| 17019 |
for (; i >= 0; i--) { |
| 17020 |
if (i in self && sought === self[i]) { |
| 17021 |
return i; |
| 17022 |
} |
| 17023 |
} |
| 17024 |
return -1; |
| 17025 |
}; |
| 17026 |
} |
| 17027 |
if (!Object.getPrototypeOf) { |
| 17028 |
Object.getPrototypeOf = function getPrototypeOf(object) { |
| 17029 |
return object.__proto__ || ( |
| 17030 |
object.constructor ? |
| 17031 |
object.constructor.prototype : |
| 17032 |
prototypeOfObject |
| 17033 |
); |
| 17034 |
}; |
| 17035 |
} |
| 17036 |
if (!Object.getOwnPropertyDescriptor) { |
| 17037 |
var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " + |
| 17038 |
"non-object: "; |
| 17039 |
Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) { |
| 17040 |
if ((typeof object != "object" && typeof object != "function") || object === null) |
| 17041 |
throw new TypeError(ERR_NON_OBJECT + object); |
| 17042 |
if (!owns(object, property)) |
| 17043 |
return; |
| 17044 |
|
| 17045 |
var descriptor, getter, setter; |
| 17046 |
descriptor = { enumerable: true, configurable: true }; |
| 17047 |
if (supportsAccessors) { |
| 17048 |
var prototype = object.__proto__; |
| 17049 |
object.__proto__ = prototypeOfObject; |
| 17050 |
|
| 17051 |
var getter = lookupGetter(object, property); |
| 17052 |
var setter = lookupSetter(object, property); |
| 17053 |
object.__proto__ = prototype; |
| 17054 |
|
| 17055 |
if (getter || setter) { |
| 17056 |
if (getter) descriptor.get = getter; |
| 17057 |
if (setter) descriptor.set = setter; |
| 17058 |
return descriptor; |
| 17059 |
} |
| 17060 |
} |
| 17061 |
descriptor.value = object[property]; |
| 17062 |
return descriptor; |
| 17063 |
}; |
| 17064 |
} |
| 17065 |
if (!Object.getOwnPropertyNames) { |
| 17066 |
Object.getOwnPropertyNames = function getOwnPropertyNames(object) { |
| 17067 |
return Object.keys(object); |
| 17068 |
}; |
| 17069 |
} |
| 17070 |
if (!Object.create) { |
| 17071 |
var createEmpty; |
| 17072 |
if (Object.prototype.__proto__ === null) { |
| 17073 |
createEmpty = function () { |
| 17074 |
return { "__proto__": null }; |
| 17075 |
}; |
| 17076 |
} else { |
| 17077 |
createEmpty = function () { |
| 17078 |
var empty = {}; |
| 17079 |
for (var i in empty) |
| 17080 |
empty[i] = null; |
| 17081 |
empty.constructor = |
| 17082 |
empty.hasOwnProperty = |
| 17083 |
empty.propertyIsEnumerable = |
| 17084 |
empty.isPrototypeOf = |
| 17085 |
empty.toLocaleString = |
| 17086 |
empty.toString = |
| 17087 |
empty.valueOf = |
| 17088 |
empty.__proto__ = null; |
| 17089 |
return empty; |
| 17090 |
} |
| 17091 |
} |
| 17092 |
|
| 17093 |
Object.create = function create(prototype, properties) { |
| 17094 |
var object; |
| 17095 |
if (prototype === null) { |
| 17096 |
object = createEmpty(); |
| 17097 |
} else { |
| 17098 |
if (typeof prototype != "object") |
| 17099 |
throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'"); |
| 17100 |
var Type = function () {}; |
| 17101 |
Type.prototype = prototype; |
| 17102 |
object = new Type(); |
| 17103 |
object.__proto__ = prototype; |
| 17104 |
} |
| 17105 |
if (properties !== void 0) |
| 17106 |
Object.defineProperties(object, properties); |
| 17107 |
return object; |
| 17108 |
}; |
| 17109 |
} |
| 17110 |
|
| 17111 |
function doesDefinePropertyWork(object) { |
| 17112 |
try { |
| 17113 |
Object.defineProperty(object, "sentinel", {}); |
| 17114 |
return "sentinel" in object; |
| 17115 |
} catch (exception) { |
| 17116 |
} |
| 17117 |
} |
| 17118 |
if (Object.defineProperty) { |
| 17119 |
var definePropertyWorksOnObject = doesDefinePropertyWork({}); |
| 17120 |
var definePropertyWorksOnDom = typeof document == "undefined" || |
| 17121 |
doesDefinePropertyWork(document.createElement("div")); |
| 17122 |
if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) { |
| 17123 |
var definePropertyFallback = Object.defineProperty; |
| 17124 |
} |
| 17125 |
} |
| 17126 |
|
| 17127 |
if (!Object.defineProperty || definePropertyFallback) { |
| 17128 |
var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: "; |
| 17129 |
var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: " |
| 17130 |
var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " + |
| 17131 |
"on this javascript engine"; |
| 17132 |
|
| 17133 |
Object.defineProperty = function defineProperty(object, property, descriptor) { |
| 17134 |
if ((typeof object != "object" && typeof object != "function") || object === null) |
| 17135 |
throw new TypeError(ERR_NON_OBJECT_TARGET + object); |
| 17136 |
if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null) |
| 17137 |
throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor); |
| 17138 |
if (definePropertyFallback) { |
| 17139 |
try { |
| 17140 |
return definePropertyFallback.call(Object, object, property, descriptor); |
| 17141 |
} catch (exception) { |
| 17142 |
} |
| 17143 |
} |
| 17144 |
if (owns(descriptor, "value")) { |
| 17145 |
|
| 17146 |
if (supportsAccessors && (lookupGetter(object, property) || |
| 17147 |
lookupSetter(object, property))) |
| 17148 |
{ |
| 17149 |
var prototype = object.__proto__; |
| 17150 |
object.__proto__ = prototypeOfObject; |
| 17151 |
delete object[property]; |
| 17152 |
object[property] = descriptor.value; |
| 17153 |
object.__proto__ = prototype; |
| 17154 |
} else { |
| 17155 |
object[property] = descriptor.value; |
| 17156 |
} |
| 17157 |
} else { |
| 17158 |
if (!supportsAccessors) |
| 17159 |
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED); |
| 17160 |
if (owns(descriptor, "get")) |
| 17161 |
defineGetter(object, property, descriptor.get); |
| 17162 |
if (owns(descriptor, "set")) |
| 17163 |
defineSetter(object, property, descriptor.set); |
| 17164 |
} |
| 17165 |
|
| 17166 |
return object; |
| 17167 |
}; |
| 17168 |
} |
| 17169 |
if (!Object.defineProperties) { |
| 17170 |
Object.defineProperties = function defineProperties(object, properties) { |
| 17171 |
for (var property in properties) { |
| 17172 |
if (owns(properties, property)) |
| 17173 |
Object.defineProperty(object, property, properties[property]); |
| 17174 |
} |
| 17175 |
return object; |
| 17176 |
}; |
| 17177 |
} |
| 17178 |
if (!Object.seal) { |
| 17179 |
Object.seal = function seal(object) { |
| 17180 |
return object; |
| 17181 |
}; |
| 17182 |
} |
| 17183 |
if (!Object.freeze) { |
| 17184 |
Object.freeze = function freeze(object) { |
| 17185 |
return object; |
| 17186 |
}; |
| 17187 |
} |
| 17188 |
try { |
| 17189 |
Object.freeze(function () {}); |
| 17190 |
} catch (exception) { |
| 17191 |
Object.freeze = (function freeze(freezeObject) { |
| 17192 |
return function freeze(object) { |
| 17193 |
if (typeof object == "function") { |
| 17194 |
return object; |
| 17195 |
} else { |
| 17196 |
return freezeObject(object); |
| 17197 |
} |
| 17198 |
}; |
| 17199 |
})(Object.freeze); |
| 17200 |
} |
| 17201 |
if (!Object.preventExtensions) { |
| 17202 |
Object.preventExtensions = function preventExtensions(object) { |
| 17203 |
return object; |
| 17204 |
}; |
| 17205 |
} |
| 17206 |
if (!Object.isSealed) { |
| 17207 |
Object.isSealed = function isSealed(object) { |
| 17208 |
return false; |
| 17209 |
}; |
| 17210 |
} |
| 17211 |
if (!Object.isFrozen) { |
| 17212 |
Object.isFrozen = function isFrozen(object) { |
| 17213 |
return false; |
| 17214 |
}; |
| 17215 |
} |
| 17216 |
if (!Object.isExtensible) { |
| 17217 |
Object.isExtensible = function isExtensible(object) { |
| 17218 |
if (Object(object) === object) { |
| 17219 |
throw new TypeError(); // TODO message |
| 17220 |
} |
| 17221 |
var name = ''; |
| 17222 |
while (owns(object, name)) { |
| 17223 |
name += '?'; |
| 17224 |
} |
| 17225 |
object[name] = true; |
| 17226 |
var returnValue = owns(object, name); |
| 17227 |
delete object[name]; |
| 17228 |
return returnValue; |
| 17229 |
}; |
| 17230 |
} |
| 17231 |
if (!Object.keys) { |
| 17232 |
var hasDontEnumBug = true, |
| 17233 |
dontEnums = [ |
| 17234 |
"toString", |
| 17235 |
"toLocaleString", |
| 17236 |
"valueOf", |
| 17237 |
"hasOwnProperty", |
| 17238 |
"isPrototypeOf", |
| 17239 |
"propertyIsEnumerable", |
| 17240 |
"constructor" |
| 17241 |
], |
| 17242 |
dontEnumsLength = dontEnums.length; |
| 17243 |
|
| 17244 |
for (var key in {"toString": null}) { |
| 17245 |
hasDontEnumBug = false; |
| 17246 |
} |
| 17247 |
|
| 17248 |
Object.keys = function keys(object) { |
| 17249 |
|
| 17250 |
if ( |
| 17251 |
(typeof object != "object" && typeof object != "function") || |
| 17252 |
object === null |
| 17253 |
) { |
| 17254 |
throw new TypeError("Object.keys called on a non-object"); |
| 17255 |
} |
| 17256 |
|
| 17257 |
var keys = []; |
| 17258 |
for (var name in object) { |
| 17259 |
if (owns(object, name)) { |
| 17260 |
keys.push(name); |
| 17261 |
} |
| 17262 |
} |
| 17263 |
|
| 17264 |
if (hasDontEnumBug) { |
| 17265 |
for (var i = 0, ii = dontEnumsLength; i < ii; i++) { |
| 17266 |
var dontEnum = dontEnums[i]; |
| 17267 |
if (owns(object, dontEnum)) { |
| 17268 |
keys.push(dontEnum); |
| 17269 |
} |
| 17270 |
} |
| 17271 |
} |
| 17272 |
return keys; |
| 17273 |
}; |
| 17274 |
|
| 17275 |
} |
| 17276 |
if (!Date.now) { |
| 17277 |
Date.now = function now() { |
| 17278 |
return new Date().getTime(); |
| 17279 |
}; |
| 17280 |
} |
| 17281 |
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" + |
| 17282 |
"\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" + |
| 17283 |
"\u2029\uFEFF"; |
| 17284 |
if (!String.prototype.trim || ws.trim()) { |
| 17285 |
ws = "[" + ws + "]"; |
| 17286 |
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"), |
| 17287 |
trimEndRegexp = new RegExp(ws + ws + "*$"); |
| 17288 |
String.prototype.trim = function trim() { |
| 17289 |
return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, ""); |
| 17290 |
}; |
| 17291 |
} |
| 17292 |
|
| 17293 |
function toInteger(n) { |
| 17294 |
n = +n; |
| 17295 |
if (n !== n) { // isNaN |
| 17296 |
n = 0; |
| 17297 |
} else if (n !== 0 && n !== (1/0) && n !== -(1/0)) { |
| 17298 |
n = (n > 0 || -1) * Math.floor(Math.abs(n)); |
| 17299 |
} |
| 17300 |
return n; |
| 17301 |
} |
| 17302 |
|
| 17303 |
function isPrimitive(input) { |
| 17304 |
var type = typeof input; |
| 17305 |
return ( |
| 17306 |
input === null || |
| 17307 |
type === "undefined" || |
| 17308 |
type === "boolean" || |
| 17309 |
type === "number" || |
| 17310 |
type === "string" |
| 17311 |
); |
| 17312 |
} |
| 17313 |
|
| 17314 |
function toPrimitive(input) { |
| 17315 |
var val, valueOf, toString; |
| 17316 |
if (isPrimitive(input)) { |
| 17317 |
return input; |
| 17318 |
} |
| 17319 |
valueOf = input.valueOf; |
| 17320 |
if (typeof valueOf === "function") { |
| 17321 |
val = valueOf.call(input); |
| 17322 |
if (isPrimitive(val)) { |
| 17323 |
return val; |
| 17324 |
} |
| 17325 |
} |
| 17326 |
toString = input.toString; |
| 17327 |
if (typeof toString === "function") { |
| 17328 |
val = toString.call(input); |
| 17329 |
if (isPrimitive(val)) { |
| 17330 |
return val; |
| 17331 |
} |
| 17332 |
} |
| 17333 |
throw new TypeError(); |
| 17334 |
} |
| 17335 |
var toObject = function (o) { |
| 17336 |
if (o == null) { // this matches both null and undefined |
| 17337 |
throw new TypeError("can't convert "+o+" to object"); |
| 17338 |
} |
| 17339 |
return Object(o); |
| 17340 |
}; |
| 17341 |
|
| 17342 |
}); |
| 17343 |
|
| 17344 |
ace.define("ace/lib/fixoldbrowsers",["require","exports","module","ace/lib/regexp","ace/lib/es5-shim"], function(acequire, exports, module) { |
| 17345 |
"use strict"; |
| 17346 |
|
| 17347 |
acequire("./regexp"); |
| 17348 |
acequire("./es5-shim"); |
| 17349 |
|
| 17350 |
}); |
| 17351 |
|
| 17352 |
ace.define("ace/lib/dom",["require","exports","module"], function(acequire, exports, module) { |
| 17353 |
"use strict"; |
| 17354 |
|
| 17355 |
var XHTML_NS = "http://www.w3.org/1999/xhtml"; |
| 17356 |
|
| 17357 |
exports.getDocumentHead = function(doc) { |
| 17358 |
if (!doc) |
| 17359 |
doc = document; |
| 17360 |
return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement; |
| 17361 |
}; |
| 17362 |
|
| 17363 |
exports.createElement = function(tag, ns) { |
| 17364 |
return document.createElementNS ? |
| 17365 |
document.createElementNS(ns || XHTML_NS, tag) : |
| 17366 |
document.createElement(tag); |
| 17367 |
}; |
| 17368 |
|
| 17369 |
exports.hasCssClass = function(el, name) { |
| 17370 |
var classes = (el.className || "").split(/\s+/g); |
| 17371 |
return classes.indexOf(name) !== -1; |
| 17372 |
}; |
| 17373 |
exports.addCssClass = function(el, name) { |
| 17374 |
if (!exports.hasCssClass(el, name)) { |
| 17375 |
el.className += " " + name; |
| 17376 |
} |
| 17377 |
}; |
| 17378 |
exports.removeCssClass = function(el, name) { |
| 17379 |
var classes = el.className.split(/\s+/g); |
| 17380 |
while (true) { |
| 17381 |
var index = classes.indexOf(name); |
| 17382 |
if (index == -1) { |
| 17383 |
break; |
| 17384 |
} |
| 17385 |
classes.splice(index, 1); |
| 17386 |
} |
| 17387 |
el.className = classes.join(" "); |
| 17388 |
}; |
| 17389 |
|
| 17390 |
exports.toggleCssClass = function(el, name) { |
| 17391 |
var classes = el.className.split(/\s+/g), add = true; |
| 17392 |
while (true) { |
| 17393 |
var index = classes.indexOf(name); |
| 17394 |
if (index == -1) { |
| 17395 |
break; |
| 17396 |
} |
| 17397 |
add = false; |
| 17398 |
classes.splice(index, 1); |
| 17399 |
} |
| 17400 |
if (add) |
| 17401 |
classes.push(name); |
| 17402 |
|
| 17403 |
el.className = classes.join(" "); |
| 17404 |
return add; |
| 17405 |
}; |
| 17406 |
exports.setCssClass = function(node, className, include) { |
| 17407 |
if (include) { |
| 17408 |
exports.addCssClass(node, className); |
| 17409 |
} else { |
| 17410 |
exports.removeCssClass(node, className); |
| 17411 |
} |
| 17412 |
}; |
| 17413 |
|
| 17414 |
exports.hasCssString = function(id, doc) { |
| 17415 |
var index = 0, sheets; |
| 17416 |
doc = doc || document; |
| 17417 |
|
| 17418 |
if (doc.createStyleSheet && (sheets = doc.styleSheets)) { |
| 17419 |
while (index < sheets.length) |
| 17420 |
if (sheets[index++].owningElement.id === id) return true; |
| 17421 |
} else if ((sheets = doc.getElementsByTagName("style"))) { |
| 17422 |
while (index < sheets.length) |
| 17423 |
if (sheets[index++].id === id) return true; |
| 17424 |
} |
| 17425 |
|
| 17426 |
return false; |
| 17427 |
}; |
| 17428 |
|
| 17429 |
exports.importCssString = function importCssString(cssText, id, doc) { |
| 17430 |
doc = doc || document; |
| 17431 |
if (id && exports.hasCssString(id, doc)) |
| 17432 |
return null; |
| 17433 |
|
| 17434 |
var style; |
| 17435 |
|
| 17436 |
if (id) |
| 17437 |
cssText += "\n/*# sourceURL=ace/css/" + id + " */"; |
| 17438 |
|
| 17439 |
if (doc.createStyleSheet) { |
| 17440 |
style = doc.createStyleSheet(); |
| 17441 |
style.cssText = cssText; |
| 17442 |
if (id) |
| 17443 |
style.owningElement.id = id; |
| 17444 |
} else { |
| 17445 |
style = exports.createElement("style"); |
| 17446 |
style.appendChild(doc.createTextNode(cssText)); |
| 17447 |
if (id) |
| 17448 |
style.id = id; |
| 17449 |
|
| 17450 |
exports.getDocumentHead(doc).appendChild(style); |
| 17451 |
} |
| 17452 |
}; |
| 17453 |
|
| 17454 |
exports.importCssStylsheet = function(uri, doc) { |
| 17455 |
if (doc.createStyleSheet) { |
| 17456 |
doc.createStyleSheet(uri); |
| 17457 |
} else { |
| 17458 |
var link = exports.createElement('link'); |
| 17459 |
link.rel = 'stylesheet'; |
| 17460 |
link.href = uri; |
| 17461 |
|
| 17462 |
exports.getDocumentHead(doc).appendChild(link); |
| 17463 |
} |
| 17464 |
}; |
| 17465 |
|
| 17466 |
exports.getInnerWidth = function(element) { |
| 17467 |
return ( |
| 17468 |
parseInt(exports.computedStyle(element, "paddingLeft"), 10) + |
| 17469 |
parseInt(exports.computedStyle(element, "paddingRight"), 10) + |
| 17470 |
element.clientWidth |
| 17471 |
); |
| 17472 |
}; |
| 17473 |
|
| 17474 |
exports.getInnerHeight = function(element) { |
| 17475 |
return ( |
| 17476 |
parseInt(exports.computedStyle(element, "paddingTop"), 10) + |
| 17477 |
parseInt(exports.computedStyle(element, "paddingBottom"), 10) + |
| 17478 |
element.clientHeight |
| 17479 |
); |
| 17480 |
}; |
| 17481 |
|
| 17482 |
exports.scrollbarWidth = function(document) { |
| 17483 |
var inner = exports.createElement("ace_inner"); |
| 17484 |
inner.style.width = "100%"; |
| 17485 |
inner.style.minWidth = "0px"; |
| 17486 |
inner.style.height = "200px"; |
| 17487 |
inner.style.display = "block"; |
| 17488 |
|
| 17489 |
var outer = exports.createElement("ace_outer"); |
| 17490 |
var style = outer.style; |
| 17491 |
|
| 17492 |
style.position = "absolute"; |
| 17493 |
style.left = "-10000px"; |
| 17494 |
style.overflow = "hidden"; |
| 17495 |
style.width = "200px"; |
| 17496 |
style.minWidth = "0px"; |
| 17497 |
style.height = "150px"; |
| 17498 |
style.display = "block"; |
| 17499 |
|
| 17500 |
outer.appendChild(inner); |
| 17501 |
|
| 17502 |
var body = document.documentElement; |
| 17503 |
body.appendChild(outer); |
| 17504 |
|
| 17505 |
var noScrollbar = inner.offsetWidth; |
| 17506 |
|
| 17507 |
style.overflow = "scroll"; |
| 17508 |
var withScrollbar = inner.offsetWidth; |
| 17509 |
|
| 17510 |
if (noScrollbar == withScrollbar) { |
| 17511 |
withScrollbar = outer.clientWidth; |
| 17512 |
} |
| 17513 |
|
| 17514 |
body.removeChild(outer); |
| 17515 |
|
| 17516 |
return noScrollbar-withScrollbar; |
| 17517 |
}; |
| 17518 |
|
| 17519 |
if (typeof document == "undefined") { |
| 17520 |
exports.importCssString = function() {}; |
| 17521 |
return; |
| 17522 |
} |
| 17523 |
|
| 17524 |
if (window.pageYOffset !== undefined) { |
| 17525 |
exports.getPageScrollTop = function() { |
| 17526 |
return window.pageYOffset; |
| 17527 |
}; |
| 17528 |
|
| 17529 |
exports.getPageScrollLeft = function() { |
| 17530 |
return window.pageXOffset; |
| 17531 |
}; |
| 17532 |
} |
| 17533 |
else { |
| 17534 |
exports.getPageScrollTop = function() { |
| 17535 |
return document.body.scrollTop; |
| 17536 |
}; |
| 17537 |
|
| 17538 |
exports.getPageScrollLeft = function() { |
| 17539 |
return document.body.scrollLeft; |
| 17540 |
}; |
| 17541 |
} |
| 17542 |
|
| 17543 |
if (window.getComputedStyle) |
| 17544 |
exports.computedStyle = function(element, style) { |
| 17545 |
if (style) |
| 17546 |
return (window.getComputedStyle(element, "") || {})[style] || ""; |
| 17547 |
return window.getComputedStyle(element, "") || {}; |
| 17548 |
}; |
| 17549 |
else |
| 17550 |
exports.computedStyle = function(element, style) { |
| 17551 |
if (style) |
| 17552 |
return element.currentStyle[style]; |
| 17553 |
return element.currentStyle; |
| 17554 |
}; |
| 17555 |
exports.setInnerHtml = function(el, innerHtml) { |
| 17556 |
var element = el.cloneNode(false);//document.createElement("div"); |
| 17557 |
element.innerHTML = innerHtml; |
| 17558 |
el.parentNode.replaceChild(element, el); |
| 17559 |
return element; |
| 17560 |
}; |
| 17561 |
|
| 17562 |
if ("textContent" in document.documentElement) { |
| 17563 |
exports.setInnerText = function(el, innerText) { |
| 17564 |
el.textContent = innerText; |
| 17565 |
}; |
| 17566 |
|
| 17567 |
exports.getInnerText = function(el) { |
| 17568 |
return el.textContent; |
| 17569 |
}; |
| 17570 |
} |
| 17571 |
else { |
| 17572 |
exports.setInnerText = function(el, innerText) { |
| 17573 |
el.innerText = innerText; |
| 17574 |
}; |
| 17575 |
|
| 17576 |
exports.getInnerText = function(el) { |
| 17577 |
return el.innerText; |
| 17578 |
}; |
| 17579 |
} |
| 17580 |
|
| 17581 |
exports.getParentWindow = function(document) { |
| 17582 |
return document.defaultView || document.parentWindow; |
| 17583 |
}; |
| 17584 |
|
| 17585 |
}); |
| 17586 |
|
| 17587 |
ace.define("ace/lib/oop",["require","exports","module"], function(acequire, exports, module) { |
| 17588 |
"use strict"; |
| 17589 |
|
| 17590 |
exports.inherits = function(ctor, superCtor) { |
| 17591 |
ctor.super_ = superCtor; |
| 17592 |
ctor.prototype = Object.create(superCtor.prototype, { |
| 17593 |
constructor: { |
| 17594 |
value: ctor, |
| 17595 |
enumerable: false, |
| 17596 |
writable: true, |
| 17597 |
configurable: true |
| 17598 |
} |
| 17599 |
}); |
| 17600 |
}; |
| 17601 |
|
| 17602 |
exports.mixin = function(obj, mixin) { |
| 17603 |
for (var key in mixin) { |
| 17604 |
obj[key] = mixin[key]; |
| 17605 |
} |
| 17606 |
return obj; |
| 17607 |
}; |
| 17608 |
|
| 17609 |
exports.implement = function(proto, mixin) { |
| 17610 |
exports.mixin(proto, mixin); |
| 17611 |
}; |
| 17612 |
|
| 17613 |
}); |
| 17614 |
|
| 17615 |
ace.define("ace/lib/keys",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop"], function(acequire, exports, module) { |
| 17616 |
"use strict"; |
| 17617 |
|
| 17618 |
acequire("./fixoldbrowsers"); |
| 17619 |
|
| 17620 |
var oop = acequire("./oop"); |
| 17621 |
var Keys = (function() { |
| 17622 |
var ret = { |
| 17623 |
MODIFIER_KEYS: { |
| 17624 |
16: 'Shift', 17: 'Ctrl', 18: 'Alt', 224: 'Meta' |
| 17625 |
}, |
| 17626 |
|
| 17627 |
KEY_MODS: { |
| 17628 |
"ctrl": 1, "alt": 2, "option" : 2, "shift": 4, |
| 17629 |
"super": 8, "meta": 8, "command": 8, "cmd": 8 |
| 17630 |
}, |
| 17631 |
|
| 17632 |
FUNCTION_KEYS : { |
| 17633 |
8 : "Backspace", |
| 17634 |
9 : "Tab", |
| 17635 |
13 : "Return", |
| 17636 |
19 : "Pause", |
| 17637 |
27 : "Esc", |
| 17638 |
32 : "Space", |
| 17639 |
33 : "PageUp", |
| 17640 |
34 : "PageDown", |
| 17641 |
35 : "End", |
| 17642 |
36 : "Home", |
| 17643 |
37 : "Left", |
| 17644 |
38 : "Up", |
| 17645 |
39 : "Right", |
| 17646 |
40 : "Down", |
| 17647 |
44 : "Print", |
| 17648 |
45 : "Insert", |
| 17649 |
46 : "Delete", |
| 17650 |
96 : "Numpad0", |
| 17651 |
97 : "Numpad1", |
| 17652 |
98 : "Numpad2", |
| 17653 |
99 : "Numpad3", |
| 17654 |
100: "Numpad4", |
| 17655 |
101: "Numpad5", |
| 17656 |
102: "Numpad6", |
| 17657 |
103: "Numpad7", |
| 17658 |
104: "Numpad8", |
| 17659 |
105: "Numpad9", |
| 17660 |
'-13': "NumpadEnter", |
| 17661 |
112: "F1", |
| 17662 |
113: "F2", |
| 17663 |
114: "F3", |
| 17664 |
115: "F4", |
| 17665 |
116: "F5", |
| 17666 |
117: "F6", |
| 17667 |
118: "F7", |
| 17668 |
119: "F8", |
| 17669 |
120: "F9", |
| 17670 |
121: "F10", |
| 17671 |
122: "F11", |
| 17672 |
123: "F12", |
| 17673 |
144: "Numlock", |
| 17674 |
145: "Scrolllock" |
| 17675 |
}, |
| 17676 |
|
| 17677 |
PRINTABLE_KEYS: { |
| 17678 |
32: ' ', 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5', |
| 17679 |
54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a', |
| 17680 |
66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h', |
| 17681 |
73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o', |
| 17682 |
80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v', |
| 17683 |
87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.', |
| 17684 |
186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`', |
| 17685 |
219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*' |
| 17686 |
} |
| 17687 |
}; |
| 17688 |
var name, i; |
| 17689 |
for (i in ret.FUNCTION_KEYS) { |
| 17690 |
name = ret.FUNCTION_KEYS[i].toLowerCase(); |
| 17691 |
ret[name] = parseInt(i, 10); |
| 17692 |
} |
| 17693 |
for (i in ret.PRINTABLE_KEYS) { |
| 17694 |
name = ret.PRINTABLE_KEYS[i].toLowerCase(); |
| 17695 |
ret[name] = parseInt(i, 10); |
| 17696 |
} |
| 17697 |
oop.mixin(ret, ret.MODIFIER_KEYS); |
| 17698 |
oop.mixin(ret, ret.PRINTABLE_KEYS); |
| 17699 |
oop.mixin(ret, ret.FUNCTION_KEYS); |
| 17700 |
ret.enter = ret["return"]; |
| 17701 |
ret.escape = ret.esc; |
| 17702 |
ret.del = ret["delete"]; |
| 17703 |
ret[173] = '-'; |
| 17704 |
|
| 17705 |
(function() { |
| 17706 |
var mods = ["cmd", "ctrl", "alt", "shift"]; |
| 17707 |
for (var i = Math.pow(2, mods.length); i--;) { |
| 17708 |
ret.KEY_MODS[i] = mods.filter(function(x) { |
| 17709 |
return i & ret.KEY_MODS[x]; |
| 17710 |
}).join("-") + "-"; |
| 17711 |
} |
| 17712 |
})(); |
| 17713 |
|
| 17714 |
ret.KEY_MODS[0] = ""; |
| 17715 |
ret.KEY_MODS[-1] = "input-"; |
| 17716 |
|
| 17717 |
return ret; |
| 17718 |
})(); |
| 17719 |
oop.mixin(exports, Keys); |
| 17720 |
|
| 17721 |
exports.keyCodeToString = function(keyCode) { |
| 17722 |
var keyString = Keys[keyCode]; |
| 17723 |
if (typeof keyString != "string") |
| 17724 |
keyString = String.fromCharCode(keyCode); |
| 17725 |
return keyString.toLowerCase(); |
| 17726 |
}; |
| 17727 |
|
| 17728 |
}); |
| 17729 |
|
| 17730 |
ace.define("ace/lib/useragent",["require","exports","module"], function(acequire, exports, module) { |
| 17731 |
"use strict"; |
| 17732 |
exports.OS = { |
| 17733 |
LINUX: "LINUX", |
| 17734 |
MAC: "MAC", |
| 17735 |
WINDOWS: "WINDOWS" |
| 17736 |
}; |
| 17737 |
exports.getOS = function() { |
| 17738 |
if (exports.isMac) { |
| 17739 |
return exports.OS.MAC; |
| 17740 |
} else if (exports.isLinux) { |
| 17741 |
return exports.OS.LINUX; |
| 17742 |
} else { |
| 17743 |
return exports.OS.WINDOWS; |
| 17744 |
} |
| 17745 |
}; |
| 17746 |
if (typeof navigator != "object") |
| 17747 |
return; |
| 17748 |
|
| 17749 |
var os = (navigator.platform.match(/mac|win|linux/i) || ["other"])[0].toLowerCase(); |
| 17750 |
var ua = navigator.userAgent; |
| 17751 |
exports.isWin = (os == "win"); |
| 17752 |
exports.isMac = (os == "mac"); |
| 17753 |
exports.isLinux = (os == "linux"); |
| 17754 |
exports.isIE = |
| 17755 |
(navigator.appName == "Microsoft Internet Explorer" || navigator.appName.indexOf("MSAppHost") >= 0) |
| 17756 |
? parseFloat((ua.match(/(?:MSIE |Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]) |
| 17757 |
: parseFloat((ua.match(/(?:Trident\/[0-9]+[\.0-9]+;.*rv:)([0-9]+[\.0-9]+)/)||[])[1]); // for ie |
| 17758 |
|
| 17759 |
exports.isOldIE = exports.isIE && exports.isIE < 9; |
| 17760 |
exports.isGecko = exports.isMozilla = (window.Controllers || window.controllers) && window.navigator.product === "Gecko"; |
| 17761 |
exports.isOldGecko = exports.isGecko && parseInt((ua.match(/rv\:(\d+)/)||[])[1], 10) < 4; |
| 17762 |
exports.isOpera = window.opera && Object.prototype.toString.call(window.opera) == "[object Opera]"; |
| 17763 |
exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined; |
| 17764 |
|
| 17765 |
exports.isChrome = parseFloat(ua.split(" Chrome/")[1]) || undefined; |
| 17766 |
|
| 17767 |
exports.isAIR = ua.indexOf("AdobeAIR") >= 0; |
| 17768 |
|
| 17769 |
exports.isIPad = ua.indexOf("iPad") >= 0; |
| 17770 |
|
| 17771 |
exports.isTouchPad = ua.indexOf("TouchPad") >= 0; |
| 17772 |
|
| 17773 |
exports.isChromeOS = ua.indexOf(" CrOS ") >= 0; |
| 17774 |
|
| 17775 |
}); |
| 17776 |
|
| 17777 |
ace.define("ace/lib/event",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(acequire, exports, module) { |
| 17778 |
"use strict"; |
| 17779 |
|
| 17780 |
var keys = acequire("./keys"); |
| 17781 |
var useragent = acequire("./useragent"); |
| 17782 |
|
| 17783 |
var pressedKeys = null; |
| 17784 |
var ts = 0; |
| 17785 |
|
| 17786 |
exports.addListener = function(elem, type, callback) { |
| 17787 |
if (elem.addEventListener) { |
| 17788 |
return elem.addEventListener(type, callback, false); |
| 17789 |
} |
| 17790 |
if (elem.attachEvent) { |
| 17791 |
var wrapper = function() { |
| 17792 |
callback.call(elem, window.event); |
| 17793 |
}; |
| 17794 |
callback._wrapper = wrapper; |
| 17795 |
elem.attachEvent("on" + type, wrapper); |
| 17796 |
} |
| 17797 |
}; |
| 17798 |
|
| 17799 |
exports.removeListener = function(elem, type, callback) { |
| 17800 |
if (elem.removeEventListener) { |
| 17801 |
return elem.removeEventListener(type, callback, false); |
| 17802 |
} |
| 17803 |
if (elem.detachEvent) { |
| 17804 |
elem.detachEvent("on" + type, callback._wrapper || callback); |
| 17805 |
} |
| 17806 |
}; |
| 17807 |
exports.stopEvent = function(e) { |
| 17808 |
exports.stopPropagation(e); |
| 17809 |
exports.preventDefault(e); |
| 17810 |
return false; |
| 17811 |
}; |
| 17812 |
|
| 17813 |
exports.stopPropagation = function(e) { |
| 17814 |
if (e.stopPropagation) |
| 17815 |
e.stopPropagation(); |
| 17816 |
else |
| 17817 |
e.cancelBubble = true; |
| 17818 |
}; |
| 17819 |
|
| 17820 |
exports.preventDefault = function(e) { |
| 17821 |
if (e.preventDefault) |
| 17822 |
e.preventDefault(); |
| 17823 |
else |
| 17824 |
e.returnValue = false; |
| 17825 |
}; |
| 17826 |
exports.getButton = function(e) { |
| 17827 |
if (e.type == "dblclick") |
| 17828 |
return 0; |
| 17829 |
if (e.type == "contextmenu" || (useragent.isMac && (e.ctrlKey && !e.altKey && !e.shiftKey))) |
| 17830 |
return 2; |
| 17831 |
if (e.preventDefault) { |
| 17832 |
return e.button; |
| 17833 |
} |
| 17834 |
else { |
| 17835 |
return {1:0, 2:2, 4:1}[e.button]; |
| 17836 |
} |
| 17837 |
}; |
| 17838 |
|
| 17839 |
exports.capture = function(el, eventHandler, releaseCaptureHandler) { |
| 17840 |
function onMouseUp(e) { |
| 17841 |
eventHandler && eventHandler(e); |
| 17842 |
releaseCaptureHandler && releaseCaptureHandler(e); |
| 17843 |
|
| 17844 |
exports.removeListener(document, "mousemove", eventHandler, true); |
| 17845 |
exports.removeListener(document, "mouseup", onMouseUp, true); |
| 17846 |
exports.removeListener(document, "dragstart", onMouseUp, true); |
| 17847 |
} |
| 17848 |
|
| 17849 |
exports.addListener(document, "mousemove", eventHandler, true); |
| 17850 |
exports.addListener(document, "mouseup", onMouseUp, true); |
| 17851 |
exports.addListener(document, "dragstart", onMouseUp, true); |
| 17852 |
|
| 17853 |
return onMouseUp; |
| 17854 |
}; |
| 17855 |
|
| 17856 |
exports.addTouchMoveListener = function (el, callback) { |
| 17857 |
if ("ontouchmove" in el) { |
| 17858 |
var startx, starty; |
| 17859 |
exports.addListener(el, "touchstart", function (e) { |
| 17860 |
var touchObj = e.changedTouches[0]; |
| 17861 |
startx = touchObj.clientX; |
| 17862 |
starty = touchObj.clientY; |
| 17863 |
}); |
| 17864 |
exports.addListener(el, "touchmove", function (e) { |
| 17865 |
var factor = 1, |
| 17866 |
touchObj = e.changedTouches[0]; |
| 17867 |
|
| 17868 |
e.wheelX = -(touchObj.clientX - startx) / factor; |
| 17869 |
e.wheelY = -(touchObj.clientY - starty) / factor; |
| 17870 |
|
| 17871 |
startx = touchObj.clientX; |
| 17872 |
starty = touchObj.clientY; |
| 17873 |
|
| 17874 |
callback(e); |
| 17875 |
}); |
| 17876 |
} |
| 17877 |
}; |
| 17878 |
|
| 17879 |
exports.addMouseWheelListener = function(el, callback) { |
| 17880 |
if ("onmousewheel" in el) { |
| 17881 |
exports.addListener(el, "mousewheel", function(e) { |
| 17882 |
var factor = 8; |
| 17883 |
if (e.wheelDeltaX !== undefined) { |
| 17884 |
e.wheelX = -e.wheelDeltaX / factor; |
| 17885 |
e.wheelY = -e.wheelDeltaY / factor; |
| 17886 |
} else { |
| 17887 |
e.wheelX = 0; |
| 17888 |
e.wheelY = -e.wheelDelta / factor; |
| 17889 |
} |
| 17890 |
callback(e); |
| 17891 |
}); |
| 17892 |
} else if ("onwheel" in el) { |
| 17893 |
exports.addListener(el, "wheel", function(e) { |
| 17894 |
var factor = 0.35; |
| 17895 |
switch (e.deltaMode) { |
| 17896 |
case e.DOM_DELTA_PIXEL: |
| 17897 |
e.wheelX = e.deltaX * factor || 0; |
| 17898 |
e.wheelY = e.deltaY * factor || 0; |
| 17899 |
break; |
| 17900 |
case e.DOM_DELTA_LINE: |
| 17901 |
case e.DOM_DELTA_PAGE: |
| 17902 |
e.wheelX = (e.deltaX || 0) * 5; |
| 17903 |
e.wheelY = (e.deltaY || 0) * 5; |
| 17904 |
break; |
| 17905 |
} |
| 17906 |
|
| 17907 |
callback(e); |
| 17908 |
}); |
| 17909 |
} else { |
| 17910 |
exports.addListener(el, "DOMMouseScroll", function(e) { |
| 17911 |
if (e.axis && e.axis == e.HORIZONTAL_AXIS) { |
| 17912 |
e.wheelX = (e.detail || 0) * 5; |
| 17913 |
e.wheelY = 0; |
| 17914 |
} else { |
| 17915 |
e.wheelX = 0; |
| 17916 |
e.wheelY = (e.detail || 0) * 5; |
| 17917 |
} |
| 17918 |
callback(e); |
| 17919 |
}); |
| 17920 |
} |
| 17921 |
}; |
| 17922 |
|
| 17923 |
exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName) { |
| 17924 |
var clicks = 0; |
| 17925 |
var startX, startY, timer; |
| 17926 |
var eventNames = { |
| 17927 |
2: "dblclick", |
| 17928 |
3: "tripleclick", |
| 17929 |
4: "quadclick" |
| 17930 |
}; |
| 17931 |
|
| 17932 |
function onMousedown(e) { |
| 17933 |
if (exports.getButton(e) !== 0) { |
| 17934 |
clicks = 0; |
| 17935 |
} else if (e.detail > 1) { |
| 17936 |
clicks++; |
| 17937 |
if (clicks > 4) |
| 17938 |
clicks = 1; |
| 17939 |
} else { |
| 17940 |
clicks = 1; |
| 17941 |
} |
| 17942 |
if (useragent.isIE) { |
| 17943 |
var isNewClick = Math.abs(e.clientX - startX) > 5 || Math.abs(e.clientY - startY) > 5; |
| 17944 |
if (!timer || isNewClick) |
| 17945 |
clicks = 1; |
| 17946 |
if (timer) |
| 17947 |
clearTimeout(timer); |
| 17948 |
timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600); |
| 17949 |
|
| 17950 |
if (clicks == 1) { |
| 17951 |
startX = e.clientX; |
| 17952 |
startY = e.clientY; |
| 17953 |
} |
| 17954 |
} |
| 17955 |
|
| 17956 |
e._clicks = clicks; |
| 17957 |
|
| 17958 |
eventHandler[callbackName]("mousedown", e); |
| 17959 |
|
| 17960 |
if (clicks > 4) |
| 17961 |
clicks = 0; |
| 17962 |
else if (clicks > 1) |
| 17963 |
return eventHandler[callbackName](eventNames[clicks], e); |
| 17964 |
} |
| 17965 |
function onDblclick(e) { |
| 17966 |
clicks = 2; |
| 17967 |
if (timer) |
| 17968 |
clearTimeout(timer); |
| 17969 |
timer = setTimeout(function() {timer = null}, timeouts[clicks - 1] || 600); |
| 17970 |
eventHandler[callbackName]("mousedown", e); |
| 17971 |
eventHandler[callbackName](eventNames[clicks], e); |
| 17972 |
} |
| 17973 |
if (!Array.isArray(elements)) |
| 17974 |
elements = [elements]; |
| 17975 |
elements.forEach(function(el) { |
| 17976 |
exports.addListener(el, "mousedown", onMousedown); |
| 17977 |
if (useragent.isOldIE) |
| 17978 |
exports.addListener(el, "dblclick", onDblclick); |
| 17979 |
}); |
| 17980 |
}; |
| 17981 |
|
| 17982 |
var getModifierHash = useragent.isMac && useragent.isOpera && !("KeyboardEvent" in window) |
| 17983 |
? function(e) { |
| 17984 |
return 0 | (e.metaKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.ctrlKey ? 8 : 0); |
| 17985 |
} |
| 17986 |
: function(e) { |
| 17987 |
return 0 | (e.ctrlKey ? 1 : 0) | (e.altKey ? 2 : 0) | (e.shiftKey ? 4 : 0) | (e.metaKey ? 8 : 0); |
| 17988 |
}; |
| 17989 |
|
| 17990 |
exports.getModifierString = function(e) { |
| 17991 |
return keys.KEY_MODS[getModifierHash(e)]; |
| 17992 |
}; |
| 17993 |
|
| 17994 |
function normalizeCommandKeys(callback, e, keyCode) { |
| 17995 |
var hashId = getModifierHash(e); |
| 17996 |
|
| 17997 |
if (!useragent.isMac && pressedKeys) { |
| 17998 |
if (pressedKeys.OSKey) |
| 17999 |
hashId |= 8; |
| 18000 |
if (pressedKeys.altGr) { |
| 18001 |
if ((3 & hashId) != 3) |
| 18002 |
pressedKeys.altGr = 0; |
| 18003 |
else |
| 18004 |
return; |
| 18005 |
} |
| 18006 |
if (keyCode === 18 || keyCode === 17) { |
| 18007 |
var location = "location" in e ? e.location : e.keyLocation; |
| 18008 |
if (keyCode === 17 && location === 1) { |
| 18009 |
if (pressedKeys[keyCode] == 1) |
| 18010 |
ts = e.timeStamp; |
| 18011 |
} else if (keyCode === 18 && hashId === 3 && location === 2) { |
| 18012 |
var dt = e.timeStamp - ts; |
| 18013 |
if (dt < 50) |
| 18014 |
pressedKeys.altGr = true; |
| 18015 |
} |
| 18016 |
} |
| 18017 |
} |
| 18018 |
|
| 18019 |
if (keyCode in keys.MODIFIER_KEYS) { |
| 18020 |
keyCode = -1; |
| 18021 |
} |
| 18022 |
if (hashId & 8 && (keyCode >= 91 && keyCode <= 93)) { |
| 18023 |
keyCode = -1; |
| 18024 |
} |
| 18025 |
|
| 18026 |
if (!hashId && keyCode === 13) { |
| 18027 |
var location = "location" in e ? e.location : e.keyLocation; |
| 18028 |
if (location === 3) { |
| 18029 |
callback(e, hashId, -keyCode); |
| 18030 |
if (e.defaultPrevented) |
| 18031 |
return; |
| 18032 |
} |
| 18033 |
} |
| 18034 |
|
| 18035 |
if (useragent.isChromeOS && hashId & 8) { |
| 18036 |
callback(e, hashId, keyCode); |
| 18037 |
if (e.defaultPrevented) |
| 18038 |
return; |
| 18039 |
else |
| 18040 |
hashId &= ~8; |
| 18041 |
} |
| 18042 |
if (!hashId && !(keyCode in keys.FUNCTION_KEYS) && !(keyCode in keys.PRINTABLE_KEYS)) { |
| 18043 |
return false; |
| 18044 |
} |
| 18045 |
|
| 18046 |
return callback(e, hashId, keyCode); |
| 18047 |
} |
| 18048 |
|
| 18049 |
|
| 18050 |
exports.addCommandKeyListener = function(el, callback) { |
| 18051 |
var addListener = exports.addListener; |
| 18052 |
if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) { |
| 18053 |
var lastKeyDownKeyCode = null; |
| 18054 |
addListener(el, "keydown", function(e) { |
| 18055 |
lastKeyDownKeyCode = e.keyCode; |
| 18056 |
}); |
| 18057 |
addListener(el, "keypress", function(e) { |
| 18058 |
return normalizeCommandKeys(callback, e, lastKeyDownKeyCode); |
| 18059 |
}); |
| 18060 |
} else { |
| 18061 |
var lastDefaultPrevented = null; |
| 18062 |
|
| 18063 |
addListener(el, "keydown", function(e) { |
| 18064 |
var keyCode = e.keyCode; |
| 18065 |
pressedKeys[keyCode] = (pressedKeys[keyCode] || 0) + 1; |
| 18066 |
if (keyCode == 91 || keyCode == 92) { |
| 18067 |
pressedKeys.OSKey = true; |
| 18068 |
} else if (pressedKeys.OSKey) { |
| 18069 |
if (e.timeStamp - pressedKeys.lastT > 200 && pressedKeys.count == 1) |
| 18070 |
resetPressedKeys(); |
| 18071 |
} |
| 18072 |
if (pressedKeys[keyCode] == 1) |
| 18073 |
pressedKeys.count++; |
| 18074 |
pressedKeys.lastT = e.timeStamp; |
| 18075 |
var result = normalizeCommandKeys(callback, e, keyCode); |
| 18076 |
lastDefaultPrevented = e.defaultPrevented; |
| 18077 |
return result; |
| 18078 |
}); |
| 18079 |
|
| 18080 |
addListener(el, "keypress", function(e) { |
| 18081 |
if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) { |
| 18082 |
exports.stopEvent(e); |
| 18083 |
lastDefaultPrevented = null; |
| 18084 |
} |
| 18085 |
}); |
| 18086 |
|
| 18087 |
addListener(el, "keyup", function(e) { |
| 18088 |
var keyCode = e.keyCode; |
| 18089 |
if (!pressedKeys[keyCode]) { |
| 18090 |
resetPressedKeys(); |
| 18091 |
} else { |
| 18092 |
pressedKeys.count = Math.max(pressedKeys.count - 1, 0); |
| 18093 |
} |
| 18094 |
if (keyCode == 91 || keyCode == 92) { |
| 18095 |
pressedKeys.OSKey = false; |
| 18096 |
} |
| 18097 |
pressedKeys[keyCode] = null; |
| 18098 |
}); |
| 18099 |
|
| 18100 |
if (!pressedKeys) { |
| 18101 |
resetPressedKeys(); |
| 18102 |
addListener(window, "focus", resetPressedKeys); |
| 18103 |
} |
| 18104 |
} |
| 18105 |
}; |
| 18106 |
function resetPressedKeys() { |
| 18107 |
pressedKeys = Object.create(null); |
| 18108 |
pressedKeys.count = 0; |
| 18109 |
pressedKeys.lastT = 0; |
| 18110 |
} |
| 18111 |
|
| 18112 |
if (typeof window == "object" && window.postMessage && !useragent.isOldIE) { |
| 18113 |
var postMessageId = 1; |
| 18114 |
exports.nextTick = function(callback, win) { |
| 18115 |
win = win || window; |
| 18116 |
var messageName = "zero-timeout-message-" + postMessageId; |
| 18117 |
exports.addListener(win, "message", function listener(e) { |
| 18118 |
if (e.data == messageName) { |
| 18119 |
exports.stopPropagation(e); |
| 18120 |
exports.removeListener(win, "message", listener); |
| 18121 |
callback(); |
| 18122 |
} |
| 18123 |
}); |
| 18124 |
win.postMessage(messageName, "*"); |
| 18125 |
}; |
| 18126 |
} |
| 18127 |
|
| 18128 |
|
| 18129 |
exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame |
| 18130 |
|| window.mozRequestAnimationFrame |
| 18131 |
|| window.webkitRequestAnimationFrame |
| 18132 |
|| window.msRequestAnimationFrame |
| 18133 |
|| window.oRequestAnimationFrame); |
| 18134 |
|
| 18135 |
if (exports.nextFrame) |
| 18136 |
exports.nextFrame = exports.nextFrame.bind(window); |
| 18137 |
else |
| 18138 |
exports.nextFrame = function(callback) { |
| 18139 |
setTimeout(callback, 17); |
| 18140 |
}; |
| 18141 |
}); |
| 18142 |
|
| 18143 |
ace.define("ace/lib/lang",["require","exports","module"], function(acequire, exports, module) { |
| 18144 |
"use strict"; |
| 18145 |
|
| 18146 |
exports.last = function(a) { |
| 18147 |
return a[a.length - 1]; |
| 18148 |
}; |
| 18149 |
|
| 18150 |
exports.stringReverse = function(string) { |
| 18151 |
return string.split("").reverse().join(""); |
| 18152 |
}; |
| 18153 |
|
| 18154 |
exports.stringRepeat = function (string, count) { |
| 18155 |
var result = ''; |
| 18156 |
while (count > 0) { |
| 18157 |
if (count & 1) |
| 18158 |
result += string; |
| 18159 |
|
| 18160 |
if (count >>= 1) |
| 18161 |
string += string; |
| 18162 |
} |
| 18163 |
return result; |
| 18164 |
}; |
| 18165 |
|
| 18166 |
var trimBeginRegexp = /^\s\s*/; |
| 18167 |
var trimEndRegexp = /\s\s*$/; |
| 18168 |
|
| 18169 |
exports.stringTrimLeft = function (string) { |
| 18170 |
return string.replace(trimBeginRegexp, ''); |
| 18171 |
}; |
| 18172 |
|
| 18173 |
exports.stringTrimRight = function (string) { |
| 18174 |
return string.replace(trimEndRegexp, ''); |
| 18175 |
}; |
| 18176 |
|
| 18177 |
exports.copyObject = function(obj) { |
| 18178 |
var copy = {}; |
| 18179 |
for (var key in obj) { |
| 18180 |
copy[key] = obj[key]; |
| 18181 |
} |
| 18182 |
return copy; |
| 18183 |
}; |
| 18184 |
|
| 18185 |
exports.copyArray = function(array){ |
| 18186 |
var copy = []; |
| 18187 |
for (var i=0, l=array.length; i<l; i++) { |
| 18188 |
if (array[i] && typeof array[i] == "object") |
| 18189 |
copy[i] = this.copyObject( array[i] ); |
| 18190 |
else |
| 18191 |
copy[i] = array[i]; |
| 18192 |
} |
| 18193 |
return copy; |
| 18194 |
}; |
| 18195 |
|
| 18196 |
exports.deepCopy = function deepCopy(obj) { |
| 18197 |
if (typeof obj !== "object" || !obj) |
| 18198 |
return obj; |
| 18199 |
var copy; |
| 18200 |
if (Array.isArray(obj)) { |
| 18201 |
copy = []; |
| 18202 |
for (var key = 0; key < obj.length; key++) { |
| 18203 |
copy[key] = deepCopy(obj[key]); |
| 18204 |
} |
| 18205 |
return copy; |
| 18206 |
} |
| 18207 |
var cons = obj.constructor; |
| 18208 |
if (cons === RegExp) |
| 18209 |
return obj; |
| 18210 |
|
| 18211 |
copy = cons(); |
| 18212 |
for (var key in obj) { |
| 18213 |
copy[key] = deepCopy(obj[key]); |
| 18214 |
} |
| 18215 |
return copy; |
| 18216 |
}; |
| 18217 |
|
| 18218 |
exports.arrayToMap = function(arr) { |
| 18219 |
var map = {}; |
| 18220 |
for (var i=0; i<arr.length; i++) { |
| 18221 |
map[arr[i]] = 1; |
| 18222 |
} |
| 18223 |
return map; |
| 18224 |
|
| 18225 |
}; |
| 18226 |
|
| 18227 |
exports.createMap = function(props) { |
| 18228 |
var map = Object.create(null); |
| 18229 |
for (var i in props) { |
| 18230 |
map[i] = props[i]; |
| 18231 |
} |
| 18232 |
return map; |
| 18233 |
}; |
| 18234 |
exports.arrayRemove = function(array, value) { |
| 18235 |
for (var i = 0; i <= array.length; i++) { |
| 18236 |
if (value === array[i]) { |
| 18237 |
array.splice(i, 1); |
| 18238 |
} |
| 18239 |
} |
| 18240 |
}; |
| 18241 |
|
| 18242 |
exports.escapeRegExp = function(str) { |
| 18243 |
return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); |
| 18244 |
}; |
| 18245 |
|
| 18246 |
exports.escapeHTML = function(str) { |
| 18247 |
return str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<"); |
| 18248 |
}; |
| 18249 |
|
| 18250 |
exports.getMatchOffsets = function(string, regExp) { |
| 18251 |
var matches = []; |
| 18252 |
|
| 18253 |
string.replace(regExp, function(str) { |
| 18254 |
matches.push({ |
| 18255 |
offset: arguments[arguments.length-2], |
| 18256 |
length: str.length |
| 18257 |
}); |
| 18258 |
}); |
| 18259 |
|
| 18260 |
return matches; |
| 18261 |
}; |
| 18262 |
exports.deferredCall = function(fcn) { |
| 18263 |
var timer = null; |
| 18264 |
var callback = function() { |
| 18265 |
timer = null; |
| 18266 |
fcn(); |
| 18267 |
}; |
| 18268 |
|
| 18269 |
var deferred = function(timeout) { |
| 18270 |
deferred.cancel(); |
| 18271 |
timer = setTimeout(callback, timeout || 0); |
| 18272 |
return deferred; |
| 18273 |
}; |
| 18274 |
|
| 18275 |
deferred.schedule = deferred; |
| 18276 |
|
| 18277 |
deferred.call = function() { |
| 18278 |
this.cancel(); |
| 18279 |
fcn(); |
| 18280 |
return deferred; |
| 18281 |
}; |
| 18282 |
|
| 18283 |
deferred.cancel = function() { |
| 18284 |
clearTimeout(timer); |
| 18285 |
timer = null; |
| 18286 |
return deferred; |
| 18287 |
}; |
| 18288 |
|
| 18289 |
deferred.isPending = function() { |
| 18290 |
return timer; |
| 18291 |
}; |
| 18292 |
|
| 18293 |
return deferred; |
| 18294 |
}; |
| 18295 |
|
| 18296 |
|
| 18297 |
exports.delayedCall = function(fcn, defaultTimeout) { |
| 18298 |
var timer = null; |
| 18299 |
var callback = function() { |
| 18300 |
timer = null; |
| 18301 |
fcn(); |
| 18302 |
}; |
| 18303 |
|
| 18304 |
var _self = function(timeout) { |
| 18305 |
if (timer == null) |
| 18306 |
timer = setTimeout(callback, timeout || defaultTimeout); |
| 18307 |
}; |
| 18308 |
|
| 18309 |
_self.delay = function(timeout) { |
| 18310 |
timer && clearTimeout(timer); |
| 18311 |
timer = setTimeout(callback, timeout || defaultTimeout); |
| 18312 |
}; |
| 18313 |
_self.schedule = _self; |
| 18314 |
|
| 18315 |
_self.call = function() { |
| 18316 |
this.cancel(); |
| 18317 |
fcn(); |
| 18318 |
}; |
| 18319 |
|
| 18320 |
_self.cancel = function() { |
| 18321 |
timer && clearTimeout(timer); |
| 18322 |
timer = null; |
| 18323 |
}; |
| 18324 |
|
| 18325 |
_self.isPending = function() { |
| 18326 |
return timer; |
| 18327 |
}; |
| 18328 |
|
| 18329 |
return _self; |
| 18330 |
}; |
| 18331 |
}); |
| 18332 |
|
| 18333 |
ace.define("ace/keyboard/textinput",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/lib/dom","ace/lib/lang"], function(acequire, exports, module) { |
| 18334 |
"use strict"; |
| 18335 |
|
| 18336 |
var event = acequire("../lib/event"); |
| 18337 |
var useragent = acequire("../lib/useragent"); |
| 18338 |
var dom = acequire("../lib/dom"); |
| 18339 |
var lang = acequire("../lib/lang"); |
| 18340 |
var BROKEN_SETDATA = useragent.isChrome < 18; |
| 18341 |
var USE_IE_MIME_TYPE = useragent.isIE; |
| 18342 |
|
| 18343 |
var TextInput = function(parentNode, host) { |
| 18344 |
var text = dom.createElement("textarea"); |
| 18345 |
text.className = "ace_text-input"; |
| 18346 |
|
| 18347 |
if (useragent.isTouchPad) |
| 18348 |
text.setAttribute("x-palm-disable-auto-cap", true); |
| 18349 |
|
| 18350 |
text.setAttribute("wrap", "off"); |
| 18351 |
text.setAttribute("autocorrect", "off"); |
| 18352 |
text.setAttribute("autocapitalize", "off"); |
| 18353 |
text.setAttribute("spellcheck", false); |
| 18354 |
|
| 18355 |
text.style.opacity = "0"; |
| 18356 |
if (useragent.isOldIE) text.style.top = "-1000px"; |
| 18357 |
parentNode.insertBefore(text, parentNode.firstChild); |
| 18358 |
|
| 18359 |
var PLACEHOLDER = "\x01\x01"; |
| 18360 |
|
| 18361 |
var copied = false; |
| 18362 |
var pasted = false; |
| 18363 |
var inComposition = false; |
| 18364 |
var tempStyle = ''; |
| 18365 |
var isSelectionEmpty = true; |
| 18366 |
try { var isFocused = document.activeElement === text; } catch(e) {} |
| 18367 |
|
| 18368 |
event.addListener(text, "blur", function(e) { |
| 18369 |
host.onBlur(e); |
| 18370 |
isFocused = false; |
| 18371 |
}); |
| 18372 |
event.addListener(text, "focus", function(e) { |
| 18373 |
isFocused = true; |
| 18374 |
host.onFocus(e); |
| 18375 |
resetSelection(); |
| 18376 |
}); |
| 18377 |
this.focus = function() { |
| 18378 |
if (tempStyle) return text.focus(); |
| 18379 |
var top = text.style.top; |
| 18380 |
text.style.position = "fixed"; |
| 18381 |
text.style.top = "0px"; |
| 18382 |
text.focus(); |
| 18383 |
setTimeout(function() { |
| 18384 |
text.style.position = ""; |
| 18385 |
if (text.style.top == "0px") |
| 18386 |
text.style.top = top; |
| 18387 |
}, 0); |
| 18388 |
}; |
| 18389 |
this.blur = function() { |
| 18390 |
text.blur(); |
| 18391 |
}; |
| 18392 |
this.isFocused = function() { |
| 18393 |
return isFocused; |
| 18394 |
}; |
| 18395 |
var syncSelection = lang.delayedCall(function() { |
| 18396 |
isFocused && resetSelection(isSelectionEmpty); |
| 18397 |
}); |
| 18398 |
var syncValue = lang.delayedCall(function() { |
| 18399 |
if (!inComposition) { |
| 18400 |
text.value = PLACEHOLDER; |
| 18401 |
isFocused && resetSelection(); |
| 18402 |
} |
| 18403 |
}); |
| 18404 |
|
| 18405 |
function resetSelection(isEmpty) { |
| 18406 |
if (inComposition) |
| 18407 |
return; |
| 18408 |
inComposition = true; |
| 18409 |
|
| 18410 |
if (inputHandler) { |
| 18411 |
selectionStart = 0; |
| 18412 |
selectionEnd = isEmpty ? 0 : text.value.length - 1; |
| 18413 |
} else { |
| 18414 |
var selectionStart = isEmpty ? 2 : 1; |
| 18415 |
var selectionEnd = 2; |
| 18416 |
} |
| 18417 |
try { |
| 18418 |
text.setSelectionRange(selectionStart, selectionEnd); |
| 18419 |
} catch(e){} |
| 18420 |
|
| 18421 |
inComposition = false; |
| 18422 |
} |
| 18423 |
|
| 18424 |
function resetValue() { |
| 18425 |
if (inComposition) |
| 18426 |
return; |
| 18427 |
text.value = PLACEHOLDER; |
| 18428 |
if (useragent.isWebKit) |
| 18429 |
syncValue.schedule(); |
| 18430 |
} |
| 18431 |
|
| 18432 |
useragent.isWebKit || host.addEventListener('changeSelection', function() { |
| 18433 |
if (host.selection.isEmpty() != isSelectionEmpty) { |
| 18434 |
isSelectionEmpty = !isSelectionEmpty; |
| 18435 |
syncSelection.schedule(); |
| 18436 |
} |
| 18437 |
}); |
| 18438 |
|
| 18439 |
resetValue(); |
| 18440 |
if (isFocused) |
| 18441 |
host.onFocus(); |
| 18442 |
|
| 18443 |
|
| 18444 |
var isAllSelected = function(text) { |
| 18445 |
return text.selectionStart === 0 && text.selectionEnd === text.value.length; |
| 18446 |
}; |
| 18447 |
if (!text.setSelectionRange && text.createTextRange) { |
| 18448 |
text.setSelectionRange = function(selectionStart, selectionEnd) { |
| 18449 |
var range = this.createTextRange(); |
| 18450 |
range.collapse(true); |
| 18451 |
range.moveStart('character', selectionStart); |
| 18452 |
range.moveEnd('character', selectionEnd); |
| 18453 |
range.select(); |
| 18454 |
}; |
| 18455 |
isAllSelected = function(text) { |
| 18456 |
try { |
| 18457 |
var range = text.ownerDocument.selection.createRange(); |
| 18458 |
}catch(e) {} |
| 18459 |
if (!range || range.parentElement() != text) return false; |
| 18460 |
return range.text == text.value; |
| 18461 |
} |
| 18462 |
} |
| 18463 |
if (useragent.isOldIE) { |
| 18464 |
var inPropertyChange = false; |
| 18465 |
var onPropertyChange = function(e){ |
| 18466 |
if (inPropertyChange) |
| 18467 |
return; |
| 18468 |
var data = text.value; |
| 18469 |
if (inComposition || !data || data == PLACEHOLDER) |
| 18470 |
return; |
| 18471 |
if (e && data == PLACEHOLDER[0]) |
| 18472 |
return syncProperty.schedule(); |
| 18473 |
|
| 18474 |
sendText(data); |
| 18475 |
inPropertyChange = true; |
| 18476 |
resetValue(); |
| 18477 |
inPropertyChange = false; |
| 18478 |
}; |
| 18479 |
var syncProperty = lang.delayedCall(onPropertyChange); |
| 18480 |
event.addListener(text, "propertychange", onPropertyChange); |
| 18481 |
|
| 18482 |
var keytable = { 13:1, 27:1 }; |
| 18483 |
event.addListener(text, "keyup", function (e) { |
| 18484 |
if (inComposition && (!text.value || keytable[e.keyCode])) |
| 18485 |
setTimeout(onCompositionEnd, 0); |
| 18486 |
if ((text.value.charCodeAt(0)||0) < 129) { |
| 18487 |
return syncProperty.call(); |
| 18488 |
} |
| 18489 |
inComposition ? onCompositionUpdate() : onCompositionStart(); |
| 18490 |
}); |
| 18491 |
event.addListener(text, "keydown", function (e) { |
| 18492 |
syncProperty.schedule(50); |
| 18493 |
}); |
| 18494 |
} |
| 18495 |
|
| 18496 |
var onSelect = function(e) { |
| 18497 |
if (copied) { |
| 18498 |
copied = false; |
| 18499 |
} else if (isAllSelected(text)) { |
| 18500 |
host.selectAll(); |
| 18501 |
resetSelection(); |
| 18502 |
} else if (inputHandler) { |
| 18503 |
resetSelection(host.selection.isEmpty()); |
| 18504 |
} |
| 18505 |
}; |
| 18506 |
|
| 18507 |
var inputHandler = null; |
| 18508 |
this.setInputHandler = function(cb) {inputHandler = cb}; |
| 18509 |
this.getInputHandler = function() {return inputHandler}; |
| 18510 |
var afterContextMenu = false; |
| 18511 |
|
| 18512 |
var sendText = function(data) { |
| 18513 |
if (inputHandler) { |
| 18514 |
data = inputHandler(data); |
| 18515 |
inputHandler = null; |
| 18516 |
} |
| 18517 |
if (pasted) { |
| 18518 |
resetSelection(); |
| 18519 |
if (data) |
| 18520 |
host.onPaste(data); |
| 18521 |
pasted = false; |
| 18522 |
} else if (data == PLACEHOLDER.charAt(0)) { |
| 18523 |
if (afterContextMenu) |
| 18524 |
host.execCommand("del", {source: "ace"}); |
| 18525 |
else // some versions of android do not fire keydown when pressing backspace |
| 18526 |
host.execCommand("backspace", {source: "ace"}); |
| 18527 |
} else { |
| 18528 |
if (data.substring(0, 2) == PLACEHOLDER) |
| 18529 |
data = data.substr(2); |
| 18530 |
else if (data.charAt(0) == PLACEHOLDER.charAt(0)) |
| 18531 |
data = data.substr(1); |
| 18532 |
else if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0)) |
| 18533 |
data = data.slice(0, -1); |
| 18534 |
if (data.charAt(data.length - 1) == PLACEHOLDER.charAt(0)) |
| 18535 |
data = data.slice(0, -1); |
| 18536 |
|
| 18537 |
if (data) |
| 18538 |
host.onTextInput(data); |
| 18539 |
} |
| 18540 |
if (afterContextMenu) |
| 18541 |
afterContextMenu = false; |
| 18542 |
}; |
| 18543 |
var onInput = function(e) { |
| 18544 |
if (inComposition) |
| 18545 |
return; |
| 18546 |
var data = text.value; |
| 18547 |
sendText(data); |
| 18548 |
resetValue(); |
| 18549 |
}; |
| 18550 |
|
| 18551 |
var handleClipboardData = function(e, data) { |
| 18552 |
var clipboardData = e.clipboardData || window.clipboardData; |
| 18553 |
if (!clipboardData || BROKEN_SETDATA) |
| 18554 |
return; |
| 18555 |
var mime = USE_IE_MIME_TYPE ? "Text" : "text/plain"; |
| 18556 |
if (data) { |
| 18557 |
return clipboardData.setData(mime, data) !== false; |
| 18558 |
} else { |
| 18559 |
return clipboardData.getData(mime); |
| 18560 |
} |
| 18561 |
}; |
| 18562 |
|
| 18563 |
var doCopy = function(e, isCut) { |
| 18564 |
var data = host.getCopyText(); |
| 18565 |
if (!data) |
| 18566 |
return event.preventDefault(e); |
| 18567 |
|
| 18568 |
if (handleClipboardData(e, data)) { |
| 18569 |
isCut ? host.onCut() : host.onCopy(); |
| 18570 |
event.preventDefault(e); |
| 18571 |
} else { |
| 18572 |
copied = true; |
| 18573 |
text.value = data; |
| 18574 |
text.select(); |
| 18575 |
setTimeout(function(){ |
| 18576 |
copied = false; |
| 18577 |
resetValue(); |
| 18578 |
resetSelection(); |
| 18579 |
isCut ? host.onCut() : host.onCopy(); |
| 18580 |
}); |
| 18581 |
} |
| 18582 |
}; |
| 18583 |
|
| 18584 |
var onCut = function(e) { |
| 18585 |
doCopy(e, true); |
| 18586 |
}; |
| 18587 |
|
| 18588 |
var onCopy = function(e) { |
| 18589 |
doCopy(e, false); |
| 18590 |
}; |
| 18591 |
|
| 18592 |
var onPaste = function(e) { |
| 18593 |
var data = handleClipboardData(e); |
| 18594 |
if (typeof data == "string") { |
| 18595 |
if (data) |
| 18596 |
host.onPaste(data, e); |
| 18597 |
if (useragent.isIE) |
| 18598 |
setTimeout(resetSelection); |
| 18599 |
event.preventDefault(e); |
| 18600 |
} |
| 18601 |
else { |
| 18602 |
text.value = ""; |
| 18603 |
pasted = true; |
| 18604 |
} |
| 18605 |
}; |
| 18606 |
|
| 18607 |
event.addCommandKeyListener(text, host.onCommandKey.bind(host)); |
| 18608 |
|
| 18609 |
event.addListener(text, "select", onSelect); |
| 18610 |
|
| 18611 |
event.addListener(text, "input", onInput); |
| 18612 |
|
| 18613 |
event.addListener(text, "cut", onCut); |
| 18614 |
event.addListener(text, "copy", onCopy); |
| 18615 |
event.addListener(text, "paste", onPaste); |
| 18616 |
if (!('oncut' in text) || !('oncopy' in text) || !('onpaste' in text)){ |
| 18617 |
event.addListener(parentNode, "keydown", function(e) { |
| 18618 |
if ((useragent.isMac && !e.metaKey) || !e.ctrlKey) |
| 18619 |
return; |
| 18620 |
|
| 18621 |
switch (e.keyCode) { |
| 18622 |
case 67: |
| 18623 |
onCopy(e); |
| 18624 |
break; |
| 18625 |
case 86: |
| 18626 |
onPaste(e); |
| 18627 |
break; |
| 18628 |
case 88: |
| 18629 |
onCut(e); |
| 18630 |
break; |
| 18631 |
} |
| 18632 |
}); |
| 18633 |
} |
| 18634 |
var onCompositionStart = function(e) { |
| 18635 |
if (inComposition || !host.onCompositionStart || host.$readOnly) |
| 18636 |
return; |
| 18637 |
inComposition = {}; |
| 18638 |
host.onCompositionStart(); |
| 18639 |
setTimeout(onCompositionUpdate, 0); |
| 18640 |
host.on("mousedown", onCompositionEnd); |
| 18641 |
if (!host.selection.isEmpty()) { |
| 18642 |
host.insert(""); |
| 18643 |
host.session.markUndoGroup(); |
| 18644 |
host.selection.clearSelection(); |
| 18645 |
} |
| 18646 |
host.session.markUndoGroup(); |
| 18647 |
}; |
| 18648 |
|
| 18649 |
var onCompositionUpdate = function() { |
| 18650 |
if (!inComposition || !host.onCompositionUpdate || host.$readOnly) |
| 18651 |
return; |
| 18652 |
var val = text.value.replace(/\x01/g, ""); |
| 18653 |
if (inComposition.lastValue === val) return; |
| 18654 |
|
| 18655 |
host.onCompositionUpdate(val); |
| 18656 |
if (inComposition.lastValue) |
| 18657 |
host.undo(); |
| 18658 |
inComposition.lastValue = val; |
| 18659 |
if (inComposition.lastValue) { |
| 18660 |
var r = host.selection.getRange(); |
| 18661 |
host.insert(inComposition.lastValue); |
| 18662 |
host.session.markUndoGroup(); |
| 18663 |
inComposition.range = host.selection.getRange(); |
| 18664 |
host.selection.setRange(r); |
| 18665 |
host.selection.clearSelection(); |
| 18666 |
} |
| 18667 |
}; |
| 18668 |
|
| 18669 |
var onCompositionEnd = function(e) { |
| 18670 |
if (!host.onCompositionEnd || host.$readOnly) return; |
| 18671 |
var c = inComposition; |
| 18672 |
inComposition = false; |
| 18673 |
var timer = setTimeout(function() { |
| 18674 |
timer = null; |
| 18675 |
var str = text.value.replace(/\x01/g, ""); |
| 18676 |
if (inComposition) |
| 18677 |
return; |
| 18678 |
else if (str == c.lastValue) |
| 18679 |
resetValue(); |
| 18680 |
else if (!c.lastValue && str) { |
| 18681 |
resetValue(); |
| 18682 |
sendText(str); |
| 18683 |
} |
| 18684 |
}); |
| 18685 |
inputHandler = function compositionInputHandler(str) { |
| 18686 |
if (timer) |
| 18687 |
clearTimeout(timer); |
| 18688 |
str = str.replace(/\x01/g, ""); |
| 18689 |
if (str == c.lastValue) |
| 18690 |
return ""; |
| 18691 |
if (c.lastValue && timer) |
| 18692 |
host.undo(); |
| 18693 |
return str; |
| 18694 |
}; |
| 18695 |
host.onCompositionEnd(); |
| 18696 |
host.removeListener("mousedown", onCompositionEnd); |
| 18697 |
if (e.type == "compositionend" && c.range) { |
| 18698 |
host.selection.setRange(c.range); |
| 18699 |
} |
| 18700 |
}; |
| 18701 |
|
| 18702 |
|
| 18703 |
|
| 18704 |
var syncComposition = lang.delayedCall(onCompositionUpdate, 50); |
| 18705 |
|
| 18706 |
event.addListener(text, "compositionstart", onCompositionStart); |
| 18707 |
if (useragent.isGecko) { |
| 18708 |
event.addListener(text, "text", function(){syncComposition.schedule()}); |
| 18709 |
} else { |
| 18710 |
event.addListener(text, "keyup", function(){syncComposition.schedule()}); |
| 18711 |
event.addListener(text, "keydown", function(){syncComposition.schedule()}); |
| 18712 |
} |
| 18713 |
event.addListener(text, "compositionend", onCompositionEnd); |
| 18714 |
|
| 18715 |
this.getElement = function() { |
| 18716 |
return text; |
| 18717 |
}; |
| 18718 |
|
| 18719 |
this.setReadOnly = function(readOnly) { |
| 18720 |
text.readOnly = readOnly; |
| 18721 |
}; |
| 18722 |
|
| 18723 |
this.onContextMenu = function(e) { |
| 18724 |
afterContextMenu = true; |
| 18725 |
resetSelection(host.selection.isEmpty()); |
| 18726 |
host._emit("nativecontextmenu", {target: host, domEvent: e}); |
| 18727 |
this.moveToMouse(e, true); |
| 18728 |
}; |
| 18729 |
|
| 18730 |
this.moveToMouse = function(e, bringToFront) { |
| 18731 |
if (!bringToFront && useragent.isOldIE) |
| 18732 |
return; |
| 18733 |
if (!tempStyle) |
| 18734 |
tempStyle = text.style.cssText; |
| 18735 |
text.style.cssText = (bringToFront ? "z-index:100000;" : "") |
| 18736 |
+ "height:" + text.style.height + ";" |
| 18737 |
+ (useragent.isIE ? "opacity:0.1;" : ""); |
| 18738 |
|
| 18739 |
var rect = host.container.getBoundingClientRect(); |
| 18740 |
var style = dom.computedStyle(host.container); |
| 18741 |
var top = rect.top + (parseInt(style.borderTopWidth) || 0); |
| 18742 |
var left = rect.left + (parseInt(rect.borderLeftWidth) || 0); |
| 18743 |
var maxTop = rect.bottom - top - text.clientHeight -2; |
| 18744 |
var move = function(e) { |
| 18745 |
text.style.left = e.clientX - left - 2 + "px"; |
| 18746 |
text.style.top = Math.min(e.clientY - top - 2, maxTop) + "px"; |
| 18747 |
}; |
| 18748 |
move(e); |
| 18749 |
|
| 18750 |
if (e.type != "mousedown") |
| 18751 |
return; |
| 18752 |
|
| 18753 |
if (host.renderer.$keepTextAreaAtCursor) |
| 18754 |
host.renderer.$keepTextAreaAtCursor = null; |
| 18755 |
|
| 18756 |
clearTimeout(closeTimeout); |
| 18757 |
if (useragent.isWin && !useragent.isOldIE) |
| 18758 |
event.capture(host.container, move, onContextMenuClose); |
| 18759 |
}; |
| 18760 |
|
| 18761 |
this.onContextMenuClose = onContextMenuClose; |
| 18762 |
var closeTimeout; |
| 18763 |
function onContextMenuClose() { |
| 18764 |
clearTimeout(closeTimeout); |
| 18765 |
closeTimeout = setTimeout(function () { |
| 18766 |
if (tempStyle) { |
| 18767 |
text.style.cssText = tempStyle; |
| 18768 |
tempStyle = ''; |
| 18769 |
} |
| 18770 |
if (host.renderer.$keepTextAreaAtCursor == null) { |
| 18771 |
host.renderer.$keepTextAreaAtCursor = true; |
| 18772 |
host.renderer.$moveTextAreaToCursor(); |
| 18773 |
} |
| 18774 |
}, useragent.isOldIE ? 200 : 0); |
| 18775 |
} |
| 18776 |
|
| 18777 |
var onContextMenu = function(e) { |
| 18778 |
host.textInput.onContextMenu(e); |
| 18779 |
onContextMenuClose(); |
| 18780 |
}; |
| 18781 |
event.addListener(text, "mouseup", onContextMenu); |
| 18782 |
event.addListener(text, "mousedown", function(e) { |
| 18783 |
e.preventDefault(); |
| 18784 |
onContextMenuClose(); |
| 18785 |
}); |
| 18786 |
event.addListener(host.renderer.scroller, "contextmenu", onContextMenu); |
| 18787 |
event.addListener(text, "contextmenu", onContextMenu); |
| 18788 |
}; |
| 18789 |
|
| 18790 |
exports.TextInput = TextInput; |
| 18791 |
}); |
| 18792 |
|
| 18793 |
ace.define("ace/mouse/default_handlers",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(acequire, exports, module) { |
| 18794 |
"use strict"; |
| 18795 |
|
| 18796 |
var dom = acequire("../lib/dom"); |
| 18797 |
var event = acequire("../lib/event"); |
| 18798 |
var useragent = acequire("../lib/useragent"); |
| 18799 |
|
| 18800 |
var DRAG_OFFSET = 0; // pixels |
| 18801 |
|
| 18802 |
function DefaultHandlers(mouseHandler) { |
| 18803 |
mouseHandler.$clickSelection = null; |
| 18804 |
|
| 18805 |
var editor = mouseHandler.editor; |
| 18806 |
editor.setDefaultHandler("mousedown", this.onMouseDown.bind(mouseHandler)); |
| 18807 |
editor.setDefaultHandler("dblclick", this.onDoubleClick.bind(mouseHandler)); |
| 18808 |
editor.setDefaultHandler("tripleclick", this.onTripleClick.bind(mouseHandler)); |
| 18809 |
editor.setDefaultHandler("quadclick", this.onQuadClick.bind(mouseHandler)); |
| 18810 |
editor.setDefaultHandler("mousewheel", this.onMouseWheel.bind(mouseHandler)); |
| 18811 |
editor.setDefaultHandler("touchmove", this.onTouchMove.bind(mouseHandler)); |
| 18812 |
|
| 18813 |
var exports = ["select", "startSelect", "selectEnd", "selectAllEnd", "selectByWordsEnd", |
| 18814 |
"selectByLinesEnd", "dragWait", "dragWaitEnd", "focusWait"]; |
| 18815 |
|
| 18816 |
exports.forEach(function(x) { |
| 18817 |
mouseHandler[x] = this[x]; |
| 18818 |
}, this); |
| 18819 |
|
| 18820 |
mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange"); |
| 18821 |
mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange"); |
| 18822 |
} |
| 18823 |
|
| 18824 |
(function() { |
| 18825 |
|
| 18826 |
this.onMouseDown = function(ev) { |
| 18827 |
var inSelection = ev.inSelection(); |
| 18828 |
var pos = ev.getDocumentPosition(); |
| 18829 |
this.mousedownEvent = ev; |
| 18830 |
var editor = this.editor; |
| 18831 |
|
| 18832 |
var button = ev.getButton(); |
| 18833 |
if (button !== 0) { |
| 18834 |
var selectionRange = editor.getSelectionRange(); |
| 18835 |
var selectionEmpty = selectionRange.isEmpty(); |
| 18836 |
editor.$blockScrolling++; |
| 18837 |
if (selectionEmpty || button == 1) |
| 18838 |
editor.selection.moveToPosition(pos); |
| 18839 |
editor.$blockScrolling--; |
| 18840 |
if (button == 2) |
| 18841 |
editor.textInput.onContextMenu(ev.domEvent); |
| 18842 |
return; // stopping event here breaks contextmenu on ff mac |
| 18843 |
} |
| 18844 |
|
| 18845 |
this.mousedownEvent.time = Date.now(); |
| 18846 |
if (inSelection && !editor.isFocused()) { |
| 18847 |
editor.focus(); |
| 18848 |
if (this.$focusTimout && !this.$clickSelection && !editor.inMultiSelectMode) { |
| 18849 |
this.setState("focusWait"); |
| 18850 |
this.captureMouse(ev); |
| 18851 |
return; |
| 18852 |
} |
| 18853 |
} |
| 18854 |
|
| 18855 |
this.captureMouse(ev); |
| 18856 |
this.startSelect(pos, ev.domEvent._clicks > 1); |
| 18857 |
return ev.preventDefault(); |
| 18858 |
}; |
| 18859 |
|
| 18860 |
this.startSelect = function(pos, waitForClickSelection) { |
| 18861 |
pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y); |
| 18862 |
var editor = this.editor; |
| 18863 |
editor.$blockScrolling++; |
| 18864 |
if (this.mousedownEvent.getShiftKey()) |
| 18865 |
editor.selection.selectToPosition(pos); |
| 18866 |
else if (!waitForClickSelection) |
| 18867 |
editor.selection.moveToPosition(pos); |
| 18868 |
if (!waitForClickSelection) |
| 18869 |
this.select(); |
| 18870 |
if (editor.renderer.scroller.setCapture) { |
| 18871 |
editor.renderer.scroller.setCapture(); |
| 18872 |
} |
| 18873 |
editor.setStyle("ace_selecting"); |
| 18874 |
this.setState("select"); |
| 18875 |
editor.$blockScrolling--; |
| 18876 |
}; |
| 18877 |
|
| 18878 |
this.select = function() { |
| 18879 |
var anchor, editor = this.editor; |
| 18880 |
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y); |
| 18881 |
editor.$blockScrolling++; |
| 18882 |
if (this.$clickSelection) { |
| 18883 |
var cmp = this.$clickSelection.comparePoint(cursor); |
| 18884 |
|
| 18885 |
if (cmp == -1) { |
| 18886 |
anchor = this.$clickSelection.end; |
| 18887 |
} else if (cmp == 1) { |
| 18888 |
anchor = this.$clickSelection.start; |
| 18889 |
} else { |
| 18890 |
var orientedRange = calcRangeOrientation(this.$clickSelection, cursor); |
| 18891 |
cursor = orientedRange.cursor; |
| 18892 |
anchor = orientedRange.anchor; |
| 18893 |
} |
| 18894 |
editor.selection.setSelectionAnchor(anchor.row, anchor.column); |
| 18895 |
} |
| 18896 |
editor.selection.selectToPosition(cursor); |
| 18897 |
editor.$blockScrolling--; |
| 18898 |
editor.renderer.scrollCursorIntoView(); |
| 18899 |
}; |
| 18900 |
|
| 18901 |
this.extendSelectionBy = function(unitName) { |
| 18902 |
var anchor, editor = this.editor; |
| 18903 |
var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y); |
| 18904 |
var range = editor.selection[unitName](cursor.row, cursor.column); |
| 18905 |
editor.$blockScrolling++; |
| 18906 |
if (this.$clickSelection) { |
| 18907 |
var cmpStart = this.$clickSelection.comparePoint(range.start); |
| 18908 |
var cmpEnd = this.$clickSelection.comparePoint(range.end); |
| 18909 |
|
| 18910 |
if (cmpStart == -1 && cmpEnd <= 0) { |
| 18911 |
anchor = this.$clickSelection.end; |
| 18912 |
if (range.end.row != cursor.row || range.end.column != cursor.column) |
| 18913 |
cursor = range.start; |
| 18914 |
} else if (cmpEnd == 1 && cmpStart >= 0) { |
| 18915 |
anchor = this.$clickSelection.start; |
| 18916 |
if (range.start.row != cursor.row || range.start.column != cursor.column) |
| 18917 |
cursor = range.end; |
| 18918 |
} else if (cmpStart == -1 && cmpEnd == 1) { |
| 18919 |
cursor = range.end; |
| 18920 |
anchor = range.start; |
| 18921 |
} else { |
| 18922 |
var orientedRange = calcRangeOrientation(this.$clickSelection, cursor); |
| 18923 |
cursor = orientedRange.cursor; |
| 18924 |
anchor = orientedRange.anchor; |
| 18925 |
} |
| 18926 |
editor.selection.setSelectionAnchor(anchor.row, anchor.column); |
| 18927 |
} |
| 18928 |
editor.selection.selectToPosition(cursor); |
| 18929 |
editor.$blockScrolling--; |
| 18930 |
editor.renderer.scrollCursorIntoView(); |
| 18931 |
}; |
| 18932 |
|
| 18933 |
this.selectEnd = |
| 18934 |
this.selectAllEnd = |
| 18935 |
this.selectByWordsEnd = |
| 18936 |
this.selectByLinesEnd = function() { |
| 18937 |
this.$clickSelection = null; |
| 18938 |
this.editor.unsetStyle("ace_selecting"); |
| 18939 |
if (this.editor.renderer.scroller.releaseCapture) { |
| 18940 |
this.editor.renderer.scroller.releaseCapture(); |
| 18941 |
} |
| 18942 |
}; |
| 18943 |
|
| 18944 |
this.focusWait = function() { |
| 18945 |
var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y); |
| 18946 |
var time = Date.now(); |
| 18947 |
|
| 18948 |
if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimout) |
| 18949 |
this.startSelect(this.mousedownEvent.getDocumentPosition()); |
| 18950 |
}; |
| 18951 |
|
| 18952 |
this.onDoubleClick = function(ev) { |
| 18953 |
var pos = ev.getDocumentPosition(); |
| 18954 |
var editor = this.editor; |
| 18955 |
var session = editor.session; |
| 18956 |
|
| 18957 |
var range = session.getBracketRange(pos); |
| 18958 |
if (range) { |
| 18959 |
if (range.isEmpty()) { |
| 18960 |
range.start.column--; |
| 18961 |
range.end.column++; |
| 18962 |
} |
| 18963 |
this.setState("select"); |
| 18964 |
} else { |
| 18965 |
range = editor.selection.getWordRange(pos.row, pos.column); |
| 18966 |
this.setState("selectByWords"); |
| 18967 |
} |
| 18968 |
this.$clickSelection = range; |
| 18969 |
this.select(); |
| 18970 |
}; |
| 18971 |
|
| 18972 |
this.onTripleClick = function(ev) { |
| 18973 |
var pos = ev.getDocumentPosition(); |
| 18974 |
var editor = this.editor; |
| 18975 |
|
| 18976 |
this.setState("selectByLines"); |
| 18977 |
var range = editor.getSelectionRange(); |
| 18978 |
if (range.isMultiLine() && range.contains(pos.row, pos.column)) { |
| 18979 |
this.$clickSelection = editor.selection.getLineRange(range.start.row); |
| 18980 |
this.$clickSelection.end = editor.selection.getLineRange(range.end.row).end; |
| 18981 |
} else { |
| 18982 |
this.$clickSelection = editor.selection.getLineRange(pos.row); |
| 18983 |
} |
| 18984 |
this.select(); |
| 18985 |
}; |
| 18986 |
|
| 18987 |
this.onQuadClick = function(ev) { |
| 18988 |
var editor = this.editor; |
| 18989 |
|
| 18990 |
editor.selectAll(); |
| 18991 |
this.$clickSelection = editor.getSelectionRange(); |
| 18992 |
this.setState("selectAll"); |
| 18993 |
}; |
| 18994 |
|
| 18995 |
this.onMouseWheel = function(ev) { |
| 18996 |
if (ev.getAccelKey()) |
| 18997 |
return; |
| 18998 |
if (ev.getShiftKey() && ev.wheelY && !ev.wheelX) { |
| 18999 |
ev.wheelX = ev.wheelY; |
| 19000 |
ev.wheelY = 0; |
| 19001 |
} |
| 19002 |
|
| 19003 |
var t = ev.domEvent.timeStamp; |
| 19004 |
var dt = t - (this.$lastScrollTime||0); |
| 19005 |
|
| 19006 |
var editor = this.editor; |
| 19007 |
var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed); |
| 19008 |
if (isScrolable || dt < 200) { |
| 19009 |
this.$lastScrollTime = t; |
| 19010 |
editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed); |
| 19011 |
return ev.stop(); |
| 19012 |
} |
| 19013 |
}; |
| 19014 |
|
| 19015 |
this.onTouchMove = function (ev) { |
| 19016 |
var t = ev.domEvent.timeStamp; |
| 19017 |
var dt = t - (this.$lastScrollTime || 0); |
| 19018 |
|
| 19019 |
var editor = this.editor; |
| 19020 |
var isScrolable = editor.renderer.isScrollableBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed); |
| 19021 |
if (isScrolable || dt < 200) { |
| 19022 |
this.$lastScrollTime = t; |
| 19023 |
editor.renderer.scrollBy(ev.wheelX * ev.speed, ev.wheelY * ev.speed); |
| 19024 |
return ev.stop(); |
| 19025 |
} |
| 19026 |
}; |
| 19027 |
|
| 19028 |
}).call(DefaultHandlers.prototype); |
| 19029 |
|
| 19030 |
exports.DefaultHandlers = DefaultHandlers; |
| 19031 |
|
| 19032 |
function calcDistance(ax, ay, bx, by) { |
| 19033 |
return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2)); |
| 19034 |
} |
| 19035 |
|
| 19036 |
function calcRangeOrientation(range, cursor) { |
| 19037 |
if (range.start.row == range.end.row) |
| 19038 |
var cmp = 2 * cursor.column - range.start.column - range.end.column; |
| 19039 |
else if (range.start.row == range.end.row - 1 && !range.start.column && !range.end.column) |
| 19040 |
var cmp = cursor.column - 4; |
| 19041 |
else |
| 19042 |
var cmp = 2 * cursor.row - range.start.row - range.end.row; |
| 19043 |
|
| 19044 |
if (cmp < 0) |
| 19045 |
return {cursor: range.start, anchor: range.end}; |
| 19046 |
else |
| 19047 |
return {cursor: range.end, anchor: range.start}; |
| 19048 |
} |
| 19049 |
|
| 19050 |
}); |
| 19051 |
|
| 19052 |
ace.define("ace/tooltip",["require","exports","module","ace/lib/oop","ace/lib/dom"], function(acequire, exports, module) { |
| 19053 |
"use strict"; |
| 19054 |
|
| 19055 |
var oop = acequire("./lib/oop"); |
| 19056 |
var dom = acequire("./lib/dom"); |
| 19057 |
function Tooltip (parentNode) { |
| 19058 |
this.isOpen = false; |
| 19059 |
this.$element = null; |
| 19060 |
this.$parentNode = parentNode; |
| 19061 |
} |
| 19062 |
|
| 19063 |
(function() { |
| 19064 |
this.$init = function() { |
| 19065 |
this.$element = dom.createElement("div"); |
| 19066 |
this.$element.className = "ace_tooltip"; |
| 19067 |
this.$element.style.display = "none"; |
| 19068 |
this.$parentNode.appendChild(this.$element); |
| 19069 |
return this.$element; |
| 19070 |
}; |
| 19071 |
this.getElement = function() { |
| 19072 |
return this.$element || this.$init(); |
| 19073 |
}; |
| 19074 |
this.setText = function(text) { |
| 19075 |
dom.setInnerText(this.getElement(), text); |
| 19076 |
}; |
| 19077 |
this.setHtml = function(html) { |
| 19078 |
this.getElement().innerHTML = html; |
| 19079 |
}; |
| 19080 |
this.setPosition = function(x, y) { |
| 19081 |
this.getElement().style.left = x + "px"; |
| 19082 |
this.getElement().style.top = y + "px"; |
| 19083 |
}; |
| 19084 |
this.setClassName = function(className) { |
| 19085 |
dom.addCssClass(this.getElement(), className); |
| 19086 |
}; |
| 19087 |
this.show = function(text, x, y) { |
| 19088 |
if (text != null) |
| 19089 |
this.setText(text); |
| 19090 |
if (x != null && y != null) |
| 19091 |
this.setPosition(x, y); |
| 19092 |
if (!this.isOpen) { |
| 19093 |
this.getElement().style.display = "block"; |
| 19094 |
this.isOpen = true; |
| 19095 |
} |
| 19096 |
}; |
| 19097 |
|
| 19098 |
this.hide = function() { |
| 19099 |
if (this.isOpen) { |
| 19100 |
this.getElement().style.display = "none"; |
| 19101 |
this.isOpen = false; |
| 19102 |
} |
| 19103 |
}; |
| 19104 |
this.getHeight = function() { |
| 19105 |
return this.getElement().offsetHeight; |
| 19106 |
}; |
| 19107 |
this.getWidth = function() { |
| 19108 |
return this.getElement().offsetWidth; |
| 19109 |
}; |
| 19110 |
|
| 19111 |
}).call(Tooltip.prototype); |
| 19112 |
|
| 19113 |
exports.Tooltip = Tooltip; |
| 19114 |
}); |
| 19115 |
|
| 19116 |
ace.define("ace/mouse/default_gutter_handler",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/event","ace/tooltip"], function(acequire, exports, module) { |
| 19117 |
"use strict"; |
| 19118 |
var dom = acequire("../lib/dom"); |
| 19119 |
var oop = acequire("../lib/oop"); |
| 19120 |
var event = acequire("../lib/event"); |
| 19121 |
var Tooltip = acequire("../tooltip").Tooltip; |
| 19122 |
|
| 19123 |
function GutterHandler(mouseHandler) { |
| 19124 |
var editor = mouseHandler.editor; |
| 19125 |
var gutter = editor.renderer.$gutterLayer; |
| 19126 |
var tooltip = new GutterTooltip(editor.container); |
| 19127 |
|
| 19128 |
mouseHandler.editor.setDefaultHandler("guttermousedown", function(e) { |
| 19129 |
if (!editor.isFocused() || e.getButton() != 0) |
| 19130 |
return; |
| 19131 |
var gutterRegion = gutter.getRegion(e); |
| 19132 |
|
| 19133 |
if (gutterRegion == "foldWidgets") |
| 19134 |
return; |
| 19135 |
|
| 19136 |
var row = e.getDocumentPosition().row; |
| 19137 |
var selection = editor.session.selection; |
| 19138 |
|
| 19139 |
if (e.getShiftKey()) |
| 19140 |
selection.selectTo(row, 0); |
| 19141 |
else { |
| 19142 |
if (e.domEvent.detail == 2) { |
| 19143 |
editor.selectAll(); |
| 19144 |
return e.preventDefault(); |
| 19145 |
} |
| 19146 |
mouseHandler.$clickSelection = editor.selection.getLineRange(row); |
| 19147 |
} |
| 19148 |
mouseHandler.setState("selectByLines"); |
| 19149 |
mouseHandler.captureMouse(e); |
| 19150 |
return e.preventDefault(); |
| 19151 |
}); |
| 19152 |
|
| 19153 |
|
| 19154 |
var tooltipTimeout, mouseEvent, tooltipAnnotation; |
| 19155 |
|
| 19156 |
function showTooltip() { |
| 19157 |
var row = mouseEvent.getDocumentPosition().row; |
| 19158 |
var annotation = gutter.$annotations[row]; |
| 19159 |
if (!annotation) |
| 19160 |
return hideTooltip(); |
| 19161 |
|
| 19162 |
var maxRow = editor.session.getLength(); |
| 19163 |
if (row == maxRow) { |
| 19164 |
var screenRow = editor.renderer.pixelToScreenCoordinates(0, mouseEvent.y).row; |
| 19165 |
var pos = mouseEvent.$pos; |
| 19166 |
if (screenRow > editor.session.documentToScreenRow(pos.row, pos.column)) |
| 19167 |
return hideTooltip(); |
| 19168 |
} |
| 19169 |
|
| 19170 |
if (tooltipAnnotation == annotation) |
| 19171 |
return; |
| 19172 |
tooltipAnnotation = annotation.text.join("<br/>"); |
| 19173 |
|
| 19174 |
tooltip.setHtml(tooltipAnnotation); |
| 19175 |
tooltip.show(); |
| 19176 |
editor.on("mousewheel", hideTooltip); |
| 19177 |
|
| 19178 |
if (mouseHandler.$tooltipFollowsMouse) { |
| 19179 |
moveTooltip(mouseEvent); |
| 19180 |
} else { |
| 19181 |
var gutterElement = mouseEvent.domEvent.target; |
| 19182 |
var rect = gutterElement.getBoundingClientRect(); |
| 19183 |
var style = tooltip.getElement().style; |
| 19184 |
style.left = rect.right + "px"; |
| 19185 |
style.top = rect.bottom + "px"; |
| 19186 |
} |
| 19187 |
} |
| 19188 |
|
| 19189 |
function hideTooltip() { |
| 19190 |
if (tooltipTimeout) |
| 19191 |
tooltipTimeout = clearTimeout(tooltipTimeout); |
| 19192 |
if (tooltipAnnotation) { |
| 19193 |
tooltip.hide(); |
| 19194 |
tooltipAnnotation = null; |
| 19195 |
editor.removeEventListener("mousewheel", hideTooltip); |
| 19196 |
} |
| 19197 |
} |
| 19198 |
|
| 19199 |
function moveTooltip(e) { |
| 19200 |
tooltip.setPosition(e.x, e.y); |
| 19201 |
} |
| 19202 |
|
| 19203 |
mouseHandler.editor.setDefaultHandler("guttermousemove", function(e) { |
| 19204 |
var target = e.domEvent.target || e.domEvent.srcElement; |
| 19205 |
if (dom.hasCssClass(target, "ace_fold-widget")) |
| 19206 |
return hideTooltip(); |
| 19207 |
|
| 19208 |
if (tooltipAnnotation && mouseHandler.$tooltipFollowsMouse) |
| 19209 |
moveTooltip(e); |
| 19210 |
|
| 19211 |
mouseEvent = e; |
| 19212 |
if (tooltipTimeout) |
| 19213 |
return; |
| 19214 |
tooltipTimeout = setTimeout(function() { |
| 19215 |
tooltipTimeout = null; |
| 19216 |
if (mouseEvent && !mouseHandler.isMousePressed) |
| 19217 |
showTooltip(); |
| 19218 |
else |
| 19219 |
hideTooltip(); |
| 19220 |
}, 50); |
| 19221 |
}); |
| 19222 |
|
| 19223 |
event.addListener(editor.renderer.$gutter, "mouseout", function(e) { |
| 19224 |
mouseEvent = null; |
| 19225 |
if (!tooltipAnnotation || tooltipTimeout) |
| 19226 |
return; |
| 19227 |
|
| 19228 |
tooltipTimeout = setTimeout(function() { |
| 19229 |
tooltipTimeout = null; |
| 19230 |
hideTooltip(); |
| 19231 |
}, 50); |
| 19232 |
}); |
| 19233 |
|
| 19234 |
editor.on("changeSession", hideTooltip); |
| 19235 |
} |
| 19236 |
|
| 19237 |
function GutterTooltip(parentNode) { |
| 19238 |
Tooltip.call(this, parentNode); |
| 19239 |
} |
| 19240 |
|
| 19241 |
oop.inherits(GutterTooltip, Tooltip); |
| 19242 |
|
| 19243 |
(function(){ |
| 19244 |
this.setPosition = function(x, y) { |
| 19245 |
var windowWidth = window.innerWidth || document.documentElement.clientWidth; |
| 19246 |
var windowHeight = window.innerHeight || document.documentElement.clientHeight; |
| 19247 |
var width = this.getWidth(); |
| 19248 |
var height = this.getHeight(); |
| 19249 |
x += 15; |
| 19250 |
y += 15; |
| 19251 |
if (x + width > windowWidth) { |
| 19252 |
x -= (x + width) - windowWidth; |
| 19253 |
} |
| 19254 |
if (y + height > windowHeight) { |
| 19255 |
y -= 20 + height; |
| 19256 |
} |
| 19257 |
Tooltip.prototype.setPosition.call(this, x, y); |
| 19258 |
}; |
| 19259 |
|
| 19260 |
}).call(GutterTooltip.prototype); |
| 19261 |
|
| 19262 |
|
| 19263 |
|
| 19264 |
exports.GutterHandler = GutterHandler; |
| 19265 |
|
| 19266 |
}); |
| 19267 |
|
| 19268 |
ace.define("ace/mouse/mouse_event",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(acequire, exports, module) { |
| 19269 |
"use strict"; |
| 19270 |
|
| 19271 |
var event = acequire("../lib/event"); |
| 19272 |
var useragent = acequire("../lib/useragent"); |
| 19273 |
var MouseEvent = exports.MouseEvent = function(domEvent, editor) { |
| 19274 |
this.domEvent = domEvent; |
| 19275 |
this.editor = editor; |
| 19276 |
|
| 19277 |
this.x = this.clientX = domEvent.clientX; |
| 19278 |
this.y = this.clientY = domEvent.clientY; |
| 19279 |
|
| 19280 |
this.$pos = null; |
| 19281 |
this.$inSelection = null; |
| 19282 |
|
| 19283 |
this.propagationStopped = false; |
| 19284 |
this.defaultPrevented = false; |
| 19285 |
}; |
| 19286 |
|
| 19287 |
(function() { |
| 19288 |
|
| 19289 |
this.stopPropagation = function() { |
| 19290 |
event.stopPropagation(this.domEvent); |
| 19291 |
this.propagationStopped = true; |
| 19292 |
}; |
| 19293 |
|
| 19294 |
this.preventDefault = function() { |
| 19295 |
event.preventDefault(this.domEvent); |
| 19296 |
this.defaultPrevented = true; |
| 19297 |
}; |
| 19298 |
|
| 19299 |
this.stop = function() { |
| 19300 |
this.stopPropagation(); |
| 19301 |
this.preventDefault(); |
| 19302 |
}; |
| 19303 |
this.getDocumentPosition = function() { |
| 19304 |
if (this.$pos) |
| 19305 |
return this.$pos; |
| 19306 |
|
| 19307 |
this.$pos = this.editor.renderer.screenToTextCoordinates(this.clientX, this.clientY); |
| 19308 |
return this.$pos; |
| 19309 |
}; |
| 19310 |
this.inSelection = function() { |
| 19311 |
if (this.$inSelection !== null) |
| 19312 |
return this.$inSelection; |
| 19313 |
|
| 19314 |
var editor = this.editor; |
| 19315 |
|
| 19316 |
|
| 19317 |
var selectionRange = editor.getSelectionRange(); |
| 19318 |
if (selectionRange.isEmpty()) |
| 19319 |
this.$inSelection = false; |
| 19320 |
else { |
| 19321 |
var pos = this.getDocumentPosition(); |
| 19322 |
this.$inSelection = selectionRange.contains(pos.row, pos.column); |
| 19323 |
} |
| 19324 |
|
| 19325 |
return this.$inSelection; |
| 19326 |
}; |
| 19327 |
this.getButton = function() { |
| 19328 |
return event.getButton(this.domEvent); |
| 19329 |
}; |
| 19330 |
this.getShiftKey = function() { |
| 19331 |
return this.domEvent.shiftKey; |
| 19332 |
}; |
| 19333 |
|
| 19334 |
this.getAccelKey = useragent.isMac |
| 19335 |
? function() { return this.domEvent.metaKey; } |
| 19336 |
: function() { return this.domEvent.ctrlKey; }; |
| 19337 |
|
| 19338 |
}).call(MouseEvent.prototype); |
| 19339 |
|
| 19340 |
}); |
| 19341 |
|
| 19342 |
ace.define("ace/mouse/dragdrop_handler",["require","exports","module","ace/lib/dom","ace/lib/event","ace/lib/useragent"], function(acequire, exports, module) { |
| 19343 |
"use strict"; |
| 19344 |
|
| 19345 |
var dom = acequire("../lib/dom"); |
| 19346 |
var event = acequire("../lib/event"); |
| 19347 |
var useragent = acequire("../lib/useragent"); |
| 19348 |
|
| 19349 |
var AUTOSCROLL_DELAY = 200; |
| 19350 |
var SCROLL_CURSOR_DELAY = 200; |
| 19351 |
var SCROLL_CURSOR_HYSTERESIS = 5; |
| 19352 |
|
| 19353 |
function DragdropHandler(mouseHandler) { |
| 19354 |
|
| 19355 |
var editor = mouseHandler.editor; |
| 19356 |
|
| 19357 |
var blankImage = dom.createElement("img"); |
| 19358 |
blankImage.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="; |
| 19359 |
if (useragent.isOpera) |
| 19360 |
blankImage.style.cssText = "width:1px;height:1px;position:fixed;top:0;left:0;z-index:2147483647;opacity:0;"; |
| 19361 |
|
| 19362 |
var exports = ["dragWait", "dragWaitEnd", "startDrag", "dragReadyEnd", "onMouseDrag"]; |
| 19363 |
|
| 19364 |
exports.forEach(function(x) { |
| 19365 |
mouseHandler[x] = this[x]; |
| 19366 |
}, this); |
| 19367 |
editor.addEventListener("mousedown", this.onMouseDown.bind(mouseHandler)); |
| 19368 |
|
| 19369 |
|
| 19370 |
var mouseTarget = editor.container; |
| 19371 |
var dragSelectionMarker, x, y; |
| 19372 |
var timerId, range; |
| 19373 |
var dragCursor, counter = 0; |
| 19374 |
var dragOperation; |
| 19375 |
var isInternal; |
| 19376 |
var autoScrollStartTime; |
| 19377 |
var cursorMovedTime; |
| 19378 |
var cursorPointOnCaretMoved; |
| 19379 |
|
| 19380 |
this.onDragStart = function(e) { |
| 19381 |
if (this.cancelDrag || !mouseTarget.draggable) { |
| 19382 |
var self = this; |
| 19383 |
setTimeout(function(){ |
| 19384 |
self.startSelect(); |
| 19385 |
self.captureMouse(e); |
| 19386 |
}, 0); |
| 19387 |
return e.preventDefault(); |
| 19388 |
} |
| 19389 |
range = editor.getSelectionRange(); |
| 19390 |
|
| 19391 |
var dataTransfer = e.dataTransfer; |
| 19392 |
dataTransfer.effectAllowed = editor.getReadOnly() ? "copy" : "copyMove"; |
| 19393 |
if (useragent.isOpera) { |
| 19394 |
editor.container.appendChild(blankImage); |
| 19395 |
blankImage.scrollTop = 0; |
| 19396 |
} |
| 19397 |
dataTransfer.setDragImage && dataTransfer.setDragImage(blankImage, 0, 0); |
| 19398 |
if (useragent.isOpera) { |
| 19399 |
editor.container.removeChild(blankImage); |
| 19400 |
} |
| 19401 |
dataTransfer.clearData(); |
| 19402 |
dataTransfer.setData("Text", editor.session.getTextRange()); |
| 19403 |
|
| 19404 |
isInternal = true; |
| 19405 |
this.setState("drag"); |
| 19406 |
}; |
| 19407 |
|
| 19408 |
this.onDragEnd = function(e) { |
| 19409 |
mouseTarget.draggable = false; |
| 19410 |
isInternal = false; |
| 19411 |
this.setState(null); |
| 19412 |
if (!editor.getReadOnly()) { |
| 19413 |
var dropEffect = e.dataTransfer.dropEffect; |
| 19414 |
if (!dragOperation && dropEffect == "move") |
| 19415 |
editor.session.remove(editor.getSelectionRange()); |
| 19416 |
editor.renderer.$cursorLayer.setBlinking(true); |
| 19417 |
} |
| 19418 |
this.editor.unsetStyle("ace_dragging"); |
| 19419 |
this.editor.renderer.setCursorStyle(""); |
| 19420 |
}; |
| 19421 |
|
| 19422 |
this.onDragEnter = function(e) { |
| 19423 |
if (editor.getReadOnly() || !canAccept(e.dataTransfer)) |
| 19424 |
return; |
| 19425 |
x = e.clientX; |
| 19426 |
y = e.clientY; |
| 19427 |
if (!dragSelectionMarker) |
| 19428 |
addDragMarker(); |
| 19429 |
counter++; |
| 19430 |
e.dataTransfer.dropEffect = dragOperation = getDropEffect(e); |
| 19431 |
return event.preventDefault(e); |
| 19432 |
}; |
| 19433 |
|
| 19434 |
this.onDragOver = function(e) { |
| 19435 |
if (editor.getReadOnly() || !canAccept(e.dataTransfer)) |
| 19436 |
return; |
| 19437 |
x = e.clientX; |
| 19438 |
y = e.clientY; |
| 19439 |
if (!dragSelectionMarker) { |
| 19440 |
addDragMarker(); |
| 19441 |
counter++; |
| 19442 |
} |
| 19443 |
if (onMouseMoveTimer !== null) |
| 19444 |
onMouseMoveTimer = null; |
| 19445 |
|
| 19446 |
e.dataTransfer.dropEffect = dragOperation = getDropEffect(e); |
| 19447 |
return event.preventDefault(e); |
| 19448 |
}; |
| 19449 |
|
| 19450 |
this.onDragLeave = function(e) { |
| 19451 |
counter--; |
| 19452 |
if (counter <= 0 && dragSelectionMarker) { |
| 19453 |
clearDragMarker(); |
| 19454 |
dragOperation = null; |
| 19455 |
return event.preventDefault(e); |
| 19456 |
} |
| 19457 |
}; |
| 19458 |
|
| 19459 |
this.onDrop = function(e) { |
| 19460 |
if (!dragCursor) |
| 19461 |
return; |
| 19462 |
var dataTransfer = e.dataTransfer; |
| 19463 |
if (isInternal) { |
| 19464 |
switch (dragOperation) { |
| 19465 |
case "move": |
| 19466 |
if (range.contains(dragCursor.row, dragCursor.column)) { |
| 19467 |
range = { |
| 19468 |
start: dragCursor, |
| 19469 |
end: dragCursor |
| 19470 |
}; |
| 19471 |
} else { |
| 19472 |
range = editor.moveText(range, dragCursor); |
| 19473 |
} |
| 19474 |
break; |
| 19475 |
case "copy": |
| 19476 |
range = editor.moveText(range, dragCursor, true); |
| 19477 |
break; |
| 19478 |
} |
| 19479 |
} else { |
| 19480 |
var dropData = dataTransfer.getData('Text'); |
| 19481 |
range = { |
| 19482 |
start: dragCursor, |
| 19483 |
end: editor.session.insert(dragCursor, dropData) |
| 19484 |
}; |
| 19485 |
editor.focus(); |
| 19486 |
dragOperation = null; |
| 19487 |
} |
| 19488 |
clearDragMarker(); |
| 19489 |
return event.preventDefault(e); |
| 19490 |
}; |
| 19491 |
|
| 19492 |
event.addListener(mouseTarget, "dragstart", this.onDragStart.bind(mouseHandler)); |
| 19493 |
event.addListener(mouseTarget, "dragend", this.onDragEnd.bind(mouseHandler)); |
| 19494 |
event.addListener(mouseTarget, "dragenter", this.onDragEnter.bind(mouseHandler)); |
| 19495 |
event.addListener(mouseTarget, "dragover", this.onDragOver.bind(mouseHandler)); |
| 19496 |
event.addListener(mouseTarget, "dragleave", this.onDragLeave.bind(mouseHandler)); |
| 19497 |
event.addListener(mouseTarget, "drop", this.onDrop.bind(mouseHandler)); |
| 19498 |
|
| 19499 |
function scrollCursorIntoView(cursor, prevCursor) { |
| 19500 |
var now = Date.now(); |
| 19501 |
var vMovement = !prevCursor || cursor.row != prevCursor.row; |
| 19502 |
var hMovement = !prevCursor || cursor.column != prevCursor.column; |
| 19503 |
if (!cursorMovedTime || vMovement || hMovement) { |
| 19504 |
editor.$blockScrolling += 1; |
| 19505 |
editor.moveCursorToPosition(cursor); |
| 19506 |
editor.$blockScrolling -= 1; |
| 19507 |
cursorMovedTime = now; |
| 19508 |
cursorPointOnCaretMoved = {x: x, y: y}; |
| 19509 |
} else { |
| 19510 |
var distance = calcDistance(cursorPointOnCaretMoved.x, cursorPointOnCaretMoved.y, x, y); |
| 19511 |
if (distance > SCROLL_CURSOR_HYSTERESIS) { |
| 19512 |
cursorMovedTime = null; |
| 19513 |
} else if (now - cursorMovedTime >= SCROLL_CURSOR_DELAY) { |
| 19514 |
editor.renderer.scrollCursorIntoView(); |
| 19515 |
cursorMovedTime = null; |
| 19516 |
} |
| 19517 |
} |
| 19518 |
} |
| 19519 |
|
| 19520 |
function autoScroll(cursor, prevCursor) { |
| 19521 |
var now = Date.now(); |
| 19522 |
var lineHeight = editor.renderer.layerConfig.lineHeight; |
| 19523 |
var characterWidth = editor.renderer.layerConfig.characterWidth; |
| 19524 |
var editorRect = editor.renderer.scroller.getBoundingClientRect(); |
| 19525 |
var offsets = { |
| 19526 |
x: { |
| 19527 |
left: x - editorRect.left, |
| 19528 |
right: editorRect.right - x |
| 19529 |
}, |
| 19530 |
y: { |
| 19531 |
top: y - editorRect.top, |
| 19532 |
bottom: editorRect.bottom - y |
| 19533 |
} |
| 19534 |
}; |
| 19535 |
var nearestXOffset = Math.min(offsets.x.left, offsets.x.right); |
| 19536 |
var nearestYOffset = Math.min(offsets.y.top, offsets.y.bottom); |
| 19537 |
var scrollCursor = {row: cursor.row, column: cursor.column}; |
| 19538 |
if (nearestXOffset / characterWidth <= 2) { |
| 19539 |
scrollCursor.column += (offsets.x.left < offsets.x.right ? -3 : +2); |
| 19540 |
} |
| 19541 |
if (nearestYOffset / lineHeight <= 1) { |
| 19542 |
scrollCursor.row += (offsets.y.top < offsets.y.bottom ? -1 : +1); |
| 19543 |
} |
| 19544 |
var vScroll = cursor.row != scrollCursor.row; |
| 19545 |
var hScroll = cursor.column != scrollCursor.column; |
| 19546 |
var vMovement = !prevCursor || cursor.row != prevCursor.row; |
| 19547 |
if (vScroll || (hScroll && !vMovement)) { |
| 19548 |
if (!autoScrollStartTime) |
| 19549 |
autoScrollStartTime = now; |
| 19550 |
else if (now - autoScrollStartTime >= AUTOSCROLL_DELAY) |
| 19551 |
editor.renderer.scrollCursorIntoView(scrollCursor); |
| 19552 |
} else { |
| 19553 |
autoScrollStartTime = null; |
| 19554 |
} |
| 19555 |
} |
| 19556 |
|
| 19557 |
function onDragInterval() { |
| 19558 |
var prevCursor = dragCursor; |
| 19559 |
dragCursor = editor.renderer.screenToTextCoordinates(x, y); |
| 19560 |
scrollCursorIntoView(dragCursor, prevCursor); |
| 19561 |
autoScroll(dragCursor, prevCursor); |
| 19562 |
} |
| 19563 |
|
| 19564 |
function addDragMarker() { |
| 19565 |
range = editor.selection.toOrientedRange(); |
| 19566 |
dragSelectionMarker = editor.session.addMarker(range, "ace_selection", editor.getSelectionStyle()); |
| 19567 |
editor.clearSelection(); |
| 19568 |
if (editor.isFocused()) |
| 19569 |
editor.renderer.$cursorLayer.setBlinking(false); |
| 19570 |
clearInterval(timerId); |
| 19571 |
onDragInterval(); |
| 19572 |
timerId = setInterval(onDragInterval, 20); |
| 19573 |
counter = 0; |
| 19574 |
event.addListener(document, "mousemove", onMouseMove); |
| 19575 |
} |
| 19576 |
|
| 19577 |
function clearDragMarker() { |
| 19578 |
clearInterval(timerId); |
| 19579 |
editor.session.removeMarker(dragSelectionMarker); |
| 19580 |
dragSelectionMarker = null; |
| 19581 |
editor.$blockScrolling += 1; |
| 19582 |
editor.selection.fromOrientedRange(range); |
| 19583 |
editor.$blockScrolling -= 1; |
| 19584 |
if (editor.isFocused() && !isInternal) |
| 19585 |
editor.renderer.$cursorLayer.setBlinking(!editor.getReadOnly()); |
| 19586 |
range = null; |
| 19587 |
dragCursor = null; |
| 19588 |
counter = 0; |
| 19589 |
autoScrollStartTime = null; |
| 19590 |
cursorMovedTime = null; |
| 19591 |
event.removeListener(document, "mousemove", onMouseMove); |
| 19592 |
} |
| 19593 |
var onMouseMoveTimer = null; |
| 19594 |
function onMouseMove() { |
| 19595 |
if (onMouseMoveTimer == null) { |
| 19596 |
onMouseMoveTimer = setTimeout(function() { |
| 19597 |
if (onMouseMoveTimer != null && dragSelectionMarker) |
| 19598 |
clearDragMarker(); |
| 19599 |
}, 20); |
| 19600 |
} |
| 19601 |
} |
| 19602 |
|
| 19603 |
function canAccept(dataTransfer) { |
| 19604 |
var types = dataTransfer.types; |
| 19605 |
return !types || Array.prototype.some.call(types, function(type) { |
| 19606 |
return type == 'text/plain' || type == 'Text'; |
| 19607 |
}); |
| 19608 |
} |
| 19609 |
|
| 19610 |
function getDropEffect(e) { |
| 19611 |
var copyAllowed = ['copy', 'copymove', 'all', 'uninitialized']; |
| 19612 |
var moveAllowed = ['move', 'copymove', 'linkmove', 'all', 'uninitialized']; |
| 19613 |
|
| 19614 |
var copyModifierState = useragent.isMac ? e.altKey : e.ctrlKey; |
| 19615 |
var effectAllowed = "uninitialized"; |
| 19616 |
try { |
| 19617 |
effectAllowed = e.dataTransfer.effectAllowed.toLowerCase(); |
| 19618 |
} catch (e) {} |
| 19619 |
var dropEffect = "none"; |
| 19620 |
|
| 19621 |
if (copyModifierState && copyAllowed.indexOf(effectAllowed) >= 0) |
| 19622 |
dropEffect = "copy"; |
| 19623 |
else if (moveAllowed.indexOf(effectAllowed) >= 0) |
| 19624 |
dropEffect = "move"; |
| 19625 |
else if (copyAllowed.indexOf(effectAllowed) >= 0) |
| 19626 |
dropEffect = "copy"; |
| 19627 |
|
| 19628 |
return dropEffect; |
| 19629 |
} |
| 19630 |
} |
| 19631 |
|
| 19632 |
(function() { |
| 19633 |
|
| 19634 |
this.dragWait = function() { |
| 19635 |
var interval = Date.now() - this.mousedownEvent.time; |
| 19636 |
if (interval > this.editor.getDragDelay()) |
| 19637 |
this.startDrag(); |
| 19638 |
}; |
| 19639 |
|
| 19640 |
this.dragWaitEnd = function() { |
| 19641 |
var target = this.editor.container; |
| 19642 |
target.draggable = false; |
| 19643 |
this.startSelect(this.mousedownEvent.getDocumentPosition()); |
| 19644 |
this.selectEnd(); |
| 19645 |
}; |
| 19646 |
|
| 19647 |
this.dragReadyEnd = function(e) { |
| 19648 |
this.editor.renderer.$cursorLayer.setBlinking(!this.editor.getReadOnly()); |
| 19649 |
this.editor.unsetStyle("ace_dragging"); |
| 19650 |
this.editor.renderer.setCursorStyle(""); |
| 19651 |
this.dragWaitEnd(); |
| 19652 |
}; |
| 19653 |
|
| 19654 |
this.startDrag = function(){ |
| 19655 |
this.cancelDrag = false; |
| 19656 |
var editor = this.editor; |
| 19657 |
var target = editor.container; |
| 19658 |
target.draggable = true; |
| 19659 |
editor.renderer.$cursorLayer.setBlinking(false); |
| 19660 |
editor.setStyle("ace_dragging"); |
| 19661 |
var cursorStyle = useragent.isWin ? "default" : "move"; |
| 19662 |
editor.renderer.setCursorStyle(cursorStyle); |
| 19663 |
this.setState("dragReady"); |
| 19664 |
}; |
| 19665 |
|
| 19666 |
this.onMouseDrag = function(e) { |
| 19667 |
var target = this.editor.container; |
| 19668 |
if (useragent.isIE && this.state == "dragReady") { |
| 19669 |
var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y); |
| 19670 |
if (distance > 3) |
| 19671 |
target.dragDrop(); |
| 19672 |
} |
| 19673 |
if (this.state === "dragWait") { |
| 19674 |
var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y); |
| 19675 |
if (distance > 0) { |
| 19676 |
target.draggable = false; |
| 19677 |
this.startSelect(this.mousedownEvent.getDocumentPosition()); |
| 19678 |
} |
| 19679 |
} |
| 19680 |
}; |
| 19681 |
|
| 19682 |
this.onMouseDown = function(e) { |
| 19683 |
if (!this.$dragEnabled) |
| 19684 |
return; |
| 19685 |
this.mousedownEvent = e; |
| 19686 |
var editor = this.editor; |
| 19687 |
|
| 19688 |
var inSelection = e.inSelection(); |
| 19689 |
var button = e.getButton(); |
| 19690 |
var clickCount = e.domEvent.detail || 1; |
| 19691 |
if (clickCount === 1 && button === 0 && inSelection) { |
| 19692 |
if (e.editor.inMultiSelectMode && (e.getAccelKey() || e.getShiftKey())) |
| 19693 |
return; |
| 19694 |
this.mousedownEvent.time = Date.now(); |
| 19695 |
var eventTarget = e.domEvent.target || e.domEvent.srcElement; |
| 19696 |
if ("unselectable" in eventTarget) |
| 19697 |
eventTarget.unselectable = "on"; |
| 19698 |
if (editor.getDragDelay()) { |
| 19699 |
if (useragent.isWebKit) { |
| 19700 |
this.cancelDrag = true; |
| 19701 |
var mouseTarget = editor.container; |
| 19702 |
mouseTarget.draggable = true; |
| 19703 |
} |
| 19704 |
this.setState("dragWait"); |
| 19705 |
} else { |
| 19706 |
this.startDrag(); |
| 19707 |
} |
| 19708 |
this.captureMouse(e, this.onMouseDrag.bind(this)); |
| 19709 |
e.defaultPrevented = true; |
| 19710 |
} |
| 19711 |
}; |
| 19712 |
|
| 19713 |
}).call(DragdropHandler.prototype); |
| 19714 |
|
| 19715 |
|
| 19716 |
function calcDistance(ax, ay, bx, by) { |
| 19717 |
return Math.sqrt(Math.pow(bx - ax, 2) + Math.pow(by - ay, 2)); |
| 19718 |
} |
| 19719 |
|
| 19720 |
exports.DragdropHandler = DragdropHandler; |
| 19721 |
|
| 19722 |
}); |
| 19723 |
|
| 19724 |
ace.define("ace/lib/net",["require","exports","module","ace/lib/dom"], function(acequire, exports, module) { |
| 19725 |
"use strict"; |
| 19726 |
var dom = acequire("./dom"); |
| 19727 |
|
| 19728 |
exports.get = function (url, callback) { |
| 19729 |
var xhr = new XMLHttpRequest(); |
| 19730 |
xhr.open('GET', url, true); |
| 19731 |
xhr.onreadystatechange = function () { |
| 19732 |
if (xhr.readyState === 4) { |
| 19733 |
callback(xhr.responseText); |
| 19734 |
} |
| 19735 |
}; |
| 19736 |
xhr.send(null); |
| 19737 |
}; |
| 19738 |
|
| 19739 |
exports.loadScript = function(path, callback) { |
| 19740 |
var head = dom.getDocumentHead(); |
| 19741 |
var s = document.createElement('script'); |
| 19742 |
|
| 19743 |
s.src = path; |
| 19744 |
head.appendChild(s); |
| 19745 |
|
| 19746 |
s.onload = s.onreadystatechange = function(_, isAbort) { |
| 19747 |
if (isAbort || !s.readyState || s.readyState == "loaded" || s.readyState == "complete") { |
| 19748 |
s = s.onload = s.onreadystatechange = null; |
| 19749 |
if (!isAbort) |
| 19750 |
callback(); |
| 19751 |
} |
| 19752 |
}; |
| 19753 |
}; |
| 19754 |
exports.qualifyURL = function(url) { |
| 19755 |
var a = document.createElement('a'); |
| 19756 |
a.href = url; |
| 19757 |
return a.href; |
| 19758 |
} |
| 19759 |
|
| 19760 |
}); |
| 19761 |
|
| 19762 |
ace.define("ace/lib/event_emitter",["require","exports","module"], function(acequire, exports, module) { |
| 19763 |
"use strict"; |
| 19764 |
|
| 19765 |
var EventEmitter = {}; |
| 19766 |
var stopPropagation = function() { this.propagationStopped = true; }; |
| 19767 |
var preventDefault = function() { this.defaultPrevented = true; }; |
| 19768 |
|
| 19769 |
EventEmitter._emit = |
| 19770 |
EventEmitter._dispatchEvent = function(eventName, e) { |
| 19771 |
this._eventRegistry || (this._eventRegistry = {}); |
| 19772 |
this._defaultHandlers || (this._defaultHandlers = {}); |
| 19773 |
|
| 19774 |
var listeners = this._eventRegistry[eventName] || []; |
| 19775 |
var defaultHandler = this._defaultHandlers[eventName]; |
| 19776 |
if (!listeners.length && !defaultHandler) |
| 19777 |
return; |
| 19778 |
|
| 19779 |
if (typeof e != "object" || !e) |
| 19780 |
e = {}; |
| 19781 |
|
| 19782 |
if (!e.type) |
| 19783 |
e.type = eventName; |
| 19784 |
if (!e.stopPropagation) |
| 19785 |
e.stopPropagation = stopPropagation; |
| 19786 |
if (!e.preventDefault) |
| 19787 |
e.preventDefault = preventDefault; |
| 19788 |
|
| 19789 |
listeners = listeners.slice(); |
| 19790 |
for (var i=0; i<listeners.length; i++) { |
| 19791 |
listeners[i](e, this); |
| 19792 |
if (e.propagationStopped) |
| 19793 |
break; |
| 19794 |
} |
| 19795 |
|
| 19796 |
if (defaultHandler && !e.defaultPrevented) |
| 19797 |
return defaultHandler(e, this); |
| 19798 |
}; |
| 19799 |
|
| 19800 |
|
| 19801 |
EventEmitter._signal = function(eventName, e) { |
| 19802 |
var listeners = (this._eventRegistry || {})[eventName]; |
| 19803 |
if (!listeners) |
| 19804 |
return; |
| 19805 |
listeners = listeners.slice(); |
| 19806 |
for (var i=0; i<listeners.length; i++) |
| 19807 |
listeners[i](e, this); |
| 19808 |
}; |
| 19809 |
|
| 19810 |
EventEmitter.once = function(eventName, callback) { |
| 19811 |
var _self = this; |
| 19812 |
callback && this.addEventListener(eventName, function newCallback() { |
| 19813 |
_self.removeEventListener(eventName, newCallback); |
| 19814 |
callback.apply(null, arguments); |
| 19815 |
}); |
| 19816 |
}; |
| 19817 |
|
| 19818 |
|
| 19819 |
EventEmitter.setDefaultHandler = function(eventName, callback) { |
| 19820 |
var handlers = this._defaultHandlers |
| 19821 |
if (!handlers) |
| 19822 |
handlers = this._defaultHandlers = {_disabled_: {}}; |
| 19823 |
|
| 19824 |
if (handlers[eventName]) { |
| 19825 |
var old = handlers[eventName]; |
| 19826 |
var disabled = handlers._disabled_[eventName]; |
| 19827 |
if (!disabled) |
| 19828 |
handlers._disabled_[eventName] = disabled = []; |
| 19829 |
disabled.push(old); |
| 19830 |
var i = disabled.indexOf(callback); |
| 19831 |
if (i != -1) |
| 19832 |
disabled.splice(i, 1); |
| 19833 |
} |
| 19834 |
handlers[eventName] = callback; |
| 19835 |
}; |
| 19836 |
EventEmitter.removeDefaultHandler = function(eventName, callback) { |
| 19837 |
var handlers = this._defaultHandlers |
| 19838 |
if (!handlers) |
| 19839 |
return; |
| 19840 |
var disabled = handlers._disabled_[eventName]; |
| 19841 |
|
| 19842 |
if (handlers[eventName] == callback) { |
| 19843 |
var old = handlers[eventName]; |
| 19844 |
if (disabled) |
| 19845 |
this.setDefaultHandler(eventName, disabled.pop()); |
| 19846 |
} else if (disabled) { |
| 19847 |
var i = disabled.indexOf(callback); |
| 19848 |
if (i != -1) |
| 19849 |
disabled.splice(i, 1); |
| 19850 |
} |
| 19851 |
}; |
| 19852 |
|
| 19853 |
EventEmitter.on = |
| 19854 |
EventEmitter.addEventListener = function(eventName, callback, capturing) { |
| 19855 |
this._eventRegistry = this._eventRegistry || {}; |
| 19856 |
|
| 19857 |
var listeners = this._eventRegistry[eventName]; |
| 19858 |
if (!listeners) |
| 19859 |
listeners = this._eventRegistry[eventName] = []; |
| 19860 |
|
| 19861 |
if (listeners.indexOf(callback) == -1) |
| 19862 |
listeners[capturing ? "unshift" : "push"](callback); |
| 19863 |
return callback; |
| 19864 |
}; |
| 19865 |
|
| 19866 |
EventEmitter.off = |
| 19867 |
EventEmitter.removeListener = |
| 19868 |
EventEmitter.removeEventListener = function(eventName, callback) { |
| 19869 |
this._eventRegistry = this._eventRegistry || {}; |
| 19870 |
|
| 19871 |
var listeners = this._eventRegistry[eventName]; |
| 19872 |
if (!listeners) |
| 19873 |
return; |
| 19874 |
|
| 19875 |
var index = listeners.indexOf(callback); |
| 19876 |
if (index !== -1) |
| 19877 |
listeners.splice(index, 1); |
| 19878 |
}; |
| 19879 |
|
| 19880 |
EventEmitter.removeAllListeners = function(eventName) { |
| 19881 |
if (this._eventRegistry) this._eventRegistry[eventName] = []; |
| 19882 |
}; |
| 19883 |
|
| 19884 |
exports.EventEmitter = EventEmitter; |
| 19885 |
|
| 19886 |
}); |
| 19887 |
|
| 19888 |
ace.define("ace/lib/app_config",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(acequire, exports, module) { |
| 19889 |
"no use strict"; |
| 19890 |
|
| 19891 |
var oop = acequire("./oop"); |
| 19892 |
var EventEmitter = acequire("./event_emitter").EventEmitter; |
| 19893 |
|
| 19894 |
var optionsProvider = { |
| 19895 |
setOptions: function(optList) { |
| 19896 |
Object.keys(optList).forEach(function(key) { |
| 19897 |
this.setOption(key, optList[key]); |
| 19898 |
}, this); |
| 19899 |
}, |
| 19900 |
getOptions: function(optionNames) { |
| 19901 |
var result = {}; |
| 19902 |
if (!optionNames) { |
| 19903 |
optionNames = Object.keys(this.$options); |
| 19904 |
} else if (!Array.isArray(optionNames)) { |
| 19905 |
result = optionNames; |
| 19906 |
optionNames = Object.keys(result); |
| 19907 |
} |
| 19908 |
optionNames.forEach(function(key) { |
| 19909 |
result[key] = this.getOption(key); |
| 19910 |
}, this); |
| 19911 |
return result; |
| 19912 |
}, |
| 19913 |
setOption: function(name, value) { |
| 19914 |
if (this["$" + name] === value) |
| 19915 |
return; |
| 19916 |
var opt = this.$options[name]; |
| 19917 |
if (!opt) { |
| 19918 |
return warn('misspelled option "' + name + '"'); |
| 19919 |
} |
| 19920 |
if (opt.forwardTo) |
| 19921 |
return this[opt.forwardTo] && this[opt.forwardTo].setOption(name, value); |
| 19922 |
|
| 19923 |
if (!opt.handlesSet) |
| 19924 |
this["$" + name] = value; |
| 19925 |
if (opt && opt.set) |
| 19926 |
opt.set.call(this, value); |
| 19927 |
}, |
| 19928 |
getOption: function(name) { |
| 19929 |
var opt = this.$options[name]; |
| 19930 |
if (!opt) { |
| 19931 |
return warn('misspelled option "' + name + '"'); |
| 19932 |
} |
| 19933 |
if (opt.forwardTo) |
| 19934 |
return this[opt.forwardTo] && this[opt.forwardTo].getOption(name); |
| 19935 |
return opt && opt.get ? opt.get.call(this) : this["$" + name]; |
| 19936 |
} |
| 19937 |
}; |
| 19938 |
|
| 19939 |
function warn(message) { |
| 19940 |
if (typeof console != "undefined" && console.warn) |
| 19941 |
console.warn.apply(console, arguments); |
| 19942 |
} |
| 19943 |
|
| 19944 |
function reportError(msg, data) { |
| 19945 |
var e = new Error(msg); |
| 19946 |
e.data = data; |
| 19947 |
if (typeof console == "object" && console.error) |
| 19948 |
console.error(e); |
| 19949 |
setTimeout(function() { throw e; }); |
| 19950 |
} |
| 19951 |
|
| 19952 |
var AppConfig = function() { |
| 19953 |
this.$defaultOptions = {}; |
| 19954 |
}; |
| 19955 |
|
| 19956 |
(function() { |
| 19957 |
oop.implement(this, EventEmitter); |
| 19958 |
this.defineOptions = function(obj, path, options) { |
| 19959 |
if (!obj.$options) |
| 19960 |
this.$defaultOptions[path] = obj.$options = {}; |
| 19961 |
|
| 19962 |
Object.keys(options).forEach(function(key) { |
| 19963 |
var opt = options[key]; |
| 19964 |
if (typeof opt == "string") |
| 19965 |
opt = {forwardTo: opt}; |
| 19966 |
|
| 19967 |
opt.name || (opt.name = key); |
| 19968 |
obj.$options[opt.name] = opt; |
| 19969 |
if ("initialValue" in opt) |
| 19970 |
obj["$" + opt.name] = opt.initialValue; |
| 19971 |
}); |
| 19972 |
oop.implement(obj, optionsProvider); |
| 19973 |
|
| 19974 |
return this; |
| 19975 |
}; |
| 19976 |
|
| 19977 |
this.resetOptions = function(obj) { |
| 19978 |
Object.keys(obj.$options).forEach(function(key) { |
| 19979 |
var opt = obj.$options[key]; |
| 19980 |
if ("value" in opt) |
| 19981 |
obj.setOption(key, opt.value); |
| 19982 |
}); |
| 19983 |
}; |
| 19984 |
|
| 19985 |
this.setDefaultValue = function(path, name, value) { |
| 19986 |
var opts = this.$defaultOptions[path] || (this.$defaultOptions[path] = {}); |
| 19987 |
if (opts[name]) { |
| 19988 |
if (opts.forwardTo) |
| 19989 |
this.setDefaultValue(opts.forwardTo, name, value); |
| 19990 |
else |
| 19991 |
opts[name].value = value; |
| 19992 |
} |
| 19993 |
}; |
| 19994 |
|
| 19995 |
this.setDefaultValues = function(path, optionHash) { |
| 19996 |
Object.keys(optionHash).forEach(function(key) { |
| 19997 |
this.setDefaultValue(path, key, optionHash[key]); |
| 19998 |
}, this); |
| 19999 |
}; |
| 20000 |
|
| 20001 |
this.warn = warn; |
| 20002 |
this.reportError = reportError; |
| 20003 |
|
| 20004 |
}).call(AppConfig.prototype); |
| 20005 |
|
| 20006 |
exports.AppConfig = AppConfig; |
| 20007 |
|
| 20008 |
}); |
| 20009 |
|
| 20010 |
ace.define("ace/config",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/lib/net","ace/lib/app_config"], function(acequire, exports, module) { |
| 20011 |
"no use strict"; |
| 20012 |
|
| 20013 |
var lang = acequire("./lib/lang"); |
| 20014 |
var oop = acequire("./lib/oop"); |
| 20015 |
var net = acequire("./lib/net"); |
| 20016 |
var AppConfig = acequire("./lib/app_config").AppConfig; |
| 20017 |
|
| 20018 |
module.exports = exports = new AppConfig(); |
| 20019 |
|
| 20020 |
var global = (function() { |
| 20021 |
return this || typeof window != "undefined" && window; |
| 20022 |
})(); |
| 20023 |
|
| 20024 |
var options = { |
| 20025 |
packaged: false, |
| 20026 |
workerPath: null, |
| 20027 |
modePath: null, |
| 20028 |
themePath: null, |
| 20029 |
basePath: "", |
| 20030 |
suffix: ".js", |
| 20031 |
$moduleUrls: {} |
| 20032 |
}; |
| 20033 |
|
| 20034 |
exports.get = function(key) { |
| 20035 |
if (!options.hasOwnProperty(key)) |
| 20036 |
throw new Error("Unknown config key: " + key); |
| 20037 |
|
| 20038 |
return options[key]; |
| 20039 |
}; |
| 20040 |
|
| 20041 |
exports.set = function(key, value) { |
| 20042 |
if (!options.hasOwnProperty(key)) |
| 20043 |
throw new Error("Unknown config key: " + key); |
| 20044 |
|
| 20045 |
options[key] = value; |
| 20046 |
}; |
| 20047 |
|
| 20048 |
exports.all = function() { |
| 20049 |
return lang.copyObject(options); |
| 20050 |
}; |
| 20051 |
exports.moduleUrl = function(name, component) { |
| 20052 |
if (options.$moduleUrls[name]) |
| 20053 |
return options.$moduleUrls[name]; |
| 20054 |
|
| 20055 |
var parts = name.split("/"); |
| 20056 |
component = component || parts[parts.length - 2] || ""; |
| 20057 |
var sep = component == "snippets" ? "/" : "-"; |
| 20058 |
var base = parts[parts.length - 1]; |
| 20059 |
if (component == "worker" && sep == "-") { |
| 20060 |
var re = new RegExp("^" + component + "[\\-_]|[\\-_]" + component + "$", "g"); |
| 20061 |
base = base.replace(re, ""); |
| 20062 |
} |
| 20063 |
|
| 20064 |
if ((!base || base == component) && parts.length > 1) |
| 20065 |
base = parts[parts.length - 2]; |
| 20066 |
var path = options[component + "Path"]; |
| 20067 |
if (path == null) { |
| 20068 |
path = options.basePath; |
| 20069 |
} else if (sep == "/") { |
| 20070 |
component = sep = ""; |
| 20071 |
} |
| 20072 |
if (path && path.slice(-1) != "/") |
| 20073 |
path += "/"; |
| 20074 |
return path + component + sep + base + this.get("suffix"); |
| 20075 |
}; |
| 20076 |
|
| 20077 |
exports.setModuleUrl = function(name, subst) { |
| 20078 |
return options.$moduleUrls[name] = subst; |
| 20079 |
}; |
| 20080 |
|
| 20081 |
exports.$loading = {}; |
| 20082 |
exports.loadModule = function(moduleName, onLoad) { |
| 20083 |
var module, moduleType; |
| 20084 |
if (Array.isArray(moduleName)) { |
| 20085 |
moduleType = moduleName[0]; |
| 20086 |
moduleName = moduleName[1]; |
| 20087 |
} |
| 20088 |
|
| 20089 |
try { |
| 20090 |
module = acequire(moduleName); |
| 20091 |
} catch (e) {} |
| 20092 |
if (module && !exports.$loading[moduleName]) |
| 20093 |
return onLoad && onLoad(module); |
| 20094 |
|
| 20095 |
if (!exports.$loading[moduleName]) |
| 20096 |
exports.$loading[moduleName] = []; |
| 20097 |
|
| 20098 |
exports.$loading[moduleName].push(onLoad); |
| 20099 |
|
| 20100 |
if (exports.$loading[moduleName].length > 1) |
| 20101 |
return; |
| 20102 |
|
| 20103 |
var afterLoad = function() { |
| 20104 |
acequire([moduleName], function(module) { |
| 20105 |
exports._emit("load.module", {name: moduleName, module: module}); |
| 20106 |
var listeners = exports.$loading[moduleName]; |
| 20107 |
exports.$loading[moduleName] = null; |
| 20108 |
listeners.forEach(function(onLoad) { |
| 20109 |
onLoad && onLoad(module); |
| 20110 |
}); |
| 20111 |
}); |
| 20112 |
}; |
| 20113 |
|
| 20114 |
if (!exports.get("packaged")) |
| 20115 |
return afterLoad(); |
| 20116 |
net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad); |
| 20117 |
}; |
| 20118 |
init(true);function init(packaged) { |
| 20119 |
|
| 20120 |
if (!global || !global.document) |
| 20121 |
return; |
| 20122 |
|
| 20123 |
options.packaged = packaged || acequire.packaged || module.packaged || (global.define && __webpack_require__(65).packaged); |
| 20124 |
|
| 20125 |
var scriptOptions = {}; |
| 20126 |
var scriptUrl = ""; |
| 20127 |
var currentScript = (document.currentScript || document._currentScript ); // native or polyfill |
| 20128 |
var currentDocument = currentScript && currentScript.ownerDocument || document; |
| 20129 |
|
| 20130 |
var scripts = currentDocument.getElementsByTagName("script"); |
| 20131 |
for (var i=0; i<scripts.length; i++) { |
| 20132 |
var script = scripts[i]; |
| 20133 |
|
| 20134 |
var src = script.src || script.getAttribute("src"); |
| 20135 |
if (!src) |
| 20136 |
continue; |
| 20137 |
|
| 20138 |
var attributes = script.attributes; |
| 20139 |
for (var j=0, l=attributes.length; j < l; j++) { |
| 20140 |
var attr = attributes[j]; |
| 20141 |
if (attr.name.indexOf("data-ace-") === 0) { |
| 20142 |
scriptOptions[deHyphenate(attr.name.replace(/^data-ace-/, ""))] = attr.value; |
| 20143 |
} |
| 20144 |
} |
| 20145 |
|
| 20146 |
var m = src.match(/^(.*)\/ace(\-\w+)?\.js(\?|$)/); |
| 20147 |
if (m) |
| 20148 |
scriptUrl = m[1]; |
| 20149 |
} |
| 20150 |
|
| 20151 |
if (scriptUrl) { |
| 20152 |
scriptOptions.base = scriptOptions.base || scriptUrl; |
| 20153 |
scriptOptions.packaged = true; |
| 20154 |
} |
| 20155 |
|
| 20156 |
scriptOptions.basePath = scriptOptions.base; |
| 20157 |
scriptOptions.workerPath = scriptOptions.workerPath || scriptOptions.base; |
| 20158 |
scriptOptions.modePath = scriptOptions.modePath || scriptOptions.base; |
| 20159 |
scriptOptions.themePath = scriptOptions.themePath || scriptOptions.base; |
| 20160 |
delete scriptOptions.base; |
| 20161 |
|
| 20162 |
for (var key in scriptOptions) |
| 20163 |
if (typeof scriptOptions[key] !== "undefined") |
| 20164 |
exports.set(key, scriptOptions[key]); |
| 20165 |
} |
| 20166 |
|
| 20167 |
exports.init = init; |
| 20168 |
|
| 20169 |
function deHyphenate(str) { |
| 20170 |
return str.replace(/-(.)/g, function(m, m1) { return m1.toUpperCase(); }); |
| 20171 |
} |
| 20172 |
|
| 20173 |
}); |
| 20174 |
|
| 20175 |
ace.define("ace/mouse/mouse_handler",["require","exports","module","ace/lib/event","ace/lib/useragent","ace/mouse/default_handlers","ace/mouse/default_gutter_handler","ace/mouse/mouse_event","ace/mouse/dragdrop_handler","ace/config"], function(acequire, exports, module) { |
| 20176 |
"use strict"; |
| 20177 |
|
| 20178 |
var event = acequire("../lib/event"); |
| 20179 |
var useragent = acequire("../lib/useragent"); |
| 20180 |
var DefaultHandlers = acequire("./default_handlers").DefaultHandlers; |
| 20181 |
var DefaultGutterHandler = acequire("./default_gutter_handler").GutterHandler; |
| 20182 |
var MouseEvent = acequire("./mouse_event").MouseEvent; |
| 20183 |
var DragdropHandler = acequire("./dragdrop_handler").DragdropHandler; |
| 20184 |
var config = acequire("../config"); |
| 20185 |
|
| 20186 |
var MouseHandler = function(editor) { |
| 20187 |
var _self = this; |
| 20188 |
this.editor = editor; |
| 20189 |
|
| 20190 |
new DefaultHandlers(this); |
| 20191 |
new DefaultGutterHandler(this); |
| 20192 |
new DragdropHandler(this); |
| 20193 |
|
| 20194 |
var focusEditor = function(e) { |
| 20195 |
var windowBlurred = !document.hasFocus || !document.hasFocus() |
| 20196 |
|| !editor.isFocused() && document.activeElement == (editor.textInput && editor.textInput.getElement()) |
| 20197 |
if (windowBlurred) |
| 20198 |
window.focus(); |
| 20199 |
editor.focus(); |
| 20200 |
}; |
| 20201 |
|
| 20202 |
var mouseTarget = editor.renderer.getMouseEventTarget(); |
| 20203 |
event.addListener(mouseTarget, "click", this.onMouseEvent.bind(this, "click")); |
| 20204 |
event.addListener(mouseTarget, "mousemove", this.onMouseMove.bind(this, "mousemove")); |
| 20205 |
event.addMultiMouseDownListener([ |
| 20206 |
mouseTarget, |
| 20207 |
editor.renderer.scrollBarV && editor.renderer.scrollBarV.inner, |
| 20208 |
editor.renderer.scrollBarH && editor.renderer.scrollBarH.inner, |
| 20209 |
editor.textInput && editor.textInput.getElement() |
| 20210 |
].filter(Boolean), [400, 300, 250], this, "onMouseEvent"); |
| 20211 |
event.addMouseWheelListener(editor.container, this.onMouseWheel.bind(this, "mousewheel")); |
| 20212 |
event.addTouchMoveListener(editor.container, this.onTouchMove.bind(this, "touchmove")); |
| 20213 |
|
| 20214 |
var gutterEl = editor.renderer.$gutter; |
| 20215 |
event.addListener(gutterEl, "mousedown", this.onMouseEvent.bind(this, "guttermousedown")); |
| 20216 |
event.addListener(gutterEl, "click", this.onMouseEvent.bind(this, "gutterclick")); |
| 20217 |
event.addListener(gutterEl, "dblclick", this.onMouseEvent.bind(this, "gutterdblclick")); |
| 20218 |
event.addListener(gutterEl, "mousemove", this.onMouseEvent.bind(this, "guttermousemove")); |
| 20219 |
|
| 20220 |
event.addListener(mouseTarget, "mousedown", focusEditor); |
| 20221 |
event.addListener(gutterEl, "mousedown", focusEditor); |
| 20222 |
if (useragent.isIE && editor.renderer.scrollBarV) { |
| 20223 |
event.addListener(editor.renderer.scrollBarV.element, "mousedown", focusEditor); |
| 20224 |
event.addListener(editor.renderer.scrollBarH.element, "mousedown", focusEditor); |
| 20225 |
} |
| 20226 |
|
| 20227 |
editor.on("mousemove", function(e){ |
| 20228 |
if (_self.state || _self.$dragDelay || !_self.$dragEnabled) |
| 20229 |
return; |
| 20230 |
|
| 20231 |
var character = editor.renderer.screenToTextCoordinates(e.x, e.y); |
| 20232 |
var range = editor.session.selection.getRange(); |
| 20233 |
var renderer = editor.renderer; |
| 20234 |
|
| 20235 |
if (!range.isEmpty() && range.insideStart(character.row, character.column)) { |
| 20236 |
renderer.setCursorStyle("default"); |
| 20237 |
} else { |
| 20238 |
renderer.setCursorStyle(""); |
| 20239 |
} |
| 20240 |
}); |
| 20241 |
}; |
| 20242 |
|
| 20243 |
(function() { |
| 20244 |
this.onMouseEvent = function(name, e) { |
| 20245 |
this.editor._emit(name, new MouseEvent(e, this.editor)); |
| 20246 |
}; |
| 20247 |
|
| 20248 |
this.onMouseMove = function(name, e) { |
| 20249 |
var listeners = this.editor._eventRegistry && this.editor._eventRegistry.mousemove; |
| 20250 |
if (!listeners || !listeners.length) |
| 20251 |
return; |
| 20252 |
|
| 20253 |
this.editor._emit(name, new MouseEvent(e, this.editor)); |
| 20254 |
}; |
| 20255 |
|
| 20256 |
this.onMouseWheel = function(name, e) { |
| 20257 |
var mouseEvent = new MouseEvent(e, this.editor); |
| 20258 |
mouseEvent.speed = this.$scrollSpeed * 2; |
| 20259 |
mouseEvent.wheelX = e.wheelX; |
| 20260 |
mouseEvent.wheelY = e.wheelY; |
| 20261 |
|
| 20262 |
this.editor._emit(name, mouseEvent); |
| 20263 |
}; |
| 20264 |
|
| 20265 |
this.onTouchMove = function (name, e) { |
| 20266 |
var mouseEvent = new MouseEvent(e, this.editor); |
| 20267 |
mouseEvent.speed = 1;//this.$scrollSpeed * 2; |
| 20268 |
mouseEvent.wheelX = e.wheelX; |
| 20269 |
mouseEvent.wheelY = e.wheelY; |
| 20270 |
this.editor._emit(name, mouseEvent); |
| 20271 |
}; |
| 20272 |
|
| 20273 |
this.setState = function(state) { |
| 20274 |
this.state = state; |
| 20275 |
}; |
| 20276 |
|
| 20277 |
this.captureMouse = function(ev, mouseMoveHandler) { |
| 20278 |
this.x = ev.x; |
| 20279 |
this.y = ev.y; |
| 20280 |
|
| 20281 |
this.isMousePressed = true; |
| 20282 |
var renderer = this.editor.renderer; |
| 20283 |
if (renderer.$keepTextAreaAtCursor) |
| 20284 |
renderer.$keepTextAreaAtCursor = null; |
| 20285 |
|
| 20286 |
var self = this; |
| 20287 |
var onMouseMove = function(e) { |
| 20288 |
if (!e) return; |
| 20289 |
if (useragent.isWebKit && !e.which && self.releaseMouse) |
| 20290 |
return self.releaseMouse(); |
| 20291 |
|
| 20292 |
self.x = e.clientX; |
| 20293 |
self.y = e.clientY; |
| 20294 |
mouseMoveHandler && mouseMoveHandler(e); |
| 20295 |
self.mouseEvent = new MouseEvent(e, self.editor); |
| 20296 |
self.$mouseMoved = true; |
| 20297 |
}; |
| 20298 |
|
| 20299 |
var onCaptureEnd = function(e) { |
| 20300 |
clearInterval(timerId); |
| 20301 |
onCaptureInterval(); |
| 20302 |
self[self.state + "End"] && self[self.state + "End"](e); |
| 20303 |
self.state = ""; |
| 20304 |
if (renderer.$keepTextAreaAtCursor == null) { |
| 20305 |
renderer.$keepTextAreaAtCursor = true; |
| 20306 |
renderer.$moveTextAreaToCursor(); |
| 20307 |
} |
| 20308 |
self.isMousePressed = false; |
| 20309 |
self.$onCaptureMouseMove = self.releaseMouse = null; |
| 20310 |
e && self.onMouseEvent("mouseup", e); |
| 20311 |
}; |
| 20312 |
|
| 20313 |
var onCaptureInterval = function() { |
| 20314 |
self[self.state] && self[self.state](); |
| 20315 |
self.$mouseMoved = false; |
| 20316 |
}; |
| 20317 |
|
| 20318 |
if (useragent.isOldIE && ev.domEvent.type == "dblclick") { |
| 20319 |
return setTimeout(function() {onCaptureEnd(ev);}); |
| 20320 |
} |
| 20321 |
|
| 20322 |
self.$onCaptureMouseMove = onMouseMove; |
| 20323 |
self.releaseMouse = event.capture(this.editor.container, onMouseMove, onCaptureEnd); |
| 20324 |
var timerId = setInterval(onCaptureInterval, 20); |
| 20325 |
}; |
| 20326 |
this.releaseMouse = null; |
| 20327 |
this.cancelContextMenu = function() { |
| 20328 |
var stop = function(e) { |
| 20329 |
if (e && e.domEvent && e.domEvent.type != "contextmenu") |
| 20330 |
return; |
| 20331 |
this.editor.off("nativecontextmenu", stop); |
| 20332 |
if (e && e.domEvent) |
| 20333 |
event.stopEvent(e.domEvent); |
| 20334 |
}.bind(this); |
| 20335 |
setTimeout(stop, 10); |
| 20336 |
this.editor.on("nativecontextmenu", stop); |
| 20337 |
}; |
| 20338 |
}).call(MouseHandler.prototype); |
| 20339 |
|
| 20340 |
config.defineOptions(MouseHandler.prototype, "mouseHandler", { |
| 20341 |
scrollSpeed: {initialValue: 2}, |
| 20342 |
dragDelay: {initialValue: (useragent.isMac ? 150 : 0)}, |
| 20343 |
dragEnabled: {initialValue: true}, |
| 20344 |
focusTimout: {initialValue: 0}, |
| 20345 |
tooltipFollowsMouse: {initialValue: true} |
| 20346 |
}); |
| 20347 |
|
| 20348 |
|
| 20349 |
exports.MouseHandler = MouseHandler; |
| 20350 |
}); |
| 20351 |
|
| 20352 |
ace.define("ace/mouse/fold_handler",["require","exports","module"], function(acequire, exports, module) { |
| 20353 |
"use strict"; |
| 20354 |
|
| 20355 |
function FoldHandler(editor) { |
| 20356 |
|
| 20357 |
editor.on("click", function(e) { |
| 20358 |
var position = e.getDocumentPosition(); |
| 20359 |
var session = editor.session; |
| 20360 |
var fold = session.getFoldAt(position.row, position.column, 1); |
| 20361 |
if (fold) { |
| 20362 |
if (e.getAccelKey()) |
| 20363 |
session.removeFold(fold); |
| 20364 |
else |
| 20365 |
session.expandFold(fold); |
| 20366 |
|
| 20367 |
e.stop(); |
| 20368 |
} |
| 20369 |
}); |
| 20370 |
|
| 20371 |
editor.on("gutterclick", function(e) { |
| 20372 |
var gutterRegion = editor.renderer.$gutterLayer.getRegion(e); |
| 20373 |
|
| 20374 |
if (gutterRegion == "foldWidgets") { |
| 20375 |
var row = e.getDocumentPosition().row; |
| 20376 |
var session = editor.session; |
| 20377 |
if (session.foldWidgets && session.foldWidgets[row]) |
| 20378 |
editor.session.onFoldWidgetClick(row, e); |
| 20379 |
if (!editor.isFocused()) |
| 20380 |
editor.focus(); |
| 20381 |
e.stop(); |
| 20382 |
} |
| 20383 |
}); |
| 20384 |
|
| 20385 |
editor.on("gutterdblclick", function(e) { |
| 20386 |
var gutterRegion = editor.renderer.$gutterLayer.getRegion(e); |
| 20387 |
|
| 20388 |
if (gutterRegion == "foldWidgets") { |
| 20389 |
var row = e.getDocumentPosition().row; |
| 20390 |
var session = editor.session; |
| 20391 |
var data = session.getParentFoldRangeData(row, true); |
| 20392 |
var range = data.range || data.firstRange; |
| 20393 |
|
| 20394 |
if (range) { |
| 20395 |
row = range.start.row; |
| 20396 |
var fold = session.getFoldAt(row, session.getLine(row).length, 1); |
| 20397 |
|
| 20398 |
if (fold) { |
| 20399 |
session.removeFold(fold); |
| 20400 |
} else { |
| 20401 |
session.addFold("...", range); |
| 20402 |
editor.renderer.scrollCursorIntoView({row: range.start.row, column: 0}); |
| 20403 |
} |
| 20404 |
} |
| 20405 |
e.stop(); |
| 20406 |
} |
| 20407 |
}); |
| 20408 |
} |
| 20409 |
|
| 20410 |
exports.FoldHandler = FoldHandler; |
| 20411 |
|
| 20412 |
}); |
| 20413 |
|
| 20414 |
ace.define("ace/keyboard/keybinding",["require","exports","module","ace/lib/keys","ace/lib/event"], function(acequire, exports, module) { |
| 20415 |
"use strict"; |
| 20416 |
|
| 20417 |
var keyUtil = acequire("../lib/keys"); |
| 20418 |
var event = acequire("../lib/event"); |
| 20419 |
|
| 20420 |
var KeyBinding = function(editor) { |
| 20421 |
this.$editor = editor; |
| 20422 |
this.$data = {editor: editor}; |
| 20423 |
this.$handlers = []; |
| 20424 |
this.setDefaultHandler(editor.commands); |
| 20425 |
}; |
| 20426 |
|
| 20427 |
(function() { |
| 20428 |
this.setDefaultHandler = function(kb) { |
| 20429 |
this.removeKeyboardHandler(this.$defaultHandler); |
| 20430 |
this.$defaultHandler = kb; |
| 20431 |
this.addKeyboardHandler(kb, 0); |
| 20432 |
}; |
| 20433 |
|
| 20434 |
this.setKeyboardHandler = function(kb) { |
| 20435 |
var h = this.$handlers; |
| 20436 |
if (h[h.length - 1] == kb) |
| 20437 |
return; |
| 20438 |
|
| 20439 |
while (h[h.length - 1] && h[h.length - 1] != this.$defaultHandler) |
| 20440 |
this.removeKeyboardHandler(h[h.length - 1]); |
| 20441 |
|
| 20442 |
this.addKeyboardHandler(kb, 1); |
| 20443 |
}; |
| 20444 |
|
| 20445 |
this.addKeyboardHandler = function(kb, pos) { |
| 20446 |
if (!kb) |
| 20447 |
return; |
| 20448 |
if (typeof kb == "function" && !kb.handleKeyboard) |
| 20449 |
kb.handleKeyboard = kb; |
| 20450 |
var i = this.$handlers.indexOf(kb); |
| 20451 |
if (i != -1) |
| 20452 |
this.$handlers.splice(i, 1); |
| 20453 |
|
| 20454 |
if (pos == undefined) |
| 20455 |
this.$handlers.push(kb); |
| 20456 |
else |
| 20457 |
this.$handlers.splice(pos, 0, kb); |
| 20458 |
|
| 20459 |
if (i == -1 && kb.attach) |
| 20460 |
kb.attach(this.$editor); |
| 20461 |
}; |
| 20462 |
|
| 20463 |
this.removeKeyboardHandler = function(kb) { |
| 20464 |
var i = this.$handlers.indexOf(kb); |
| 20465 |
if (i == -1) |
| 20466 |
return false; |
| 20467 |
this.$handlers.splice(i, 1); |
| 20468 |
kb.detach && kb.detach(this.$editor); |
| 20469 |
return true; |
| 20470 |
}; |
| 20471 |
|
| 20472 |
this.getKeyboardHandler = function() { |
| 20473 |
return this.$handlers[this.$handlers.length - 1]; |
| 20474 |
}; |
| 20475 |
|
| 20476 |
this.getStatusText = function() { |
| 20477 |
var data = this.$data; |
| 20478 |
var editor = data.editor; |
| 20479 |
return this.$handlers.map(function(h) { |
| 20480 |
return h.getStatusText && h.getStatusText(editor, data) || ""; |
| 20481 |
}).filter(Boolean).join(" "); |
| 20482 |
}; |
| 20483 |
|
| 20484 |
this.$callKeyboardHandlers = function(hashId, keyString, keyCode, e) { |
| 20485 |
var toExecute; |
| 20486 |
var success = false; |
| 20487 |
var commands = this.$editor.commands; |
| 20488 |
|
| 20489 |
for (var i = this.$handlers.length; i--;) { |
| 20490 |
toExecute = this.$handlers[i].handleKeyboard( |
| 20491 |
this.$data, hashId, keyString, keyCode, e |
| 20492 |
); |
| 20493 |
if (!toExecute || !toExecute.command) |
| 20494 |
continue; |
| 20495 |
if (toExecute.command == "null") { |
| 20496 |
success = true; |
| 20497 |
} else { |
| 20498 |
success = commands.exec(toExecute.command, this.$editor, toExecute.args, e); |
| 20499 |
} |
| 20500 |
if (success && e && hashId != -1 && |
| 20501 |
toExecute.passEvent != true && toExecute.command.passEvent != true |
| 20502 |
) { |
| 20503 |
event.stopEvent(e); |
| 20504 |
} |
| 20505 |
if (success) |
| 20506 |
break; |
| 20507 |
} |
| 20508 |
|
| 20509 |
if (!success && hashId == -1) { |
| 20510 |
toExecute = {command: "insertstring"}; |
| 20511 |
success = commands.exec("insertstring", this.$editor, keyString); |
| 20512 |
} |
| 20513 |
|
| 20514 |
if (success) |
| 20515 |
this.$editor._signal("keyboardActivity", toExecute); |
| 20516 |
|
| 20517 |
return success; |
| 20518 |
}; |
| 20519 |
|
| 20520 |
this.onCommandKey = function(e, hashId, keyCode) { |
| 20521 |
var keyString = keyUtil.keyCodeToString(keyCode); |
| 20522 |
this.$callKeyboardHandlers(hashId, keyString, keyCode, e); |
| 20523 |
}; |
| 20524 |
|
| 20525 |
this.onTextInput = function(text) { |
| 20526 |
this.$callKeyboardHandlers(-1, text); |
| 20527 |
}; |
| 20528 |
|
| 20529 |
}).call(KeyBinding.prototype); |
| 20530 |
|
| 20531 |
exports.KeyBinding = KeyBinding; |
| 20532 |
}); |
| 20533 |
|
| 20534 |
ace.define("ace/range",["require","exports","module"], function(acequire, exports, module) { |
| 20535 |
"use strict"; |
| 20536 |
var comparePoints = function(p1, p2) { |
| 20537 |
return p1.row - p2.row || p1.column - p2.column; |
| 20538 |
}; |
| 20539 |
var Range = function(startRow, startColumn, endRow, endColumn) { |
| 20540 |
this.start = { |
| 20541 |
row: startRow, |
| 20542 |
column: startColumn |
| 20543 |
}; |
| 20544 |
|
| 20545 |
this.end = { |
| 20546 |
row: endRow, |
| 20547 |
column: endColumn |
| 20548 |
}; |
| 20549 |
}; |
| 20550 |
|
| 20551 |
(function() { |
| 20552 |
this.isEqual = function(range) { |
| 20553 |
return this.start.row === range.start.row && |
| 20554 |
this.end.row === range.end.row && |
| 20555 |
this.start.column === range.start.column && |
| 20556 |
this.end.column === range.end.column; |
| 20557 |
}; |
| 20558 |
this.toString = function() { |
| 20559 |
return ("Range: [" + this.start.row + "/" + this.start.column + |
| 20560 |
"] -> [" + this.end.row + "/" + this.end.column + "]"); |
| 20561 |
}; |
| 20562 |
|
| 20563 |
this.contains = function(row, column) { |
| 20564 |
return this.compare(row, column) == 0; |
| 20565 |
}; |
| 20566 |
this.compareRange = function(range) { |
| 20567 |
var cmp, |
| 20568 |
end = range.end, |
| 20569 |
start = range.start; |
| 20570 |
|
| 20571 |
cmp = this.compare(end.row, end.column); |
| 20572 |
if (cmp == 1) { |
| 20573 |
cmp = this.compare(start.row, start.column); |
| 20574 |
if (cmp == 1) { |
| 20575 |
return 2; |
| 20576 |
} else if (cmp == 0) { |
| 20577 |
return 1; |
| 20578 |
} else { |
| 20579 |
return 0; |
| 20580 |
} |
| 20581 |
} else if (cmp == -1) { |
| 20582 |
return -2; |
| 20583 |
} else { |
| 20584 |
cmp = this.compare(start.row, start.column); |
| 20585 |
if (cmp == -1) { |
| 20586 |
return -1; |
| 20587 |
} else if (cmp == 1) { |
| 20588 |
return 42; |
| 20589 |
} else { |
| 20590 |
return 0; |
| 20591 |
} |
| 20592 |
} |
| 20593 |
}; |
| 20594 |
this.comparePoint = function(p) { |
| 20595 |
return this.compare(p.row, p.column); |
| 20596 |
}; |
| 20597 |
this.containsRange = function(range) { |
| 20598 |
return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0; |
| 20599 |
}; |
| 20600 |
this.intersects = function(range) { |
| 20601 |
var cmp = this.compareRange(range); |
| 20602 |
return (cmp == -1 || cmp == 0 || cmp == 1); |
| 20603 |
}; |
| 20604 |
this.isEnd = function(row, column) { |
| 20605 |
return this.end.row == row && this.end.column == column; |
| 20606 |
}; |
| 20607 |
this.isStart = function(row, column) { |
| 20608 |
return this.start.row == row && this.start.column == column; |
| 20609 |
}; |
| 20610 |
this.setStart = function(row, column) { |
| 20611 |
if (typeof row == "object") { |
| 20612 |
this.start.column = row.column; |
| 20613 |
this.start.row = row.row; |
| 20614 |
} else { |
| 20615 |
this.start.row = row; |
| 20616 |
this.start.column = column; |
| 20617 |
} |
| 20618 |
}; |
| 20619 |
this.setEnd = function(row, column) { |
| 20620 |
if (typeof row == "object") { |
| 20621 |
this.end.column = row.column; |
| 20622 |
this.end.row = row.row; |
| 20623 |
} else { |
| 20624 |
this.end.row = row; |
| 20625 |
this.end.column = column; |
| 20626 |
} |
| 20627 |
}; |
| 20628 |
this.inside = function(row, column) { |
| 20629 |
if (this.compare(row, column) == 0) { |
| 20630 |
if (this.isEnd(row, column) || this.isStart(row, column)) { |
| 20631 |
return false; |
| 20632 |
} else { |
| 20633 |
return true; |
| 20634 |
} |
| 20635 |
} |
| 20636 |
return false; |
| 20637 |
}; |
| 20638 |
this.insideStart = function(row, column) { |
| 20639 |
if (this.compare(row, column) == 0) { |
| 20640 |
if (this.isEnd(row, column)) { |
| 20641 |
return false; |
| 20642 |
} else { |
| 20643 |
return true; |
| 20644 |
} |
| 20645 |
} |
| 20646 |
return false; |
| 20647 |
}; |
| 20648 |
this.insideEnd = function(row, column) { |
| 20649 |
if (this.compare(row, column) == 0) { |
| 20650 |
if (this.isStart(row, column)) { |
| 20651 |
return false; |
| 20652 |
} else { |
| 20653 |
return true; |
| 20654 |
} |
| 20655 |
} |
| 20656 |
return false; |
| 20657 |
}; |
| 20658 |
this.compare = function(row, column) { |
| 20659 |
if (!this.isMultiLine()) { |
| 20660 |
if (row === this.start.row) { |
| 20661 |
return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0); |
| 20662 |
} |
| 20663 |
} |
| 20664 |
|
| 20665 |
if (row < this.start.row) |
| 20666 |
return -1; |
| 20667 |
|
| 20668 |
if (row > this.end.row) |
| 20669 |
return 1; |
| 20670 |
|
| 20671 |
if (this.start.row === row) |
| 20672 |
return column >= this.start.column ? 0 : -1; |
| 20673 |
|
| 20674 |
if (this.end.row === row) |
| 20675 |
return column <= this.end.column ? 0 : 1; |
| 20676 |
|
| 20677 |
return 0; |
| 20678 |
}; |
| 20679 |
this.compareStart = function(row, column) { |
| 20680 |
if (this.start.row == row && this.start.column == column) { |
| 20681 |
return -1; |
| 20682 |
} else { |
| 20683 |
return this.compare(row, column); |
| 20684 |
} |
| 20685 |
}; |
| 20686 |
this.compareEnd = function(row, column) { |
| 20687 |
if (this.end.row == row && this.end.column == column) { |
| 20688 |
return 1; |
| 20689 |
} else { |
| 20690 |
return this.compare(row, column); |
| 20691 |
} |
| 20692 |
}; |
| 20693 |
this.compareInside = function(row, column) { |
| 20694 |
if (this.end.row == row && this.end.column == column) { |
| 20695 |
return 1; |
| 20696 |
} else if (this.start.row == row && this.start.column == column) { |
| 20697 |
return -1; |
| 20698 |
} else { |
| 20699 |
return this.compare(row, column); |
| 20700 |
} |
| 20701 |
}; |
| 20702 |
this.clipRows = function(firstRow, lastRow) { |
| 20703 |
if (this.end.row > lastRow) |
| 20704 |
var end = {row: lastRow + 1, column: 0}; |
| 20705 |
else if (this.end.row < firstRow) |
| 20706 |
var end = {row: firstRow, column: 0}; |
| 20707 |
|
| 20708 |
if (this.start.row > lastRow) |
| 20709 |
var start = {row: lastRow + 1, column: 0}; |
| 20710 |
else if (this.start.row < firstRow) |
| 20711 |
var start = {row: firstRow, column: 0}; |
| 20712 |
|
| 20713 |
return Range.fromPoints(start || this.start, end || this.end); |
| 20714 |
}; |
| 20715 |
this.extend = function(row, column) { |
| 20716 |
var cmp = this.compare(row, column); |
| 20717 |
|
| 20718 |
if (cmp == 0) |
| 20719 |
return this; |
| 20720 |
else if (cmp == -1) |
| 20721 |
var start = {row: row, column: column}; |
| 20722 |
else |
| 20723 |
var end = {row: row, column: column}; |
| 20724 |
|
| 20725 |
return Range.fromPoints(start || this.start, end || this.end); |
| 20726 |
}; |
| 20727 |
|
| 20728 |
this.isEmpty = function() { |
| 20729 |
return (this.start.row === this.end.row && this.start.column === this.end.column); |
| 20730 |
}; |
| 20731 |
this.isMultiLine = function() { |
| 20732 |
return (this.start.row !== this.end.row); |
| 20733 |
}; |
| 20734 |
this.clone = function() { |
| 20735 |
return Range.fromPoints(this.start, this.end); |
| 20736 |
}; |
| 20737 |
this.collapseRows = function() { |
| 20738 |
if (this.end.column == 0) |
| 20739 |
return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0) |
| 20740 |
else |
| 20741 |
return new Range(this.start.row, 0, this.end.row, 0) |
| 20742 |
}; |
| 20743 |
this.toScreenRange = function(session) { |
| 20744 |
var screenPosStart = session.documentToScreenPosition(this.start); |
| 20745 |
var screenPosEnd = session.documentToScreenPosition(this.end); |
| 20746 |
|
| 20747 |
return new Range( |
| 20748 |
screenPosStart.row, screenPosStart.column, |
| 20749 |
screenPosEnd.row, screenPosEnd.column |
| 20750 |
); |
| 20751 |
}; |
| 20752 |
this.moveBy = function(row, column) { |
| 20753 |
this.start.row += row; |
| 20754 |
this.start.column += column; |
| 20755 |
this.end.row += row; |
| 20756 |
this.end.column += column; |
| 20757 |
}; |
| 20758 |
|
| 20759 |
}).call(Range.prototype); |
| 20760 |
Range.fromPoints = function(start, end) { |
| 20761 |
return new Range(start.row, start.column, end.row, end.column); |
| 20762 |
}; |
| 20763 |
Range.comparePoints = comparePoints; |
| 20764 |
|
| 20765 |
Range.comparePoints = function(p1, p2) { |
| 20766 |
return p1.row - p2.row || p1.column - p2.column; |
| 20767 |
}; |
| 20768 |
|
| 20769 |
|
| 20770 |
exports.Range = Range; |
| 20771 |
}); |
| 20772 |
|
| 20773 |
ace.define("ace/selection",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter","ace/range"], function(acequire, exports, module) { |
| 20774 |
"use strict"; |
| 20775 |
|
| 20776 |
var oop = acequire("./lib/oop"); |
| 20777 |
var lang = acequire("./lib/lang"); |
| 20778 |
var EventEmitter = acequire("./lib/event_emitter").EventEmitter; |
| 20779 |
var Range = acequire("./range").Range; |
| 20780 |
var Selection = function(session) { |
| 20781 |
this.session = session; |
| 20782 |
this.doc = session.getDocument(); |
| 20783 |
|
| 20784 |
this.clearSelection(); |
| 20785 |
this.lead = this.selectionLead = this.doc.createAnchor(0, 0); |
| 20786 |
this.anchor = this.selectionAnchor = this.doc.createAnchor(0, 0); |
| 20787 |
|
| 20788 |
var self = this; |
| 20789 |
this.lead.on("change", function(e) { |
| 20790 |
self._emit("changeCursor"); |
| 20791 |
if (!self.$isEmpty) |
| 20792 |
self._emit("changeSelection"); |
| 20793 |
if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column) |
| 20794 |
self.$desiredColumn = null; |
| 20795 |
}); |
| 20796 |
|
| 20797 |
this.selectionAnchor.on("change", function() { |
| 20798 |
if (!self.$isEmpty) |
| 20799 |
self._emit("changeSelection"); |
| 20800 |
}); |
| 20801 |
}; |
| 20802 |
|
| 20803 |
(function() { |
| 20804 |
|
| 20805 |
oop.implement(this, EventEmitter); |
| 20806 |
this.isEmpty = function() { |
| 20807 |
return (this.$isEmpty || ( |
| 20808 |
this.anchor.row == this.lead.row && |
| 20809 |
this.anchor.column == this.lead.column |
| 20810 |
)); |
| 20811 |
}; |
| 20812 |
this.isMultiLine = function() { |
| 20813 |
if (this.isEmpty()) { |
| 20814 |
return false; |
| 20815 |
} |
| 20816 |
|
| 20817 |
return this.getRange().isMultiLine(); |
| 20818 |
}; |
| 20819 |
this.getCursor = function() { |
| 20820 |
return this.lead.getPosition(); |
| 20821 |
}; |
| 20822 |
this.setSelectionAnchor = function(row, column) { |
| 20823 |
this.anchor.setPosition(row, column); |
| 20824 |
|
| 20825 |
if (this.$isEmpty) { |
| 20826 |
this.$isEmpty = false; |
| 20827 |
this._emit("changeSelection"); |
| 20828 |
} |
| 20829 |
}; |
| 20830 |
this.getSelectionAnchor = function() { |
| 20831 |
if (this.$isEmpty) |
| 20832 |
return this.getSelectionLead(); |
| 20833 |
else |
| 20834 |
return this.anchor.getPosition(); |
| 20835 |
}; |
| 20836 |
this.getSelectionLead = function() { |
| 20837 |
return this.lead.getPosition(); |
| 20838 |
}; |
| 20839 |
this.shiftSelection = function(columns) { |
| 20840 |
if (this.$isEmpty) { |
| 20841 |
this.moveCursorTo(this.lead.row, this.lead.column + columns); |
| 20842 |
return; |
| 20843 |
} |
| 20844 |
|
| 20845 |
var anchor = this.getSelectionAnchor(); |
| 20846 |
var lead = this.getSelectionLead(); |
| 20847 |
|
| 20848 |
var isBackwards = this.isBackwards(); |
| 20849 |
|
| 20850 |
if (!isBackwards || anchor.column !== 0) |
| 20851 |
this.setSelectionAnchor(anchor.row, anchor.column + columns); |
| 20852 |
|
| 20853 |
if (isBackwards || lead.column !== 0) { |
| 20854 |
this.$moveSelection(function() { |
| 20855 |
this.moveCursorTo(lead.row, lead.column + columns); |
| 20856 |
}); |
| 20857 |
} |
| 20858 |
}; |
| 20859 |
this.isBackwards = function() { |
| 20860 |
var anchor = this.anchor; |
| 20861 |
var lead = this.lead; |
| 20862 |
return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column)); |
| 20863 |
}; |
| 20864 |
this.getRange = function() { |
| 20865 |
var anchor = this.anchor; |
| 20866 |
var lead = this.lead; |
| 20867 |
|
| 20868 |
if (this.isEmpty()) |
| 20869 |
return Range.fromPoints(lead, lead); |
| 20870 |
|
| 20871 |
if (this.isBackwards()) { |
| 20872 |
return Range.fromPoints(lead, anchor); |
| 20873 |
} |
| 20874 |
else { |
| 20875 |
return Range.fromPoints(anchor, lead); |
| 20876 |
} |
| 20877 |
}; |
| 20878 |
this.clearSelection = function() { |
| 20879 |
if (!this.$isEmpty) { |
| 20880 |
this.$isEmpty = true; |
| 20881 |
this._emit("changeSelection"); |
| 20882 |
} |
| 20883 |
}; |
| 20884 |
this.selectAll = function() { |
| 20885 |
var lastRow = this.doc.getLength() - 1; |
| 20886 |
this.setSelectionAnchor(0, 0); |
| 20887 |
this.moveCursorTo(lastRow, this.doc.getLine(lastRow).length); |
| 20888 |
}; |
| 20889 |
this.setRange = |
| 20890 |
this.setSelectionRange = function(range, reverse) { |
| 20891 |
if (reverse) { |
| 20892 |
this.setSelectionAnchor(range.end.row, range.end.column); |
| 20893 |
this.selectTo(range.start.row, range.start.column); |
| 20894 |
} else { |
| 20895 |
this.setSelectionAnchor(range.start.row, range.start.column); |
| 20896 |
this.selectTo(range.end.row, range.end.column); |
| 20897 |
} |
| 20898 |
if (this.getRange().isEmpty()) |
| 20899 |
this.$isEmpty = true; |
| 20900 |
this.$desiredColumn = null; |
| 20901 |
}; |
| 20902 |
|
| 20903 |
this.$moveSelection = function(mover) { |
| 20904 |
var lead = this.lead; |
| 20905 |
if (this.$isEmpty) |
| 20906 |
this.setSelectionAnchor(lead.row, lead.column); |
| 20907 |
|
| 20908 |
mover.call(this); |
| 20909 |
}; |
| 20910 |
this.selectTo = function(row, column) { |
| 20911 |
this.$moveSelection(function() { |
| 20912 |
this.moveCursorTo(row, column); |
| 20913 |
}); |
| 20914 |
}; |
| 20915 |
this.selectToPosition = function(pos) { |
| 20916 |
this.$moveSelection(function() { |
| 20917 |
this.moveCursorToPosition(pos); |
| 20918 |
}); |
| 20919 |
}; |
| 20920 |
this.moveTo = function(row, column) { |
| 20921 |
this.clearSelection(); |
| 20922 |
this.moveCursorTo(row, column); |
| 20923 |
}; |
| 20924 |
this.moveToPosition = function(pos) { |
| 20925 |
this.clearSelection(); |
| 20926 |
this.moveCursorToPosition(pos); |
| 20927 |
}; |
| 20928 |
this.selectUp = function() { |
| 20929 |
this.$moveSelection(this.moveCursorUp); |
| 20930 |
}; |
| 20931 |
this.selectDown = function() { |
| 20932 |
this.$moveSelection(this.moveCursorDown); |
| 20933 |
}; |
| 20934 |
this.selectRight = function() { |
| 20935 |
this.$moveSelection(this.moveCursorRight); |
| 20936 |
}; |
| 20937 |
this.selectLeft = function() { |
| 20938 |
this.$moveSelection(this.moveCursorLeft); |
| 20939 |
}; |
| 20940 |
this.selectLineStart = function() { |
| 20941 |
this.$moveSelection(this.moveCursorLineStart); |
| 20942 |
}; |
| 20943 |
this.selectLineEnd = function() { |
| 20944 |
this.$moveSelection(this.moveCursorLineEnd); |
| 20945 |
}; |
| 20946 |
this.selectFileEnd = function() { |
| 20947 |
this.$moveSelection(this.moveCursorFileEnd); |
| 20948 |
}; |
| 20949 |
this.selectFileStart = function() { |
| 20950 |
this.$moveSelection(this.moveCursorFileStart); |
| 20951 |
}; |
| 20952 |
this.selectWordRight = function() { |
| 20953 |
this.$moveSelection(this.moveCursorWordRight); |
| 20954 |
}; |
| 20955 |
this.selectWordLeft = function() { |
| 20956 |
this.$moveSelection(this.moveCursorWordLeft); |
| 20957 |
}; |
| 20958 |
this.getWordRange = function(row, column) { |
| 20959 |
if (typeof column == "undefined") { |
| 20960 |
var cursor = row || this.lead; |
| 20961 |
row = cursor.row; |
| 20962 |
column = cursor.column; |
| 20963 |
} |
| 20964 |
return this.session.getWordRange(row, column); |
| 20965 |
}; |
| 20966 |
this.selectWord = function() { |
| 20967 |
this.setSelectionRange(this.getWordRange()); |
| 20968 |
}; |
| 20969 |
this.selectAWord = function() { |
| 20970 |
var cursor = this.getCursor(); |
| 20971 |
var range = this.session.getAWordRange(cursor.row, cursor.column); |
| 20972 |
this.setSelectionRange(range); |
| 20973 |
}; |
| 20974 |
|
| 20975 |
this.getLineRange = function(row, excludeLastChar) { |
| 20976 |
var rowStart = typeof row == "number" ? row : this.lead.row; |
| 20977 |
var rowEnd; |
| 20978 |
|
| 20979 |
var foldLine = this.session.getFoldLine(rowStart); |
| 20980 |
if (foldLine) { |
| 20981 |
rowStart = foldLine.start.row; |
| 20982 |
rowEnd = foldLine.end.row; |
| 20983 |
} else { |
| 20984 |
rowEnd = rowStart; |
| 20985 |
} |
| 20986 |
if (excludeLastChar === true) |
| 20987 |
return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length); |
| 20988 |
else |
| 20989 |
return new Range(rowStart, 0, rowEnd + 1, 0); |
| 20990 |
}; |
| 20991 |
this.selectLine = function() { |
| 20992 |
this.setSelectionRange(this.getLineRange()); |
| 20993 |
}; |
| 20994 |
this.moveCursorUp = function() { |
| 20995 |
this.moveCursorBy(-1, 0); |
| 20996 |
}; |
| 20997 |
this.moveCursorDown = function() { |
| 20998 |
this.moveCursorBy(1, 0); |
| 20999 |
}; |
| 21000 |
this.moveCursorLeft = function() { |
| 21001 |
var cursor = this.lead.getPosition(), |
| 21002 |
fold; |
| 21003 |
|
| 21004 |
if (fold = this.session.getFoldAt(cursor.row, cursor.column, -1)) { |
| 21005 |
this.moveCursorTo(fold.start.row, fold.start.column); |
| 21006 |
} else if (cursor.column === 0) { |
| 21007 |
if (cursor.row > 0) { |
| 21008 |
this.moveCursorTo(cursor.row - 1, this.doc.getLine(cursor.row - 1).length); |
| 21009 |
} |
| 21010 |
} |
| 21011 |
else { |
| 21012 |
var tabSize = this.session.getTabSize(); |
| 21013 |
if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column-tabSize, cursor.column).split(" ").length-1 == tabSize) |
| 21014 |
this.moveCursorBy(0, -tabSize); |
| 21015 |
else |
| 21016 |
this.moveCursorBy(0, -1); |
| 21017 |
} |
| 21018 |
}; |
| 21019 |
this.moveCursorRight = function() { |
| 21020 |
var cursor = this.lead.getPosition(), |
| 21021 |
fold; |
| 21022 |
if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) { |
| 21023 |
this.moveCursorTo(fold.end.row, fold.end.column); |
| 21024 |
} |
| 21025 |
else if (this.lead.column == this.doc.getLine(this.lead.row).length) { |
| 21026 |
if (this.lead.row < this.doc.getLength() - 1) { |
| 21027 |
this.moveCursorTo(this.lead.row + 1, 0); |
| 21028 |
} |
| 21029 |
} |
| 21030 |
else { |
| 21031 |
var tabSize = this.session.getTabSize(); |
| 21032 |
var cursor = this.lead; |
| 21033 |
if (this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(cursor.column, cursor.column+tabSize).split(" ").length-1 == tabSize) |
| 21034 |
this.moveCursorBy(0, tabSize); |
| 21035 |
else |
| 21036 |
this.moveCursorBy(0, 1); |
| 21037 |
} |
| 21038 |
}; |
| 21039 |
this.moveCursorLineStart = function() { |
| 21040 |
var row = this.lead.row; |
| 21041 |
var column = this.lead.column; |
| 21042 |
var screenRow = this.session.documentToScreenRow(row, column); |
| 21043 |
var firstColumnPosition = this.session.screenToDocumentPosition(screenRow, 0); |
| 21044 |
var beforeCursor = this.session.getDisplayLine( |
| 21045 |
row, null, firstColumnPosition.row, |
| 21046 |
firstColumnPosition.column |
| 21047 |
); |
| 21048 |
|
| 21049 |
var leadingSpace = beforeCursor.match(/^\s*/); |
| 21050 |
if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart) |
| 21051 |
firstColumnPosition.column += leadingSpace[0].length; |
| 21052 |
this.moveCursorToPosition(firstColumnPosition); |
| 21053 |
}; |
| 21054 |
this.moveCursorLineEnd = function() { |
| 21055 |
var lead = this.lead; |
| 21056 |
var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column); |
| 21057 |
if (this.lead.column == lineEnd.column) { |
| 21058 |
var line = this.session.getLine(lineEnd.row); |
| 21059 |
if (lineEnd.column == line.length) { |
| 21060 |
var textEnd = line.search(/\s+$/); |
| 21061 |
if (textEnd > 0) |
| 21062 |
lineEnd.column = textEnd; |
| 21063 |
} |
| 21064 |
} |
| 21065 |
|
| 21066 |
this.moveCursorTo(lineEnd.row, lineEnd.column); |
| 21067 |
}; |
| 21068 |
this.moveCursorFileEnd = function() { |
| 21069 |
var row = this.doc.getLength() - 1; |
| 21070 |
var column = this.doc.getLine(row).length; |
| 21071 |
this.moveCursorTo(row, column); |
| 21072 |
}; |
| 21073 |
this.moveCursorFileStart = function() { |
| 21074 |
this.moveCursorTo(0, 0); |
| 21075 |
}; |
| 21076 |
this.moveCursorLongWordRight = function() { |
| 21077 |
var row = this.lead.row; |
| 21078 |
var column = this.lead.column; |
| 21079 |
var line = this.doc.getLine(row); |
| 21080 |
var rightOfCursor = line.substring(column); |
| 21081 |
|
| 21082 |
var match; |
| 21083 |
this.session.nonTokenRe.lastIndex = 0; |
| 21084 |
this.session.tokenRe.lastIndex = 0; |
| 21085 |
var fold = this.session.getFoldAt(row, column, 1); |
| 21086 |
if (fold) { |
| 21087 |
this.moveCursorTo(fold.end.row, fold.end.column); |
| 21088 |
return; |
| 21089 |
} |
| 21090 |
if (match = this.session.nonTokenRe.exec(rightOfCursor)) { |
| 21091 |
column += this.session.nonTokenRe.lastIndex; |
| 21092 |
this.session.nonTokenRe.lastIndex = 0; |
| 21093 |
rightOfCursor = line.substring(column); |
| 21094 |
} |
| 21095 |
if (column >= line.length) { |
| 21096 |
this.moveCursorTo(row, line.length); |
| 21097 |
this.moveCursorRight(); |
| 21098 |
if (row < this.doc.getLength() - 1) |
| 21099 |
this.moveCursorWordRight(); |
| 21100 |
return; |
| 21101 |
} |
| 21102 |
if (match = this.session.tokenRe.exec(rightOfCursor)) { |
| 21103 |
column += this.session.tokenRe.lastIndex; |
| 21104 |
this.session.tokenRe.lastIndex = 0; |
| 21105 |
} |
| 21106 |
|
| 21107 |
this.moveCursorTo(row, column); |
| 21108 |
}; |
| 21109 |
this.moveCursorLongWordLeft = function() { |
| 21110 |
var row = this.lead.row; |
| 21111 |
var column = this.lead.column; |
| 21112 |
var fold; |
| 21113 |
if (fold = this.session.getFoldAt(row, column, -1)) { |
| 21114 |
this.moveCursorTo(fold.start.row, fold.start.column); |
| 21115 |
return; |
| 21116 |
} |
| 21117 |
|
| 21118 |
var str = this.session.getFoldStringAt(row, column, -1); |
| 21119 |
if (str == null) { |
| 21120 |
str = this.doc.getLine(row).substring(0, column); |
| 21121 |
} |
| 21122 |
|
| 21123 |
var leftOfCursor = lang.stringReverse(str); |
| 21124 |
var match; |
| 21125 |
this.session.nonTokenRe.lastIndex = 0; |
| 21126 |
this.session.tokenRe.lastIndex = 0; |
| 21127 |
if (match = this.session.nonTokenRe.exec(leftOfCursor)) { |
| 21128 |
column -= this.session.nonTokenRe.lastIndex; |
| 21129 |
leftOfCursor = leftOfCursor.slice(this.session.nonTokenRe.lastIndex); |
| 21130 |
this.session.nonTokenRe.lastIndex = 0; |
| 21131 |
} |
| 21132 |
if (column <= 0) { |
| 21133 |
this.moveCursorTo(row, 0); |
| 21134 |
this.moveCursorLeft(); |
| 21135 |
if (row > 0) |
| 21136 |
this.moveCursorWordLeft(); |
| 21137 |
return; |
| 21138 |
} |
| 21139 |
if (match = this.session.tokenRe.exec(leftOfCursor)) { |
| 21140 |
column -= this.session.tokenRe.lastIndex; |
| 21141 |
this.session.tokenRe.lastIndex = 0; |
| 21142 |
} |
| 21143 |
|
| 21144 |
this.moveCursorTo(row, column); |
| 21145 |
}; |
| 21146 |
|
| 21147 |
this.$shortWordEndIndex = function(rightOfCursor) { |
| 21148 |
var match, index = 0, ch; |
| 21149 |
var whitespaceRe = /\s/; |
| 21150 |
var tokenRe = this.session.tokenRe; |
| 21151 |
|
| 21152 |
tokenRe.lastIndex = 0; |
| 21153 |
if (match = this.session.tokenRe.exec(rightOfCursor)) { |
| 21154 |
index = this.session.tokenRe.lastIndex; |
| 21155 |
} else { |
| 21156 |
while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch)) |
| 21157 |
index ++; |
| 21158 |
|
| 21159 |
if (index < 1) { |
| 21160 |
tokenRe.lastIndex = 0; |
| 21161 |
while ((ch = rightOfCursor[index]) && !tokenRe.test(ch)) { |
| 21162 |
tokenRe.lastIndex = 0; |
| 21163 |
index ++; |
| 21164 |
if (whitespaceRe.test(ch)) { |
| 21165 |
if (index > 2) { |
| 21166 |
index--; |
| 21167 |
break; |
| 21168 |
} else { |
| 21169 |
while ((ch = rightOfCursor[index]) && whitespaceRe.test(ch)) |
| 21170 |
index ++; |
| 21171 |
if (index > 2) |
| 21172 |
break; |
| 21173 |
} |
| 21174 |
} |
| 21175 |
} |
| 21176 |
} |
| 21177 |
} |
| 21178 |
tokenRe.lastIndex = 0; |
| 21179 |
|
| 21180 |
return index; |
| 21181 |
}; |
| 21182 |
|
| 21183 |
this.moveCursorShortWordRight = function() { |
| 21184 |
var row = this.lead.row; |
| 21185 |
var column = this.lead.column; |
| 21186 |
var line = this.doc.getLine(row); |
| 21187 |
var rightOfCursor = line.substring(column); |
| 21188 |
|
| 21189 |
var fold = this.session.getFoldAt(row, column, 1); |
| 21190 |
if (fold) |
| 21191 |
return this.moveCursorTo(fold.end.row, fold.end.column); |
| 21192 |
|
| 21193 |
if (column == line.length) { |
| 21194 |
var l = this.doc.getLength(); |
| 21195 |
do { |
| 21196 |
row++; |
| 21197 |
rightOfCursor = this.doc.getLine(row); |
| 21198 |
} while (row < l && /^\s*$/.test(rightOfCursor)); |
| 21199 |
|
| 21200 |
if (!/^\s+/.test(rightOfCursor)) |
| 21201 |
rightOfCursor = ""; |
| 21202 |
column = 0; |
| 21203 |
} |
| 21204 |
|
| 21205 |
var index = this.$shortWordEndIndex(rightOfCursor); |
| 21206 |
|
| 21207 |
this.moveCursorTo(row, column + index); |
| 21208 |
}; |
| 21209 |
|
| 21210 |
this.moveCursorShortWordLeft = function() { |
| 21211 |
var row = this.lead.row; |
| 21212 |
var column = this.lead.column; |
| 21213 |
|
| 21214 |
var fold; |
| 21215 |
if (fold = this.session.getFoldAt(row, column, -1)) |
| 21216 |
return this.moveCursorTo(fold.start.row, fold.start.column); |
| 21217 |
|
| 21218 |
var line = this.session.getLine(row).substring(0, column); |
| 21219 |
if (column === 0) { |
| 21220 |
do { |
| 21221 |
row--; |
| 21222 |
line = this.doc.getLine(row); |
| 21223 |
} while (row > 0 && /^\s*$/.test(line)); |
| 21224 |
|
| 21225 |
column = line.length; |
| 21226 |
if (!/\s+$/.test(line)) |
| 21227 |
line = ""; |
| 21228 |
} |
| 21229 |
|
| 21230 |
var leftOfCursor = lang.stringReverse(line); |
| 21231 |
var index = this.$shortWordEndIndex(leftOfCursor); |
| 21232 |
|
| 21233 |
return this.moveCursorTo(row, column - index); |
| 21234 |
}; |
| 21235 |
|
| 21236 |
this.moveCursorWordRight = function() { |
| 21237 |
if (this.session.$selectLongWords) |
| 21238 |
this.moveCursorLongWordRight(); |
| 21239 |
else |
| 21240 |
this.moveCursorShortWordRight(); |
| 21241 |
}; |
| 21242 |
|
| 21243 |
this.moveCursorWordLeft = function() { |
| 21244 |
if (this.session.$selectLongWords) |
| 21245 |
this.moveCursorLongWordLeft(); |
| 21246 |
else |
| 21247 |
this.moveCursorShortWordLeft(); |
| 21248 |
}; |
| 21249 |
this.moveCursorBy = function(rows, chars) { |
| 21250 |
var screenPos = this.session.documentToScreenPosition( |
| 21251 |
this.lead.row, |
| 21252 |
this.lead.column |
| 21253 |
); |
| 21254 |
|
| 21255 |
if (chars === 0) { |
| 21256 |
if (this.$desiredColumn) |
| 21257 |
screenPos.column = this.$desiredColumn; |
| 21258 |
else |
| 21259 |
this.$desiredColumn = screenPos.column; |
| 21260 |
} |
| 21261 |
|
| 21262 |
var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column); |
| 21263 |
|
| 21264 |
if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) { |
| 21265 |
if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) { |
| 21266 |
if (docPos.row > 0 || rows > 0) |
| 21267 |
docPos.row++; |
| 21268 |
} |
| 21269 |
} |
| 21270 |
this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); |
| 21271 |
}; |
| 21272 |
this.moveCursorToPosition = function(position) { |
| 21273 |
this.moveCursorTo(position.row, position.column); |
| 21274 |
}; |
| 21275 |
this.moveCursorTo = function(row, column, keepDesiredColumn) { |
| 21276 |
var fold = this.session.getFoldAt(row, column, 1); |
| 21277 |
if (fold) { |
| 21278 |
row = fold.start.row; |
| 21279 |
column = fold.start.column; |
| 21280 |
} |
| 21281 |
|
| 21282 |
this.$keepDesiredColumnOnChange = true; |
| 21283 |
this.lead.setPosition(row, column); |
| 21284 |
this.$keepDesiredColumnOnChange = false; |
| 21285 |
|
| 21286 |
if (!keepDesiredColumn) |
| 21287 |
this.$desiredColumn = null; |
| 21288 |
}; |
| 21289 |
this.moveCursorToScreen = function(row, column, keepDesiredColumn) { |
| 21290 |
var pos = this.session.screenToDocumentPosition(row, column); |
| 21291 |
this.moveCursorTo(pos.row, pos.column, keepDesiredColumn); |
| 21292 |
}; |
| 21293 |
this.detach = function() { |
| 21294 |
this.lead.detach(); |
| 21295 |
this.anchor.detach(); |
| 21296 |
this.session = this.doc = null; |
| 21297 |
}; |
| 21298 |
|
| 21299 |
this.fromOrientedRange = function(range) { |
| 21300 |
this.setSelectionRange(range, range.cursor == range.start); |
| 21301 |
this.$desiredColumn = range.desiredColumn || this.$desiredColumn; |
| 21302 |
}; |
| 21303 |
|
| 21304 |
this.toOrientedRange = function(range) { |
| 21305 |
var r = this.getRange(); |
| 21306 |
if (range) { |
| 21307 |
range.start.column = r.start.column; |
| 21308 |
range.start.row = r.start.row; |
| 21309 |
range.end.column = r.end.column; |
| 21310 |
range.end.row = r.end.row; |
| 21311 |
} else { |
| 21312 |
range = r; |
| 21313 |
} |
| 21314 |
|
| 21315 |
range.cursor = this.isBackwards() ? range.start : range.end; |
| 21316 |
range.desiredColumn = this.$desiredColumn; |
| 21317 |
return range; |
| 21318 |
}; |
| 21319 |
this.getRangeOfMovements = function(func) { |
| 21320 |
var start = this.getCursor(); |
| 21321 |
try { |
| 21322 |
func(this); |
| 21323 |
var end = this.getCursor(); |
| 21324 |
return Range.fromPoints(start,end); |
| 21325 |
} catch(e) { |
| 21326 |
return Range.fromPoints(start,start); |
| 21327 |
} finally { |
| 21328 |
this.moveCursorToPosition(start); |
| 21329 |
} |
| 21330 |
}; |
| 21331 |
|
| 21332 |
this.toJSON = function() { |
| 21333 |
if (this.rangeCount) { |
| 21334 |
var data = this.ranges.map(function(r) { |
| 21335 |
var r1 = r.clone(); |
| 21336 |
r1.isBackwards = r.cursor == r.start; |
| 21337 |
return r1; |
| 21338 |
}); |
| 21339 |
} else { |
| 21340 |
var data = this.getRange(); |
| 21341 |
data.isBackwards = this.isBackwards(); |
| 21342 |
} |
| 21343 |
return data; |
| 21344 |
}; |
| 21345 |
|
| 21346 |
this.fromJSON = function(data) { |
| 21347 |
if (data.start == undefined) { |
| 21348 |
if (this.rangeList) { |
| 21349 |
this.toSingleRange(data[0]); |
| 21350 |
for (var i = data.length; i--; ) { |
| 21351 |
var r = Range.fromPoints(data[i].start, data[i].end); |
| 21352 |
if (data[i].isBackwards) |
| 21353 |
r.cursor = r.start; |
| 21354 |
this.addRange(r, true); |
| 21355 |
} |
| 21356 |
return; |
| 21357 |
} else |
| 21358 |
data = data[0]; |
| 21359 |
} |
| 21360 |
if (this.rangeList) |
| 21361 |
this.toSingleRange(data); |
| 21362 |
this.setSelectionRange(data, data.isBackwards); |
| 21363 |
}; |
| 21364 |
|
| 21365 |
this.isEqual = function(data) { |
| 21366 |
if ((data.length || this.rangeCount) && data.length != this.rangeCount) |
| 21367 |
return false; |
| 21368 |
if (!data.length || !this.ranges) |
| 21369 |
return this.getRange().isEqual(data); |
| 21370 |
|
| 21371 |
for (var i = this.ranges.length; i--; ) { |
| 21372 |
if (!this.ranges[i].isEqual(data[i])) |
| 21373 |
return false; |
| 21374 |
} |
| 21375 |
return true; |
| 21376 |
}; |
| 21377 |
|
| 21378 |
}).call(Selection.prototype); |
| 21379 |
|
| 21380 |
exports.Selection = Selection; |
| 21381 |
}); |
| 21382 |
|
| 21383 |
ace.define("ace/tokenizer",["require","exports","module","ace/config"], function(acequire, exports, module) { |
| 21384 |
"use strict"; |
| 21385 |
|
| 21386 |
var config = acequire("./config"); |
| 21387 |
var MAX_TOKEN_COUNT = 2000; |
| 21388 |
var Tokenizer = function(rules) { |
| 21389 |
this.states = rules; |
| 21390 |
|
| 21391 |
this.regExps = {}; |
| 21392 |
this.matchMappings = {}; |
| 21393 |
for (var key in this.states) { |
| 21394 |
var state = this.states[key]; |
| 21395 |
var ruleRegExps = []; |
| 21396 |
var matchTotal = 0; |
| 21397 |
var mapping = this.matchMappings[key] = {defaultToken: "text"}; |
| 21398 |
var flag = "g"; |
| 21399 |
|
| 21400 |
var splitterRurles = []; |
| 21401 |
for (var i = 0; i < state.length; i++) { |
| 21402 |
var rule = state[i]; |
| 21403 |
if (rule.defaultToken) |
| 21404 |
mapping.defaultToken = rule.defaultToken; |
| 21405 |
if (rule.caseInsensitive) |
| 21406 |
flag = "gi"; |
| 21407 |
if (rule.regex == null) |
| 21408 |
continue; |
| 21409 |
|
| 21410 |
if (rule.regex instanceof RegExp) |
| 21411 |
rule.regex = rule.regex.toString().slice(1, -1); |
| 21412 |
var adjustedregex = rule.regex; |
| 21413 |
var matchcount = new RegExp("(?:(" + adjustedregex + ")|(.))").exec("a").length - 2; |
| 21414 |
if (Array.isArray(rule.token)) { |
| 21415 |
if (rule.token.length == 1 || matchcount == 1) { |
| 21416 |
rule.token = rule.token[0]; |
| 21417 |
} else if (matchcount - 1 != rule.token.length) { |
| 21418 |
this.reportError("number of classes and regexp groups doesn't match", { |
| 21419 |
rule: rule, |
| 21420 |
groupCount: matchcount - 1 |
| 21421 |
}); |
| 21422 |
rule.token = rule.token[0]; |
| 21423 |
} else { |
| 21424 |
rule.tokenArray = rule.token; |
| 21425 |
rule.token = null; |
| 21426 |
rule.onMatch = this.$arrayTokens; |
| 21427 |
} |
| 21428 |
} else if (typeof rule.token == "function" && !rule.onMatch) { |
| 21429 |
if (matchcount > 1) |
| 21430 |
rule.onMatch = this.$applyToken; |
| 21431 |
else |
| 21432 |
rule.onMatch = rule.token; |
| 21433 |
} |
| 21434 |
|
| 21435 |
if (matchcount > 1) { |
| 21436 |
if (/\\\d/.test(rule.regex)) { |
| 21437 |
adjustedregex = rule.regex.replace(/\\([0-9]+)/g, function(match, digit) { |
| 21438 |
return "\\" + (parseInt(digit, 10) + matchTotal + 1); |
| 21439 |
}); |
| 21440 |
} else { |
| 21441 |
matchcount = 1; |
| 21442 |
adjustedregex = this.removeCapturingGroups(rule.regex); |
| 21443 |
} |
| 21444 |
if (!rule.splitRegex && typeof rule.token != "string") |
| 21445 |
splitterRurles.push(rule); // flag will be known only at the very end |
| 21446 |
} |
| 21447 |
|
| 21448 |
mapping[matchTotal] = i; |
| 21449 |
matchTotal += matchcount; |
| 21450 |
|
| 21451 |
ruleRegExps.push(adjustedregex); |
| 21452 |
if (!rule.onMatch) |
| 21453 |
rule.onMatch = null; |
| 21454 |
} |
| 21455 |
|
| 21456 |
if (!ruleRegExps.length) { |
| 21457 |
mapping[0] = 0; |
| 21458 |
ruleRegExps.push("$"); |
| 21459 |
} |
| 21460 |
|
| 21461 |
splitterRurles.forEach(function(rule) { |
| 21462 |
rule.splitRegex = this.createSplitterRegexp(rule.regex, flag); |
| 21463 |
}, this); |
| 21464 |
|
| 21465 |
this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag); |
| 21466 |
} |
| 21467 |
}; |
| 21468 |
|
| 21469 |
(function() { |
| 21470 |
this.$setMaxTokenCount = function(m) { |
| 21471 |
MAX_TOKEN_COUNT = m | 0; |
| 21472 |
}; |
| 21473 |
|
| 21474 |
this.$applyToken = function(str) { |
| 21475 |
var values = this.splitRegex.exec(str).slice(1); |
| 21476 |
var types = this.token.apply(this, values); |
| 21477 |
if (typeof types === "string") |
| 21478 |
return [{type: types, value: str}]; |
| 21479 |
|
| 21480 |
var tokens = []; |
| 21481 |
for (var i = 0, l = types.length; i < l; i++) { |
| 21482 |
if (values[i]) |
| 21483 |
tokens[tokens.length] = { |
| 21484 |
type: types[i], |
| 21485 |
value: values[i] |
| 21486 |
}; |
| 21487 |
} |
| 21488 |
return tokens; |
| 21489 |
}; |
| 21490 |
|
| 21491 |
this.$arrayTokens = function(str) { |
| 21492 |
if (!str) |
| 21493 |
return []; |
| 21494 |
var values = this.splitRegex.exec(str); |
| 21495 |
if (!values) |
| 21496 |
return "text"; |
| 21497 |
var tokens = []; |
| 21498 |
var types = this.tokenArray; |
| 21499 |
for (var i = 0, l = types.length; i < l; i++) { |
| 21500 |
if (values[i + 1]) |
| 21501 |
tokens[tokens.length] = { |
| 21502 |
type: types[i], |
| 21503 |
value: values[i + 1] |
| 21504 |
}; |
| 21505 |
} |
| 21506 |
return tokens; |
| 21507 |
}; |
| 21508 |
|
| 21509 |
this.removeCapturingGroups = function(src) { |
| 21510 |
var r = src.replace( |
| 21511 |
/\[(?:\\.|[^\]])*?\]|\\.|\(\?[:=!]|(\()/g, |
| 21512 |
function(x, y) {return y ? "(?:" : x;} |
| 21513 |
); |
| 21514 |
return r; |
| 21515 |
}; |
| 21516 |
|
| 21517 |
this.createSplitterRegexp = function(src, flag) { |
| 21518 |
if (src.indexOf("(?=") != -1) { |
| 21519 |
var stack = 0; |
| 21520 |
var inChClass = false; |
| 21521 |
var lastCapture = {}; |
| 21522 |
src.replace(/(\\.)|(\((?:\?[=!])?)|(\))|([\[\]])/g, function( |
| 21523 |
m, esc, parenOpen, parenClose, square, index |
| 21524 |
) { |
| 21525 |
if (inChClass) { |
| 21526 |
inChClass = square != "]"; |
| 21527 |
} else if (square) { |
| 21528 |
inChClass = true; |
| 21529 |
} else if (parenClose) { |
| 21530 |
if (stack == lastCapture.stack) { |
| 21531 |
lastCapture.end = index+1; |
| 21532 |
lastCapture.stack = -1; |
| 21533 |
} |
| 21534 |
stack--; |
| 21535 |
} else if (parenOpen) { |
| 21536 |
stack++; |
| 21537 |
if (parenOpen.length != 1) { |
| 21538 |
lastCapture.stack = stack |
| 21539 |
lastCapture.start = index; |
| 21540 |
} |
| 21541 |
} |
| 21542 |
return m; |
| 21543 |
}); |
| 21544 |
|
| 21545 |
if (lastCapture.end != null && /^\)*$/.test(src.substr(lastCapture.end))) |
| 21546 |
src = src.substring(0, lastCapture.start) + src.substr(lastCapture.end); |
| 21547 |
} |
| 21548 |
if (src.charAt(0) != "^") src = "^" + src; |
| 21549 |
if (src.charAt(src.length - 1) != "$") src += "$"; |
| 21550 |
|
| 21551 |
return new RegExp(src, (flag||"").replace("g", "")); |
| 21552 |
}; |
| 21553 |
this.getLineTokens = function(line, startState) { |
| 21554 |
if (startState && typeof startState != "string") { |
| 21555 |
var stack = startState.slice(0); |
| 21556 |
startState = stack[0]; |
| 21557 |
if (startState === "#tmp") { |
| 21558 |
stack.shift() |
| 21559 |
startState = stack.shift() |
| 21560 |
} |
| 21561 |
} else |
| 21562 |
var stack = []; |
| 21563 |
|
| 21564 |
var currentState = startState || "start"; |
| 21565 |
var state = this.states[currentState]; |
| 21566 |
if (!state) { |
| 21567 |
currentState = "start"; |
| 21568 |
state = this.states[currentState]; |
| 21569 |
} |
| 21570 |
var mapping = this.matchMappings[currentState]; |
| 21571 |
var re = this.regExps[currentState]; |
| 21572 |
re.lastIndex = 0; |
| 21573 |
|
| 21574 |
var match, tokens = []; |
| 21575 |
var lastIndex = 0; |
| 21576 |
var matchAttempts = 0; |
| 21577 |
|
| 21578 |
var token = {type: null, value: ""}; |
| 21579 |
|
| 21580 |
while (match = re.exec(line)) { |
| 21581 |
var type = mapping.defaultToken; |
| 21582 |
var rule = null; |
| 21583 |
var value = match[0]; |
| 21584 |
var index = re.lastIndex; |
| 21585 |
|
| 21586 |
if (index - value.length > lastIndex) { |
| 21587 |
var skipped = line.substring(lastIndex, index - value.length); |
| 21588 |
if (token.type == type) { |
| 21589 |
token.value += skipped; |
| 21590 |
} else { |
| 21591 |
if (token.type) |
| 21592 |
tokens.push(token); |
| 21593 |
token = {type: type, value: skipped}; |
| 21594 |
} |
| 21595 |
} |
| 21596 |
|
| 21597 |
for (var i = 0; i < match.length-2; i++) { |
| 21598 |
if (match[i + 1] === undefined) |
| 21599 |
continue; |
| 21600 |
|
| 21601 |
rule = state[mapping[i]]; |
| 21602 |
|
| 21603 |
if (rule.onMatch) |
| 21604 |
type = rule.onMatch(value, currentState, stack); |
| 21605 |
else |
| 21606 |
type = rule.token; |
| 21607 |
|
| 21608 |
if (rule.next) { |
| 21609 |
if (typeof rule.next == "string") { |
| 21610 |
currentState = rule.next; |
| 21611 |
} else { |
| 21612 |
currentState = rule.next(currentState, stack); |
| 21613 |
} |
| 21614 |
|
| 21615 |
state = this.states[currentState]; |
| 21616 |
if (!state) { |
| 21617 |
this.reportError("state doesn't exist", currentState); |
| 21618 |
currentState = "start"; |
| 21619 |
state = this.states[currentState]; |
| 21620 |
} |
| 21621 |
mapping = this.matchMappings[currentState]; |
| 21622 |
lastIndex = index; |
| 21623 |
re = this.regExps[currentState]; |
| 21624 |
re.lastIndex = index; |
| 21625 |
} |
| 21626 |
break; |
| 21627 |
} |
| 21628 |
|
| 21629 |
if (value) { |
| 21630 |
if (typeof type === "string") { |
| 21631 |
if ((!rule || rule.merge !== false) && token.type === type) { |
| 21632 |
token.value += value; |
| 21633 |
} else { |
| 21634 |
if (token.type) |
| 21635 |
tokens.push(token); |
| 21636 |
token = {type: type, value: value}; |
| 21637 |
} |
| 21638 |
} else if (type) { |
| 21639 |
if (token.type) |
| 21640 |
tokens.push(token); |
| 21641 |
token = {type: null, value: ""}; |
| 21642 |
for (var i = 0; i < type.length; i++) |
| 21643 |
tokens.push(type[i]); |
| 21644 |
} |
| 21645 |
} |
| 21646 |
|
| 21647 |
if (lastIndex == line.length) |
| 21648 |
break; |
| 21649 |
|
| 21650 |
lastIndex = index; |
| 21651 |
|
| 21652 |
if (matchAttempts++ > MAX_TOKEN_COUNT) { |
| 21653 |
if (matchAttempts > 2 * line.length) { |
| 21654 |
this.reportError("infinite loop with in ace tokenizer", { |
| 21655 |
startState: startState, |
| 21656 |
line: line |
| 21657 |
}); |
| 21658 |
} |
| 21659 |
while (lastIndex < line.length) { |
| 21660 |
if (token.type) |
| 21661 |
tokens.push(token); |
| 21662 |
token = { |
| 21663 |
value: line.substring(lastIndex, lastIndex += 2000), |
| 21664 |
type: "overflow" |
| 21665 |
}; |
| 21666 |
} |
| 21667 |
currentState = "start"; |
| 21668 |
stack = []; |
| 21669 |
break; |
| 21670 |
} |
| 21671 |
} |
| 21672 |
|
| 21673 |
if (token.type) |
| 21674 |
tokens.push(token); |
| 21675 |
|
| 21676 |
if (stack.length > 1) { |
| 21677 |
if (stack[0] !== currentState) |
| 21678 |
stack.unshift("#tmp", currentState); |
| 21679 |
} |
| 21680 |
return { |
| 21681 |
tokens : tokens, |
| 21682 |
state : stack.length ? stack : currentState |
| 21683 |
}; |
| 21684 |
}; |
| 21685 |
|
| 21686 |
this.reportError = config.reportError; |
| 21687 |
|
| 21688 |
}).call(Tokenizer.prototype); |
| 21689 |
|
| 21690 |
exports.Tokenizer = Tokenizer; |
| 21691 |
}); |
| 21692 |
|
| 21693 |
ace.define("ace/mode/text_highlight_rules",["require","exports","module","ace/lib/lang"], function(acequire, exports, module) { |
| 21694 |
"use strict"; |
| 21695 |
|
| 21696 |
var lang = acequire("../lib/lang"); |
| 21697 |
|
| 21698 |
var TextHighlightRules = function() { |
| 21699 |
|
| 21700 |
this.$rules = { |
| 21701 |
"start" : [{ |
| 21702 |
token : "empty_line", |
| 21703 |
regex : '^$' |
| 21704 |
}, { |
| 21705 |
defaultToken : "text" |
| 21706 |
}] |
| 21707 |
}; |
| 21708 |
}; |
| 21709 |
|
| 21710 |
(function() { |
| 21711 |
|
| 21712 |
this.addRules = function(rules, prefix) { |
| 21713 |
if (!prefix) { |
| 21714 |
for (var key in rules) |
| 21715 |
this.$rules[key] = rules[key]; |
| 21716 |
return; |
| 21717 |
} |
| 21718 |
for (var key in rules) { |
| 21719 |
var state = rules[key]; |
| 21720 |
for (var i = 0; i < state.length; i++) { |
| 21721 |
var rule = state[i]; |
| 21722 |
if (rule.next || rule.onMatch) { |
| 21723 |
if (typeof rule.next == "string") { |
| 21724 |
if (rule.next.indexOf(prefix) !== 0) |
| 21725 |
rule.next = prefix + rule.next; |
| 21726 |
} |
| 21727 |
if (rule.nextState && rule.nextState.indexOf(prefix) !== 0) |
| 21728 |
rule.nextState = prefix + rule.nextState; |
| 21729 |
} |
| 21730 |
} |
| 21731 |
this.$rules[prefix + key] = state; |
| 21732 |
} |
| 21733 |
}; |
| 21734 |
|
| 21735 |
this.getRules = function() { |
| 21736 |
return this.$rules; |
| 21737 |
}; |
| 21738 |
|
| 21739 |
this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) { |
| 21740 |
var embedRules = typeof HighlightRules == "function" |
| 21741 |
? new HighlightRules().getRules() |
| 21742 |
: HighlightRules; |
| 21743 |
if (states) { |
| 21744 |
for (var i = 0; i < states.length; i++) |
| 21745 |
states[i] = prefix + states[i]; |
| 21746 |
} else { |
| 21747 |
states = []; |
| 21748 |
for (var key in embedRules) |
| 21749 |
states.push(prefix + key); |
| 21750 |
} |
| 21751 |
|
| 21752 |
this.addRules(embedRules, prefix); |
| 21753 |
|
| 21754 |
if (escapeRules) { |
| 21755 |
var addRules = Array.prototype[append ? "push" : "unshift"]; |
| 21756 |
for (var i = 0; i < states.length; i++) |
| 21757 |
addRules.apply(this.$rules[states[i]], lang.deepCopy(escapeRules)); |
| 21758 |
} |
| 21759 |
|
| 21760 |
if (!this.$embeds) |
| 21761 |
this.$embeds = []; |
| 21762 |
this.$embeds.push(prefix); |
| 21763 |
}; |
| 21764 |
|
| 21765 |
this.getEmbeds = function() { |
| 21766 |
return this.$embeds; |
| 21767 |
}; |
| 21768 |
|
| 21769 |
var pushState = function(currentState, stack) { |
| 21770 |
if (currentState != "start" || stack.length) |
| 21771 |
stack.unshift(this.nextState, currentState); |
| 21772 |
return this.nextState; |
| 21773 |
}; |
| 21774 |
var popState = function(currentState, stack) { |
| 21775 |
stack.shift(); |
| 21776 |
return stack.shift() || "start"; |
| 21777 |
}; |
| 21778 |
|
| 21779 |
this.normalizeRules = function() { |
| 21780 |
var id = 0; |
| 21781 |
var rules = this.$rules; |
| 21782 |
function processState(key) { |
| 21783 |
var state = rules[key]; |
| 21784 |
state.processed = true; |
| 21785 |
for (var i = 0; i < state.length; i++) { |
| 21786 |
var rule = state[i]; |
| 21787 |
if (!rule.regex && rule.start) { |
| 21788 |
rule.regex = rule.start; |
| 21789 |
if (!rule.next) |
| 21790 |
rule.next = []; |
| 21791 |
rule.next.push({ |
| 21792 |
defaultToken: rule.token |
| 21793 |
}, { |
| 21794 |
token: rule.token + ".end", |
| 21795 |
regex: rule.end || rule.start, |
| 21796 |
next: "pop" |
| 21797 |
}); |
| 21798 |
rule.token = rule.token + ".start"; |
| 21799 |
rule.push = true; |
| 21800 |
} |
| 21801 |
var next = rule.next || rule.push; |
| 21802 |
if (next && Array.isArray(next)) { |
| 21803 |
var stateName = rule.stateName; |
| 21804 |
if (!stateName) { |
| 21805 |
stateName = rule.token; |
| 21806 |
if (typeof stateName != "string") |
| 21807 |
stateName = stateName[0] || ""; |
| 21808 |
if (rules[stateName]) |
| 21809 |
stateName += id++; |
| 21810 |
} |
| 21811 |
rules[stateName] = next; |
| 21812 |
rule.next = stateName; |
| 21813 |
processState(stateName); |
| 21814 |
} else if (next == "pop") { |
| 21815 |
rule.next = popState; |
| 21816 |
} |
| 21817 |
|
| 21818 |
if (rule.push) { |
| 21819 |
rule.nextState = rule.next || rule.push; |
| 21820 |
rule.next = pushState; |
| 21821 |
delete rule.push; |
| 21822 |
} |
| 21823 |
|
| 21824 |
if (rule.rules) { |
| 21825 |
for (var r in rule.rules) { |
| 21826 |
if (rules[r]) { |
| 21827 |
if (rules[r].push) |
| 21828 |
rules[r].push.apply(rules[r], rule.rules[r]); |
| 21829 |
} else { |
| 21830 |
rules[r] = rule.rules[r]; |
| 21831 |
} |
| 21832 |
} |
| 21833 |
} |
| 21834 |
if (rule.include || typeof rule == "string") { |
| 21835 |
var includeName = rule.include || rule; |
| 21836 |
var toInsert = rules[includeName]; |
| 21837 |
} else if (Array.isArray(rule)) |
| 21838 |
toInsert = rule; |
| 21839 |
|
| 21840 |
if (toInsert) { |
| 21841 |
var args = [i, 1].concat(toInsert); |
| 21842 |
if (rule.noEscape) |
| 21843 |
args = args.filter(function(x) {return !x.next;}); |
| 21844 |
state.splice.apply(state, args); |
| 21845 |
i--; |
| 21846 |
toInsert = null; |
| 21847 |
} |
| 21848 |
|
| 21849 |
if (rule.keywordMap) { |
| 21850 |
rule.token = this.createKeywordMapper( |
| 21851 |
rule.keywordMap, rule.defaultToken || "text", rule.caseInsensitive |
| 21852 |
); |
| 21853 |
delete rule.defaultToken; |
| 21854 |
} |
| 21855 |
} |
| 21856 |
} |
| 21857 |
Object.keys(rules).forEach(processState, this); |
| 21858 |
}; |
| 21859 |
|
| 21860 |
this.createKeywordMapper = function(map, defaultToken, ignoreCase, splitChar) { |
| 21861 |
var keywords = Object.create(null); |
| 21862 |
Object.keys(map).forEach(function(className) { |
| 21863 |
var a = map[className]; |
| 21864 |
if (ignoreCase) |
| 21865 |
a = a.toLowerCase(); |
| 21866 |
var list = a.split(splitChar || "|"); |
| 21867 |
for (var i = list.length; i--; ) |
| 21868 |
keywords[list[i]] = className; |
| 21869 |
}); |
| 21870 |
if (Object.getPrototypeOf(keywords)) { |
| 21871 |
keywords.__proto__ = null; |
| 21872 |
} |
| 21873 |
this.$keywordList = Object.keys(keywords); |
| 21874 |
map = null; |
| 21875 |
return ignoreCase |
| 21876 |
? function(value) {return keywords[value.toLowerCase()] || defaultToken } |
| 21877 |
: function(value) {return keywords[value] || defaultToken }; |
| 21878 |
}; |
| 21879 |
|
| 21880 |
this.getKeywords = function() { |
| 21881 |
return this.$keywords; |
| 21882 |
}; |
| 21883 |
|
| 21884 |
}).call(TextHighlightRules.prototype); |
| 21885 |
|
| 21886 |
exports.TextHighlightRules = TextHighlightRules; |
| 21887 |
}); |
| 21888 |
|
| 21889 |
ace.define("ace/mode/behaviour",["require","exports","module"], function(acequire, exports, module) { |
| 21890 |
"use strict"; |
| 21891 |
|
| 21892 |
var Behaviour = function() { |
| 21893 |
this.$behaviours = {}; |
| 21894 |
}; |
| 21895 |
|
| 21896 |
(function () { |
| 21897 |
|
| 21898 |
this.add = function (name, action, callback) { |
| 21899 |
switch (undefined) { |
| 21900 |
case this.$behaviours: |
| 21901 |
this.$behaviours = {}; |
| 21902 |
case this.$behaviours[name]: |
| 21903 |
this.$behaviours[name] = {}; |
| 21904 |
} |
| 21905 |
this.$behaviours[name][action] = callback; |
| 21906 |
} |
| 21907 |
|
| 21908 |
this.addBehaviours = function (behaviours) { |
| 21909 |
for (var key in behaviours) { |
| 21910 |
for (var action in behaviours[key]) { |
| 21911 |
this.add(key, action, behaviours[key][action]); |
| 21912 |
} |
| 21913 |
} |
| 21914 |
} |
| 21915 |
|
| 21916 |
this.remove = function (name) { |
| 21917 |
if (this.$behaviours && this.$behaviours[name]) { |
| 21918 |
delete this.$behaviours[name]; |
| 21919 |
} |
| 21920 |
} |
| 21921 |
|
| 21922 |
this.inherit = function (mode, filter) { |
| 21923 |
if (typeof mode === "function") { |
| 21924 |
var behaviours = new mode().getBehaviours(filter); |
| 21925 |
} else { |
| 21926 |
var behaviours = mode.getBehaviours(filter); |
| 21927 |
} |
| 21928 |
this.addBehaviours(behaviours); |
| 21929 |
} |
| 21930 |
|
| 21931 |
this.getBehaviours = function (filter) { |
| 21932 |
if (!filter) { |
| 21933 |
return this.$behaviours; |
| 21934 |
} else { |
| 21935 |
var ret = {} |
| 21936 |
for (var i = 0; i < filter.length; i++) { |
| 21937 |
if (this.$behaviours[filter[i]]) { |
| 21938 |
ret[filter[i]] = this.$behaviours[filter[i]]; |
| 21939 |
} |
| 21940 |
} |
| 21941 |
return ret; |
| 21942 |
} |
| 21943 |
} |
| 21944 |
|
| 21945 |
}).call(Behaviour.prototype); |
| 21946 |
|
| 21947 |
exports.Behaviour = Behaviour; |
| 21948 |
}); |
| 21949 |
|
| 21950 |
ace.define("ace/unicode",["require","exports","module"], function(acequire, exports, module) { |
| 21951 |
"use strict"; |
| 21952 |
exports.packages = {}; |
| 21953 |
|
| 21954 |
addUnicodePackage({ |
| 21955 |
L: "0041-005A0061-007A00AA00B500BA00C0-00D600D8-00F600F8-02C102C6-02D102E0-02E402EC02EE0370-037403760377037A-037D03860388-038A038C038E-03A103A3-03F503F7-0481048A-05250531-055605590561-058705D0-05EA05F0-05F20621-064A066E066F0671-06D306D506E506E606EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA07F407F507FA0800-0815081A082408280904-0939093D09500958-0961097109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E460E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EC60EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10A0-10C510D0-10FA10FC1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317D717DC1820-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541AA71B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C7D1CE9-1CEC1CEE-1CF11D00-1DBF1E00-1F151F18-1F1D1F20-1F451F48-1F4D1F50-1F571F591F5B1F5D1F5F-1F7D1F80-1FB41FB6-1FBC1FBE1FC2-1FC41FC6-1FCC1FD0-1FD31FD6-1FDB1FE0-1FEC1FF2-1FF41FF6-1FFC2071207F2090-209421022107210A-211321152119-211D212421262128212A-212D212F-2139213C-213F2145-2149214E218321842C00-2C2E2C30-2C5E2C60-2CE42CEB-2CEE2D00-2D252D30-2D652D6F2D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE2E2F300530063031-3035303B303C3041-3096309D-309F30A1-30FA30FC-30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A48CA4D0-A4FDA500-A60CA610-A61FA62AA62BA640-A65FA662-A66EA67F-A697A6A0-A6E5A717-A71FA722-A788A78BA78CA7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2A9CFAA00-AA28AA40-AA42AA44-AA4BAA60-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADB-AADDABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB00-FB06FB13-FB17FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF21-FF3AFF41-FF5AFF66-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC", |
| 21956 |
Ll: "0061-007A00AA00B500BA00DF-00F600F8-00FF01010103010501070109010B010D010F01110113011501170119011B011D011F01210123012501270129012B012D012F01310133013501370138013A013C013E014001420144014601480149014B014D014F01510153015501570159015B015D015F01610163016501670169016B016D016F0171017301750177017A017C017E-0180018301850188018C018D019201950199-019B019E01A101A301A501A801AA01AB01AD01B001B401B601B901BA01BD-01BF01C601C901CC01CE01D001D201D401D601D801DA01DC01DD01DF01E101E301E501E701E901EB01ED01EF01F001F301F501F901FB01FD01FF02010203020502070209020B020D020F02110213021502170219021B021D021F02210223022502270229022B022D022F02310233-0239023C023F0240024202470249024B024D024F-02930295-02AF037103730377037B-037D039003AC-03CE03D003D103D5-03D703D903DB03DD03DF03E103E303E503E703E903EB03ED03EF-03F303F503F803FB03FC0430-045F04610463046504670469046B046D046F04710473047504770479047B047D047F0481048B048D048F04910493049504970499049B049D049F04A104A304A504A704A904AB04AD04AF04B104B304B504B704B904BB04BD04BF04C204C404C604C804CA04CC04CE04CF04D104D304D504D704D904DB04DD04DF04E104E304E504E704E904EB04ED04EF04F104F304F504F704F904FB04FD04FF05010503050505070509050B050D050F05110513051505170519051B051D051F0521052305250561-05871D00-1D2B1D62-1D771D79-1D9A1E011E031E051E071E091E0B1E0D1E0F1E111E131E151E171E191E1B1E1D1E1F1E211E231E251E271E291E2B1E2D1E2F1E311E331E351E371E391E3B1E3D1E3F1E411E431E451E471E491E4B1E4D1E4F1E511E531E551E571E591E5B1E5D1E5F1E611E631E651E671E691E6B1E6D1E6F1E711E731E751E771E791E7B1E7D1E7F1E811E831E851E871E891E8B1E8D1E8F1E911E931E95-1E9D1E9F1EA11EA31EA51EA71EA91EAB1EAD1EAF1EB11EB31EB51EB71EB91EBB1EBD1EBF1EC11EC31EC51EC71EC91ECB1ECD1ECF1ED11ED31ED51ED71ED91EDB1EDD1EDF1EE11EE31EE51EE71EE91EEB1EED1EEF1EF11EF31EF51EF71EF91EFB1EFD1EFF-1F071F10-1F151F20-1F271F30-1F371F40-1F451F50-1F571F60-1F671F70-1F7D1F80-1F871F90-1F971FA0-1FA71FB0-1FB41FB61FB71FBE1FC2-1FC41FC61FC71FD0-1FD31FD61FD71FE0-1FE71FF2-1FF41FF61FF7210A210E210F2113212F21342139213C213D2146-2149214E21842C30-2C5E2C612C652C662C682C6A2C6C2C712C732C742C76-2C7C2C812C832C852C872C892C8B2C8D2C8F2C912C932C952C972C992C9B2C9D2C9F2CA12CA32CA52CA72CA92CAB2CAD2CAF2CB12CB32CB52CB72CB92CBB2CBD2CBF2CC12CC32CC52CC72CC92CCB2CCD2CCF2CD12CD32CD52CD72CD92CDB2CDD2CDF2CE12CE32CE42CEC2CEE2D00-2D25A641A643A645A647A649A64BA64DA64FA651A653A655A657A659A65BA65DA65FA663A665A667A669A66BA66DA681A683A685A687A689A68BA68DA68FA691A693A695A697A723A725A727A729A72BA72DA72F-A731A733A735A737A739A73BA73DA73FA741A743A745A747A749A74BA74DA74FA751A753A755A757A759A75BA75DA75FA761A763A765A767A769A76BA76DA76FA771-A778A77AA77CA77FA781A783A785A787A78CFB00-FB06FB13-FB17FF41-FF5A", |
| 21957 |
Lu: "0041-005A00C0-00D600D8-00DE01000102010401060108010A010C010E01100112011401160118011A011C011E01200122012401260128012A012C012E01300132013401360139013B013D013F0141014301450147014A014C014E01500152015401560158015A015C015E01600162016401660168016A016C016E017001720174017601780179017B017D018101820184018601870189-018B018E-0191019301940196-0198019C019D019F01A001A201A401A601A701A901AC01AE01AF01B1-01B301B501B701B801BC01C401C701CA01CD01CF01D101D301D501D701D901DB01DE01E001E201E401E601E801EA01EC01EE01F101F401F6-01F801FA01FC01FE02000202020402060208020A020C020E02100212021402160218021A021C021E02200222022402260228022A022C022E02300232023A023B023D023E02410243-02460248024A024C024E03700372037603860388-038A038C038E038F0391-03A103A3-03AB03CF03D2-03D403D803DA03DC03DE03E003E203E403E603E803EA03EC03EE03F403F703F903FA03FD-042F04600462046404660468046A046C046E04700472047404760478047A047C047E0480048A048C048E04900492049404960498049A049C049E04A004A204A404A604A804AA04AC04AE04B004B204B404B604B804BA04BC04BE04C004C104C304C504C704C904CB04CD04D004D204D404D604D804DA04DC04DE04E004E204E404E604E804EA04EC04EE04F004F204F404F604F804FA04FC04FE05000502050405060508050A050C050E05100512051405160518051A051C051E0520052205240531-055610A0-10C51E001E021E041E061E081E0A1E0C1E0E1E101E121E141E161E181E1A1E1C1E1E1E201E221E241E261E281E2A1E2C1E2E1E301E321E341E361E381E3A1E3C1E3E1E401E421E441E461E481E4A1E4C1E4E1E501E521E541E561E581E5A1E5C1E5E1E601E621E641E661E681E6A1E6C1E6E1E701E721E741E761E781E7A1E7C1E7E1E801E821E841E861E881E8A1E8C1E8E1E901E921E941E9E1EA01EA21EA41EA61EA81EAA1EAC1EAE1EB01EB21EB41EB61EB81EBA1EBC1EBE1EC01EC21EC41EC61EC81ECA1ECC1ECE1ED01ED21ED41ED61ED81EDA1EDC1EDE1EE01EE21EE41EE61EE81EEA1EEC1EEE1EF01EF21EF41EF61EF81EFA1EFC1EFE1F08-1F0F1F18-1F1D1F28-1F2F1F38-1F3F1F48-1F4D1F591F5B1F5D1F5F1F68-1F6F1FB8-1FBB1FC8-1FCB1FD8-1FDB1FE8-1FEC1FF8-1FFB21022107210B-210D2110-211221152119-211D212421262128212A-212D2130-2133213E213F214521832C00-2C2E2C602C62-2C642C672C692C6B2C6D-2C702C722C752C7E-2C802C822C842C862C882C8A2C8C2C8E2C902C922C942C962C982C9A2C9C2C9E2CA02CA22CA42CA62CA82CAA2CAC2CAE2CB02CB22CB42CB62CB82CBA2CBC2CBE2CC02CC22CC42CC62CC82CCA2CCC2CCE2CD02CD22CD42CD62CD82CDA2CDC2CDE2CE02CE22CEB2CEDA640A642A644A646A648A64AA64CA64EA650A652A654A656A658A65AA65CA65EA662A664A666A668A66AA66CA680A682A684A686A688A68AA68CA68EA690A692A694A696A722A724A726A728A72AA72CA72EA732A734A736A738A73AA73CA73EA740A742A744A746A748A74AA74CA74EA750A752A754A756A758A75AA75CA75EA760A762A764A766A768A76AA76CA76EA779A77BA77DA77EA780A782A784A786A78BFF21-FF3A", |
| 21958 |
Lt: "01C501C801CB01F21F88-1F8F1F98-1F9F1FA8-1FAF1FBC1FCC1FFC", |
| 21959 |
Lm: "02B0-02C102C6-02D102E0-02E402EC02EE0374037A0559064006E506E607F407F507FA081A0824082809710E460EC610FC17D718431AA71C78-1C7D1D2C-1D611D781D9B-1DBF2071207F2090-20942C7D2D6F2E2F30053031-3035303B309D309E30FC-30FEA015A4F8-A4FDA60CA67FA717-A71FA770A788A9CFAA70AADDFF70FF9EFF9F", |
| 21960 |
Lo: "01BB01C0-01C3029405D0-05EA05F0-05F20621-063F0641-064A066E066F0671-06D306D506EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA0800-08150904-0939093D09500958-096109720979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10D05-0D0C0D0E-0D100D12-0D280D2A-0D390D3D0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E450E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EDC0EDD0F000F40-0F470F49-0F6C0F88-0F8B1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10D0-10FA1100-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317DC1820-18421844-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541B05-1B331B45-1B4B1B83-1BA01BAE1BAF1C00-1C231C4D-1C4F1C5A-1C771CE9-1CEC1CEE-1CF12135-21382D30-2D652D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE3006303C3041-3096309F30A1-30FA30FF3105-312D3131-318E31A0-31B731F0-31FF3400-4DB54E00-9FCBA000-A014A016-A48CA4D0-A4F7A500-A60BA610-A61FA62AA62BA66EA6A0-A6E5A7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2AA00-AA28AA40-AA42AA44-AA4BAA60-AA6FAA71-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADBAADCABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA2DFA30-FA6DFA70-FAD9FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF66-FF6FFF71-FF9DFFA0-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC", |
| 21961 |
M: "0300-036F0483-04890591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DE-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0903093C093E-094E0951-0955096209630981-098309BC09BE-09C409C709C809CB-09CD09D709E209E30A01-0A030A3C0A3E-0A420A470A480A4B-0A4D0A510A700A710A750A81-0A830ABC0ABE-0AC50AC7-0AC90ACB-0ACD0AE20AE30B01-0B030B3C0B3E-0B440B470B480B4B-0B4D0B560B570B620B630B820BBE-0BC20BC6-0BC80BCA-0BCD0BD70C01-0C030C3E-0C440C46-0C480C4A-0C4D0C550C560C620C630C820C830CBC0CBE-0CC40CC6-0CC80CCA-0CCD0CD50CD60CE20CE30D020D030D3E-0D440D46-0D480D4A-0D4D0D570D620D630D820D830DCA0DCF-0DD40DD60DD8-0DDF0DF20DF30E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F3E0F3F0F71-0F840F860F870F90-0F970F99-0FBC0FC6102B-103E1056-1059105E-10601062-10641067-106D1071-10741082-108D108F109A-109D135F1712-17141732-1734175217531772177317B6-17D317DD180B-180D18A91920-192B1930-193B19B0-19C019C819C91A17-1A1B1A55-1A5E1A60-1A7C1A7F1B00-1B041B34-1B441B6B-1B731B80-1B821BA1-1BAA1C24-1C371CD0-1CD21CD4-1CE81CED1CF21DC0-1DE61DFD-1DFF20D0-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66F-A672A67CA67DA6F0A6F1A802A806A80BA823-A827A880A881A8B4-A8C4A8E0-A8F1A926-A92DA947-A953A980-A983A9B3-A9C0AA29-AA36AA43AA4CAA4DAA7BAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE3-ABEAABECABEDFB1EFE00-FE0FFE20-FE26", |
| 21962 |
Mn: "0300-036F0483-04870591-05BD05BF05C105C205C405C505C70610-061A064B-065E067006D6-06DC06DF-06E406E706E806EA-06ED07110730-074A07A6-07B007EB-07F30816-0819081B-08230825-08270829-082D0900-0902093C0941-0948094D0951-095509620963098109BC09C1-09C409CD09E209E30A010A020A3C0A410A420A470A480A4B-0A4D0A510A700A710A750A810A820ABC0AC1-0AC50AC70AC80ACD0AE20AE30B010B3C0B3F0B41-0B440B4D0B560B620B630B820BC00BCD0C3E-0C400C46-0C480C4A-0C4D0C550C560C620C630CBC0CBF0CC60CCC0CCD0CE20CE30D41-0D440D4D0D620D630DCA0DD2-0DD40DD60E310E34-0E3A0E47-0E4E0EB10EB4-0EB90EBB0EBC0EC8-0ECD0F180F190F350F370F390F71-0F7E0F80-0F840F860F870F90-0F970F99-0FBC0FC6102D-10301032-10371039103A103D103E10581059105E-10601071-1074108210851086108D109D135F1712-17141732-1734175217531772177317B7-17BD17C617C9-17D317DD180B-180D18A91920-19221927192819321939-193B1A171A181A561A58-1A5E1A601A621A65-1A6C1A73-1A7C1A7F1B00-1B031B341B36-1B3A1B3C1B421B6B-1B731B801B811BA2-1BA51BA81BA91C2C-1C331C361C371CD0-1CD21CD4-1CE01CE2-1CE81CED1DC0-1DE61DFD-1DFF20D0-20DC20E120E5-20F02CEF-2CF12DE0-2DFF302A-302F3099309AA66FA67CA67DA6F0A6F1A802A806A80BA825A826A8C4A8E0-A8F1A926-A92DA947-A951A980-A982A9B3A9B6-A9B9A9BCAA29-AA2EAA31AA32AA35AA36AA43AA4CAAB0AAB2-AAB4AAB7AAB8AABEAABFAAC1ABE5ABE8ABEDFB1EFE00-FE0FFE20-FE26", |
| 21963 |
Mc: "0903093E-09400949-094C094E0982098309BE-09C009C709C809CB09CC09D70A030A3E-0A400A830ABE-0AC00AC90ACB0ACC0B020B030B3E0B400B470B480B4B0B4C0B570BBE0BBF0BC10BC20BC6-0BC80BCA-0BCC0BD70C01-0C030C41-0C440C820C830CBE0CC0-0CC40CC70CC80CCA0CCB0CD50CD60D020D030D3E-0D400D46-0D480D4A-0D4C0D570D820D830DCF-0DD10DD8-0DDF0DF20DF30F3E0F3F0F7F102B102C10311038103B103C105610571062-10641067-106D108310841087-108C108F109A-109C17B617BE-17C517C717C81923-19261929-192B193019311933-193819B0-19C019C819C91A19-1A1B1A551A571A611A631A641A6D-1A721B041B351B3B1B3D-1B411B431B441B821BA11BA61BA71BAA1C24-1C2B1C341C351CE11CF2A823A824A827A880A881A8B4-A8C3A952A953A983A9B4A9B5A9BAA9BBA9BD-A9C0AA2FAA30AA33AA34AA4DAA7BABE3ABE4ABE6ABE7ABE9ABEAABEC", |
| 21964 |
Me: "0488048906DE20DD-20E020E2-20E4A670-A672", |
| 21965 |
N: "0030-003900B200B300B900BC-00BE0660-066906F0-06F907C0-07C90966-096F09E6-09EF09F4-09F90A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BF20C66-0C6F0C78-0C7E0CE6-0CEF0D66-0D750E50-0E590ED0-0ED90F20-0F331040-10491090-10991369-137C16EE-16F017E0-17E917F0-17F91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C5920702074-20792080-20892150-21822185-21892460-249B24EA-24FF2776-27932CFD30073021-30293038-303A3192-31953220-32293251-325F3280-328932B1-32BFA620-A629A6E6-A6EFA830-A835A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19", |
| 21966 |
Nd: "0030-00390660-066906F0-06F907C0-07C90966-096F09E6-09EF0A66-0A6F0AE6-0AEF0B66-0B6F0BE6-0BEF0C66-0C6F0CE6-0CEF0D66-0D6F0E50-0E590ED0-0ED90F20-0F291040-10491090-109917E0-17E91810-18191946-194F19D0-19DA1A80-1A891A90-1A991B50-1B591BB0-1BB91C40-1C491C50-1C59A620-A629A8D0-A8D9A900-A909A9D0-A9D9AA50-AA59ABF0-ABF9FF10-FF19", |
| 21967 |
Nl: "16EE-16F02160-21822185-218830073021-30293038-303AA6E6-A6EF", |
| 21968 |
No: "00B200B300B900BC-00BE09F4-09F90BF0-0BF20C78-0C7E0D70-0D750F2A-0F331369-137C17F0-17F920702074-20792080-20892150-215F21892460-249B24EA-24FF2776-27932CFD3192-31953220-32293251-325F3280-328932B1-32BFA830-A835", |
| 21969 |
P: "0021-00230025-002A002C-002F003A003B003F0040005B-005D005F007B007D00A100AB00B700BB00BF037E0387055A-055F0589058A05BE05C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F3A-0F3D0F850FD0-0FD4104A-104F10FB1361-13681400166D166E169B169C16EB-16ED1735173617D4-17D617D8-17DA1800-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD32010-20272030-20432045-20512053-205E207D207E208D208E2329232A2768-277527C527C627E6-27EF2983-299829D8-29DB29FC29FD2CF9-2CFC2CFE2CFF2E00-2E2E2E302E313001-30033008-30113014-301F3030303D30A030FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFD3EFD3FFE10-FE19FE30-FE52FE54-FE61FE63FE68FE6AFE6BFF01-FF03FF05-FF0AFF0C-FF0FFF1AFF1BFF1FFF20FF3B-FF3DFF3FFF5BFF5DFF5F-FF65", |
| 21970 |
Pd: "002D058A05BE140018062010-20152E172E1A301C303030A0FE31FE32FE58FE63FF0D", |
| 21971 |
Ps: "0028005B007B0F3A0F3C169B201A201E2045207D208D23292768276A276C276E27702772277427C527E627E827EA27EC27EE2983298529872989298B298D298F299129932995299729D829DA29FC2E222E242E262E283008300A300C300E3010301430163018301A301DFD3EFE17FE35FE37FE39FE3BFE3DFE3FFE41FE43FE47FE59FE5BFE5DFF08FF3BFF5BFF5FFF62", |
| 21972 |
Pe: "0029005D007D0F3B0F3D169C2046207E208E232A2769276B276D276F27712773277527C627E727E927EB27ED27EF298429862988298A298C298E2990299229942996299829D929DB29FD2E232E252E272E293009300B300D300F3011301530173019301B301E301FFD3FFE18FE36FE38FE3AFE3CFE3EFE40FE42FE44FE48FE5AFE5CFE5EFF09FF3DFF5DFF60FF63", |
| 21973 |
Pi: "00AB2018201B201C201F20392E022E042E092E0C2E1C2E20", |
| 21974 |
Pf: "00BB2019201D203A2E032E052E0A2E0D2E1D2E21", |
| 21975 |
Pc: "005F203F20402054FE33FE34FE4D-FE4FFF3F", |
| 21976 |
Po: "0021-00230025-0027002A002C002E002F003A003B003F0040005C00A100B700BF037E0387055A-055F058905C005C305C605F305F40609060A060C060D061B061E061F066A-066D06D40700-070D07F7-07F90830-083E0964096509700DF40E4F0E5A0E5B0F04-0F120F850FD0-0FD4104A-104F10FB1361-1368166D166E16EB-16ED1735173617D4-17D617D8-17DA1800-18051807-180A1944194519DE19DF1A1E1A1F1AA0-1AA61AA8-1AAD1B5A-1B601C3B-1C3F1C7E1C7F1CD3201620172020-20272030-2038203B-203E2041-20432047-205120532055-205E2CF9-2CFC2CFE2CFF2E002E012E06-2E082E0B2E0E-2E162E182E192E1B2E1E2E1F2E2A-2E2E2E302E313001-3003303D30FBA4FEA4FFA60D-A60FA673A67EA6F2-A6F7A874-A877A8CEA8CFA8F8-A8FAA92EA92FA95FA9C1-A9CDA9DEA9DFAA5C-AA5FAADEAADFABEBFE10-FE16FE19FE30FE45FE46FE49-FE4CFE50-FE52FE54-FE57FE5F-FE61FE68FE6AFE6BFF01-FF03FF05-FF07FF0AFF0CFF0EFF0FFF1AFF1BFF1FFF20FF3CFF61FF64FF65", |
| 21977 |
S: "0024002B003C-003E005E0060007C007E00A2-00A900AC00AE-00B100B400B600B800D700F702C2-02C502D2-02DF02E5-02EB02ED02EF-02FF03750384038503F604820606-0608060B060E060F06E906FD06FE07F609F209F309FA09FB0AF10B700BF3-0BFA0C7F0CF10CF20D790E3F0F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-139917DB194019E0-19FF1B61-1B6A1B74-1B7C1FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE20442052207A-207C208A-208C20A0-20B8210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B2140-2144214A-214D214F2190-2328232B-23E82400-24262440-244A249C-24E92500-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE27C0-27C427C7-27CA27CC27D0-27E527F0-29822999-29D729DC-29FB29FE-2B4C2B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F309B309C319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A700-A716A720A721A789A78AA828-A82BA836-A839AA77-AA79FB29FDFCFDFDFE62FE64-FE66FE69FF04FF0BFF1C-FF1EFF3EFF40FF5CFF5EFFE0-FFE6FFE8-FFEEFFFCFFFD", |
| 21978 |
Sm: "002B003C-003E007C007E00AC00B100D700F703F60606-060820442052207A-207C208A-208C2140-2144214B2190-2194219A219B21A021A321A621AE21CE21CF21D221D421F4-22FF2308-230B23202321237C239B-23B323DC-23E125B725C125F8-25FF266F27C0-27C427C7-27CA27CC27D0-27E527F0-27FF2900-29822999-29D729DC-29FB29FE-2AFF2B30-2B442B47-2B4CFB29FE62FE64-FE66FF0BFF1C-FF1EFF5CFF5EFFE2FFE9-FFEC", |
| 21979 |
Sc: "002400A2-00A5060B09F209F309FB0AF10BF90E3F17DB20A0-20B8A838FDFCFE69FF04FFE0FFE1FFE5FFE6", |
| 21980 |
Sk: "005E006000A800AF00B400B802C2-02C502D2-02DF02E5-02EB02ED02EF-02FF0375038403851FBD1FBF-1FC11FCD-1FCF1FDD-1FDF1FED-1FEF1FFD1FFE309B309CA700-A716A720A721A789A78AFF3EFF40FFE3", |
| 21981 |
So: "00A600A700A900AE00B000B60482060E060F06E906FD06FE07F609FA0B700BF3-0BF80BFA0C7F0CF10CF20D790F01-0F030F13-0F170F1A-0F1F0F340F360F380FBE-0FC50FC7-0FCC0FCE0FCF0FD5-0FD8109E109F13601390-1399194019E0-19FF1B61-1B6A1B74-1B7C210021012103-21062108210921142116-2118211E-2123212521272129212E213A213B214A214C214D214F2195-2199219C-219F21A121A221A421A521A7-21AD21AF-21CD21D021D121D321D5-21F32300-2307230C-231F2322-2328232B-237B237D-239A23B4-23DB23E2-23E82400-24262440-244A249C-24E92500-25B625B8-25C025C2-25F72600-266E2670-26CD26CF-26E126E326E8-26FF2701-27042706-2709270C-27272729-274B274D274F-27522756-275E2761-276727942798-27AF27B1-27BE2800-28FF2B00-2B2F2B452B462B50-2B592CE5-2CEA2E80-2E992E9B-2EF32F00-2FD52FF0-2FFB300430123013302030363037303E303F319031913196-319F31C0-31E33200-321E322A-32503260-327F328A-32B032C0-32FE3300-33FF4DC0-4DFFA490-A4C6A828-A82BA836A837A839AA77-AA79FDFDFFE4FFE8FFEDFFEEFFFCFFFD", |
| 21982 |
Z: "002000A01680180E2000-200A20282029202F205F3000", |
| 21983 |
Zs: "002000A01680180E2000-200A202F205F3000", |
| 21984 |
Zl: "2028", |
| 21985 |
Zp: "2029", |
| 21986 |
C: "0000-001F007F-009F00AD03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-0605061C061D0620065F06DD070E070F074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17B417B517DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF200B-200F202A-202E2060-206F20722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-F8FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFD-FF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFFBFFFEFFFF", |
| 21987 |
Cc: "0000-001F007F-009F", |
| 21988 |
Cf: "00AD0600-060306DD070F17B417B5200B-200F202A-202E2060-2064206A-206FFEFFFFF9-FFFB", |
| 21989 |
Co: "E000-F8FF", |
| 21990 |
Cs: "D800-DFFF", |
| 21991 |
Cn: "03780379037F-0383038B038D03A20526-05300557055805600588058B-059005C8-05CF05EB-05EF05F5-05FF06040605061C061D0620065F070E074B074C07B2-07BF07FB-07FF082E082F083F-08FF093A093B094F095609570973-097809800984098D098E0991099209A909B109B3-09B509BA09BB09C509C609C909CA09CF-09D609D8-09DB09DE09E409E509FC-0A000A040A0B-0A0E0A110A120A290A310A340A370A3A0A3B0A3D0A43-0A460A490A4A0A4E-0A500A52-0A580A5D0A5F-0A650A76-0A800A840A8E0A920AA90AB10AB40ABA0ABB0AC60ACA0ACE0ACF0AD1-0ADF0AE40AE50AF00AF2-0B000B040B0D0B0E0B110B120B290B310B340B3A0B3B0B450B460B490B4A0B4E-0B550B58-0B5B0B5E0B640B650B72-0B810B840B8B-0B8D0B910B96-0B980B9B0B9D0BA0-0BA20BA5-0BA70BAB-0BAD0BBA-0BBD0BC3-0BC50BC90BCE0BCF0BD1-0BD60BD8-0BE50BFB-0C000C040C0D0C110C290C340C3A-0C3C0C450C490C4E-0C540C570C5A-0C5F0C640C650C70-0C770C800C810C840C8D0C910CA90CB40CBA0CBB0CC50CC90CCE-0CD40CD7-0CDD0CDF0CE40CE50CF00CF3-0D010D040D0D0D110D290D3A-0D3C0D450D490D4E-0D560D58-0D5F0D640D650D76-0D780D800D810D840D97-0D990DB20DBC0DBE0DBF0DC7-0DC90DCB-0DCE0DD50DD70DE0-0DF10DF5-0E000E3B-0E3E0E5C-0E800E830E850E860E890E8B0E8C0E8E-0E930E980EA00EA40EA60EA80EA90EAC0EBA0EBE0EBF0EC50EC70ECE0ECF0EDA0EDB0EDE-0EFF0F480F6D-0F700F8C-0F8F0F980FBD0FCD0FD9-0FFF10C6-10CF10FD-10FF1249124E124F12571259125E125F1289128E128F12B112B612B712BF12C112C612C712D7131113161317135B-135E137D-137F139A-139F13F5-13FF169D-169F16F1-16FF170D1715-171F1737-173F1754-175F176D17711774-177F17DE17DF17EA-17EF17FA-17FF180F181A-181F1878-187F18AB-18AF18F6-18FF191D-191F192C-192F193C-193F1941-1943196E196F1975-197F19AC-19AF19CA-19CF19DB-19DD1A1C1A1D1A5F1A7D1A7E1A8A-1A8F1A9A-1A9F1AAE-1AFF1B4C-1B4F1B7D-1B7F1BAB-1BAD1BBA-1BFF1C38-1C3A1C4A-1C4C1C80-1CCF1CF3-1CFF1DE7-1DFC1F161F171F1E1F1F1F461F471F4E1F4F1F581F5A1F5C1F5E1F7E1F7F1FB51FC51FD41FD51FDC1FF01FF11FF51FFF2065-206920722073208F2095-209F20B9-20CF20F1-20FF218A-218F23E9-23FF2427-243F244B-245F26CE26E226E4-26E727002705270A270B2728274C274E2753-2755275F27602795-279727B027BF27CB27CD-27CF2B4D-2B4F2B5A-2BFF2C2F2C5F2CF2-2CF82D26-2D2F2D66-2D6E2D70-2D7F2D97-2D9F2DA72DAF2DB72DBF2DC72DCF2DD72DDF2E32-2E7F2E9A2EF4-2EFF2FD6-2FEF2FFC-2FFF3040309730983100-3104312E-3130318F31B8-31BF31E4-31EF321F32FF4DB6-4DBF9FCC-9FFFA48D-A48FA4C7-A4CFA62C-A63FA660A661A674-A67BA698-A69FA6F8-A6FFA78D-A7FAA82C-A82FA83A-A83FA878-A87FA8C5-A8CDA8DA-A8DFA8FC-A8FFA954-A95EA97D-A97FA9CEA9DA-A9DDA9E0-A9FFAA37-AA3FAA4EAA4FAA5AAA5BAA7C-AA7FAAC3-AADAAAE0-ABBFABEEABEFABFA-ABFFD7A4-D7AFD7C7-D7CAD7FC-D7FFFA2EFA2FFA6EFA6FFADA-FAFFFB07-FB12FB18-FB1CFB37FB3DFB3FFB42FB45FBB2-FBD2FD40-FD4FFD90FD91FDC8-FDEFFDFEFDFFFE1A-FE1FFE27-FE2FFE53FE67FE6C-FE6FFE75FEFDFEFEFF00FFBF-FFC1FFC8FFC9FFD0FFD1FFD8FFD9FFDD-FFDFFFE7FFEF-FFF8FFFEFFFF" |
| 21992 |
}); |
| 21993 |
|
| 21994 |
function addUnicodePackage (pack) { |
| 21995 |
var codePoint = /\w{4}/g; |
| 21996 |
for (var name in pack) |
| 21997 |
exports.packages[name] = pack[name].replace(codePoint, "\\u$&"); |
| 21998 |
} |
| 21999 |
|
| 22000 |
}); |
| 22001 |
|
| 22002 |
ace.define("ace/token_iterator",["require","exports","module"], function(acequire, exports, module) { |
| 22003 |
"use strict"; |
| 22004 |
var TokenIterator = function(session, initialRow, initialColumn) { |
| 22005 |
this.$session = session; |
| 22006 |
this.$row = initialRow; |
| 22007 |
this.$rowTokens = session.getTokens(initialRow); |
| 22008 |
|
| 22009 |
var token = session.getTokenAt(initialRow, initialColumn); |
| 22010 |
this.$tokenIndex = token ? token.index : -1; |
| 22011 |
}; |
| 22012 |
|
| 22013 |
(function() { |
| 22014 |
this.stepBackward = function() { |
| 22015 |
this.$tokenIndex -= 1; |
| 22016 |
|
| 22017 |
while (this.$tokenIndex < 0) { |
| 22018 |
this.$row -= 1; |
| 22019 |
if (this.$row < 0) { |
| 22020 |
this.$row = 0; |
| 22021 |
return null; |
| 22022 |
} |
| 22023 |
|
| 22024 |
this.$rowTokens = this.$session.getTokens(this.$row); |
| 22025 |
this.$tokenIndex = this.$rowTokens.length - 1; |
| 22026 |
} |
| 22027 |
|
| 22028 |
return this.$rowTokens[this.$tokenIndex]; |
| 22029 |
}; |
| 22030 |
this.stepForward = function() { |
| 22031 |
this.$tokenIndex += 1; |
| 22032 |
var rowCount; |
| 22033 |
while (this.$tokenIndex >= this.$rowTokens.length) { |
| 22034 |
this.$row += 1; |
| 22035 |
if (!rowCount) |
| 22036 |
rowCount = this.$session.getLength(); |
| 22037 |
if (this.$row >= rowCount) { |
| 22038 |
this.$row = rowCount - 1; |
| 22039 |
return null; |
| 22040 |
} |
| 22041 |
|
| 22042 |
this.$rowTokens = this.$session.getTokens(this.$row); |
| 22043 |
this.$tokenIndex = 0; |
| 22044 |
} |
| 22045 |
|
| 22046 |
return this.$rowTokens[this.$tokenIndex]; |
| 22047 |
}; |
| 22048 |
this.getCurrentToken = function () { |
| 22049 |
return this.$rowTokens[this.$tokenIndex]; |
| 22050 |
}; |
| 22051 |
this.getCurrentTokenRow = function () { |
| 22052 |
return this.$row; |
| 22053 |
}; |
| 22054 |
this.getCurrentTokenColumn = function() { |
| 22055 |
var rowTokens = this.$rowTokens; |
| 22056 |
var tokenIndex = this.$tokenIndex; |
| 22057 |
var column = rowTokens[tokenIndex].start; |
| 22058 |
if (column !== undefined) |
| 22059 |
return column; |
| 22060 |
|
| 22061 |
column = 0; |
| 22062 |
while (tokenIndex > 0) { |
| 22063 |
tokenIndex -= 1; |
| 22064 |
column += rowTokens[tokenIndex].value.length; |
| 22065 |
} |
| 22066 |
|
| 22067 |
return column; |
| 22068 |
}; |
| 22069 |
this.getCurrentTokenPosition = function() { |
| 22070 |
return {row: this.$row, column: this.getCurrentTokenColumn()}; |
| 22071 |
}; |
| 22072 |
|
| 22073 |
}).call(TokenIterator.prototype); |
| 22074 |
|
| 22075 |
exports.TokenIterator = TokenIterator; |
| 22076 |
}); |
| 22077 |
|
| 22078 |
ace.define("ace/mode/text",["require","exports","module","ace/tokenizer","ace/mode/text_highlight_rules","ace/mode/behaviour","ace/unicode","ace/lib/lang","ace/token_iterator","ace/range"], function(acequire, exports, module) { |
| 22079 |
"use strict"; |
| 22080 |
|
| 22081 |
var Tokenizer = acequire("../tokenizer").Tokenizer; |
| 22082 |
var TextHighlightRules = acequire("./text_highlight_rules").TextHighlightRules; |
| 22083 |
var Behaviour = acequire("./behaviour").Behaviour; |
| 22084 |
var unicode = acequire("../unicode"); |
| 22085 |
var lang = acequire("../lib/lang"); |
| 22086 |
var TokenIterator = acequire("../token_iterator").TokenIterator; |
| 22087 |
var Range = acequire("../range").Range; |
| 22088 |
|
| 22089 |
var Mode = function() { |
| 22090 |
this.HighlightRules = TextHighlightRules; |
| 22091 |
this.$behaviour = new Behaviour(); |
| 22092 |
}; |
| 22093 |
|
| 22094 |
(function() { |
| 22095 |
|
| 22096 |
this.tokenRe = new RegExp("^[" |
| 22097 |
+ unicode.packages.L |
| 22098 |
+ unicode.packages.Mn + unicode.packages.Mc |
| 22099 |
+ unicode.packages.Nd |
| 22100 |
+ unicode.packages.Pc + "\\$_]+", "g" |
| 22101 |
); |
| 22102 |
|
| 22103 |
this.nonTokenRe = new RegExp("^(?:[^" |
| 22104 |
+ unicode.packages.L |
| 22105 |
+ unicode.packages.Mn + unicode.packages.Mc |
| 22106 |
+ unicode.packages.Nd |
| 22107 |
+ unicode.packages.Pc + "\\$_]|\\s])+", "g" |
| 22108 |
); |
| 22109 |
|
| 22110 |
this.getTokenizer = function() { |
| 22111 |
if (!this.$tokenizer) { |
| 22112 |
this.$highlightRules = this.$highlightRules || new this.HighlightRules(); |
| 22113 |
this.$tokenizer = new Tokenizer(this.$highlightRules.getRules()); |
| 22114 |
} |
| 22115 |
return this.$tokenizer; |
| 22116 |
}; |
| 22117 |
|
| 22118 |
this.lineCommentStart = ""; |
| 22119 |
this.blockComment = ""; |
| 22120 |
|
| 22121 |
this.toggleCommentLines = function(state, session, startRow, endRow) { |
| 22122 |
var doc = session.doc; |
| 22123 |
|
| 22124 |
var ignoreBlankLines = true; |
| 22125 |
var shouldRemove = true; |
| 22126 |
var minIndent = Infinity; |
| 22127 |
var tabSize = session.getTabSize(); |
| 22128 |
var insertAtTabStop = false; |
| 22129 |
|
| 22130 |
if (!this.lineCommentStart) { |
| 22131 |
if (!this.blockComment) |
| 22132 |
return false; |
| 22133 |
var lineCommentStart = this.blockComment.start; |
| 22134 |
var lineCommentEnd = this.blockComment.end; |
| 22135 |
var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")"); |
| 22136 |
var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$"); |
| 22137 |
|
| 22138 |
var comment = function(line, i) { |
| 22139 |
if (testRemove(line, i)) |
| 22140 |
return; |
| 22141 |
if (!ignoreBlankLines || /\S/.test(line)) { |
| 22142 |
doc.insertInLine({row: i, column: line.length}, lineCommentEnd); |
| 22143 |
doc.insertInLine({row: i, column: minIndent}, lineCommentStart); |
| 22144 |
} |
| 22145 |
}; |
| 22146 |
|
| 22147 |
var uncomment = function(line, i) { |
| 22148 |
var m; |
| 22149 |
if (m = line.match(regexpEnd)) |
| 22150 |
doc.removeInLine(i, line.length - m[0].length, line.length); |
| 22151 |
if (m = line.match(regexpStart)) |
| 22152 |
doc.removeInLine(i, m[1].length, m[0].length); |
| 22153 |
}; |
| 22154 |
|
| 22155 |
var testRemove = function(line, row) { |
| 22156 |
if (regexpStart.test(line)) |
| 22157 |
return true; |
| 22158 |
var tokens = session.getTokens(row); |
| 22159 |
for (var i = 0; i < tokens.length; i++) { |
| 22160 |
if (tokens[i].type === "comment") |
| 22161 |
return true; |
| 22162 |
} |
| 22163 |
}; |
| 22164 |
} else { |
| 22165 |
if (Array.isArray(this.lineCommentStart)) { |
| 22166 |
var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|"); |
| 22167 |
var lineCommentStart = this.lineCommentStart[0]; |
| 22168 |
} else { |
| 22169 |
var regexpStart = lang.escapeRegExp(this.lineCommentStart); |
| 22170 |
var lineCommentStart = this.lineCommentStart; |
| 22171 |
} |
| 22172 |
regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?"); |
| 22173 |
|
| 22174 |
insertAtTabStop = session.getUseSoftTabs(); |
| 22175 |
|
| 22176 |
var uncomment = function(line, i) { |
| 22177 |
var m = line.match(regexpStart); |
| 22178 |
if (!m) return; |
| 22179 |
var start = m[1].length, end = m[0].length; |
| 22180 |
if (!shouldInsertSpace(line, start, end) && m[0][end - 1] == " ") |
| 22181 |
end--; |
| 22182 |
doc.removeInLine(i, start, end); |
| 22183 |
}; |
| 22184 |
var commentWithSpace = lineCommentStart + " "; |
| 22185 |
var comment = function(line, i) { |
| 22186 |
if (!ignoreBlankLines || /\S/.test(line)) { |
| 22187 |
if (shouldInsertSpace(line, minIndent, minIndent)) |
| 22188 |
doc.insertInLine({row: i, column: minIndent}, commentWithSpace); |
| 22189 |
else |
| 22190 |
doc.insertInLine({row: i, column: minIndent}, lineCommentStart); |
| 22191 |
} |
| 22192 |
}; |
| 22193 |
var testRemove = function(line, i) { |
| 22194 |
return regexpStart.test(line); |
| 22195 |
}; |
| 22196 |
|
| 22197 |
var shouldInsertSpace = function(line, before, after) { |
| 22198 |
var spaces = 0; |
| 22199 |
while (before-- && line.charAt(before) == " ") |
| 22200 |
spaces++; |
| 22201 |
if (spaces % tabSize != 0) |
| 22202 |
return false; |
| 22203 |
var spaces = 0; |
| 22204 |
while (line.charAt(after++) == " ") |
| 22205 |
spaces++; |
| 22206 |
if (tabSize > 2) |
| 22207 |
return spaces % tabSize != tabSize - 1; |
| 22208 |
else |
| 22209 |
return spaces % tabSize == 0; |
| 22210 |
return true; |
| 22211 |
}; |
| 22212 |
} |
| 22213 |
|
| 22214 |
function iter(fun) { |
| 22215 |
for (var i = startRow; i <= endRow; i++) |
| 22216 |
fun(doc.getLine(i), i); |
| 22217 |
} |
| 22218 |
|
| 22219 |
|
| 22220 |
var minEmptyLength = Infinity; |
| 22221 |
iter(function(line, i) { |
| 22222 |
var indent = line.search(/\S/); |
| 22223 |
if (indent !== -1) { |
| 22224 |
if (indent < minIndent) |
| 22225 |
minIndent = indent; |
| 22226 |
if (shouldRemove && !testRemove(line, i)) |
| 22227 |
shouldRemove = false; |
| 22228 |
} else if (minEmptyLength > line.length) { |
| 22229 |
minEmptyLength = line.length; |
| 22230 |
} |
| 22231 |
}); |
| 22232 |
|
| 22233 |
if (minIndent == Infinity) { |
| 22234 |
minIndent = minEmptyLength; |
| 22235 |
ignoreBlankLines = false; |
| 22236 |
shouldRemove = false; |
| 22237 |
} |
| 22238 |
|
| 22239 |
if (insertAtTabStop && minIndent % tabSize != 0) |
| 22240 |
minIndent = Math.floor(minIndent / tabSize) * tabSize; |
| 22241 |
|
| 22242 |
iter(shouldRemove ? uncomment : comment); |
| 22243 |
}; |
| 22244 |
|
| 22245 |
this.toggleBlockComment = function(state, session, range, cursor) { |
| 22246 |
var comment = this.blockComment; |
| 22247 |
if (!comment) |
| 22248 |
return; |
| 22249 |
if (!comment.start && comment[0]) |
| 22250 |
comment = comment[0]; |
| 22251 |
|
| 22252 |
var iterator = new TokenIterator(session, cursor.row, cursor.column); |
| 22253 |
var token = iterator.getCurrentToken(); |
| 22254 |
|
| 22255 |
var sel = session.selection; |
| 22256 |
var initialRange = session.selection.toOrientedRange(); |
| 22257 |
var startRow, colDiff; |
| 22258 |
|
| 22259 |
if (token && /comment/.test(token.type)) { |
| 22260 |
var startRange, endRange; |
| 22261 |
while (token && /comment/.test(token.type)) { |
| 22262 |
var i = token.value.indexOf(comment.start); |
| 22263 |
if (i != -1) { |
| 22264 |
var row = iterator.getCurrentTokenRow(); |
| 22265 |
var column = iterator.getCurrentTokenColumn() + i; |
| 22266 |
startRange = new Range(row, column, row, column + comment.start.length); |
| 22267 |
break; |
| 22268 |
} |
| 22269 |
token = iterator.stepBackward(); |
| 22270 |
} |
| 22271 |
|
| 22272 |
var iterator = new TokenIterator(session, cursor.row, cursor.column); |
| 22273 |
var token = iterator.getCurrentToken(); |
| 22274 |
while (token && /comment/.test(token.type)) { |
| 22275 |
var i = token.value.indexOf(comment.end); |
| 22276 |
if (i != -1) { |
| 22277 |
var row = iterator.getCurrentTokenRow(); |
| 22278 |
var column = iterator.getCurrentTokenColumn() + i; |
| 22279 |
endRange = new Range(row, column, row, column + comment.end.length); |
| 22280 |
break; |
| 22281 |
} |
| 22282 |
token = iterator.stepForward(); |
| 22283 |
} |
| 22284 |
if (endRange) |
| 22285 |
session.remove(endRange); |
| 22286 |
if (startRange) { |
| 22287 |
session.remove(startRange); |
| 22288 |
startRow = startRange.start.row; |
| 22289 |
colDiff = -comment.start.length; |
| 22290 |
} |
| 22291 |
} else { |
| 22292 |
colDiff = comment.start.length; |
| 22293 |
startRow = range.start.row; |
| 22294 |
session.insert(range.end, comment.end); |
| 22295 |
session.insert(range.start, comment.start); |
| 22296 |
} |
| 22297 |
if (initialRange.start.row == startRow) |
| 22298 |
initialRange.start.column += colDiff; |
| 22299 |
if (initialRange.end.row == startRow) |
| 22300 |
initialRange.end.column += colDiff; |
| 22301 |
session.selection.fromOrientedRange(initialRange); |
| 22302 |
}; |
| 22303 |
|
| 22304 |
this.getNextLineIndent = function(state, line, tab) { |
| 22305 |
return this.$getIndent(line); |
| 22306 |
}; |
| 22307 |
|
| 22308 |
this.checkOutdent = function(state, line, input) { |
| 22309 |
return false; |
| 22310 |
}; |
| 22311 |
|
| 22312 |
this.autoOutdent = function(state, doc, row) { |
| 22313 |
}; |
| 22314 |
|
| 22315 |
this.$getIndent = function(line) { |
| 22316 |
return line.match(/^\s*/)[0]; |
| 22317 |
}; |
| 22318 |
|
| 22319 |
this.createWorker = function(session) { |
| 22320 |
return null; |
| 22321 |
}; |
| 22322 |
|
| 22323 |
this.createModeDelegates = function (mapping) { |
| 22324 |
this.$embeds = []; |
| 22325 |
this.$modes = {}; |
| 22326 |
for (var i in mapping) { |
| 22327 |
if (mapping[i]) { |
| 22328 |
this.$embeds.push(i); |
| 22329 |
this.$modes[i] = new mapping[i](); |
| 22330 |
} |
| 22331 |
} |
| 22332 |
|
| 22333 |
var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent", |
| 22334 |
"checkOutdent", "autoOutdent", "transformAction", "getCompletions"]; |
| 22335 |
|
| 22336 |
for (var i = 0; i < delegations.length; i++) { |
| 22337 |
(function(scope) { |
| 22338 |
var functionName = delegations[i]; |
| 22339 |
var defaultHandler = scope[functionName]; |
| 22340 |
scope[delegations[i]] = function() { |
| 22341 |
return this.$delegator(functionName, arguments, defaultHandler); |
| 22342 |
}; |
| 22343 |
}(this)); |
| 22344 |
} |
| 22345 |
}; |
| 22346 |
|
| 22347 |
this.$delegator = function(method, args, defaultHandler) { |
| 22348 |
var state = args[0]; |
| 22349 |
if (typeof state != "string") |
| 22350 |
state = state[0]; |
| 22351 |
for (var i = 0; i < this.$embeds.length; i++) { |
| 22352 |
if (!this.$modes[this.$embeds[i]]) continue; |
| 22353 |
|
| 22354 |
var split = state.split(this.$embeds[i]); |
| 22355 |
if (!split[0] && split[1]) { |
| 22356 |
args[0] = split[1]; |
| 22357 |
var mode = this.$modes[this.$embeds[i]]; |
| 22358 |
return mode[method].apply(mode, args); |
| 22359 |
} |
| 22360 |
} |
| 22361 |
var ret = defaultHandler.apply(this, args); |
| 22362 |
return defaultHandler ? ret : undefined; |
| 22363 |
}; |
| 22364 |
|
| 22365 |
this.transformAction = function(state, action, editor, session, param) { |
| 22366 |
if (this.$behaviour) { |
| 22367 |
var behaviours = this.$behaviour.getBehaviours(); |
| 22368 |
for (var key in behaviours) { |
| 22369 |
if (behaviours[key][action]) { |
| 22370 |
var ret = behaviours[key][action].apply(this, arguments); |
| 22371 |
if (ret) { |
| 22372 |
return ret; |
| 22373 |
} |
| 22374 |
} |
| 22375 |
} |
| 22376 |
} |
| 22377 |
}; |
| 22378 |
|
| 22379 |
this.getKeywords = function(append) { |
| 22380 |
if (!this.completionKeywords) { |
| 22381 |
var rules = this.$tokenizer.rules; |
| 22382 |
var completionKeywords = []; |
| 22383 |
for (var rule in rules) { |
| 22384 |
var ruleItr = rules[rule]; |
| 22385 |
for (var r = 0, l = ruleItr.length; r < l; r++) { |
| 22386 |
if (typeof ruleItr[r].token === "string") { |
| 22387 |
if (/keyword|support|storage/.test(ruleItr[r].token)) |
| 22388 |
completionKeywords.push(ruleItr[r].regex); |
| 22389 |
} |
| 22390 |
else if (typeof ruleItr[r].token === "object") { |
| 22391 |
for (var a = 0, aLength = ruleItr[r].token.length; a < aLength; a++) { |
| 22392 |
if (/keyword|support|storage/.test(ruleItr[r].token[a])) { |
| 22393 |
var rule = ruleItr[r].regex.match(/\(.+?\)/g)[a]; |
| 22394 |
completionKeywords.push(rule.substr(1, rule.length - 2)); |
| 22395 |
} |
| 22396 |
} |
| 22397 |
} |
| 22398 |
} |
| 22399 |
} |
| 22400 |
this.completionKeywords = completionKeywords; |
| 22401 |
} |
| 22402 |
if (!append) |
| 22403 |
return this.$keywordList; |
| 22404 |
return completionKeywords.concat(this.$keywordList || []); |
| 22405 |
}; |
| 22406 |
|
| 22407 |
this.$createKeywordList = function() { |
| 22408 |
if (!this.$highlightRules) |
| 22409 |
this.getTokenizer(); |
| 22410 |
return this.$keywordList = this.$highlightRules.$keywordList || []; |
| 22411 |
}; |
| 22412 |
|
| 22413 |
this.getCompletions = function(state, session, pos, prefix) { |
| 22414 |
var keywords = this.$keywordList || this.$createKeywordList(); |
| 22415 |
return keywords.map(function(word) { |
| 22416 |
return { |
| 22417 |
name: word, |
| 22418 |
value: word, |
| 22419 |
score: 0, |
| 22420 |
meta: "keyword" |
| 22421 |
}; |
| 22422 |
}); |
| 22423 |
}; |
| 22424 |
|
| 22425 |
this.$id = "ace/mode/text"; |
| 22426 |
}).call(Mode.prototype); |
| 22427 |
|
| 22428 |
exports.Mode = Mode; |
| 22429 |
}); |
| 22430 |
|
| 22431 |
ace.define("ace/apply_delta",["require","exports","module"], function(acequire, exports, module) { |
| 22432 |
"use strict"; |
| 22433 |
|
| 22434 |
function throwDeltaError(delta, errorText){ |
| 22435 |
console.log("Invalid Delta:", delta); |
| 22436 |
throw "Invalid Delta: " + errorText; |
| 22437 |
} |
| 22438 |
|
| 22439 |
function positionInDocument(docLines, position) { |
| 22440 |
return position.row >= 0 && position.row < docLines.length && |
| 22441 |
position.column >= 0 && position.column <= docLines[position.row].length; |
| 22442 |
} |
| 22443 |
|
| 22444 |
function validateDelta(docLines, delta) { |
| 22445 |
if (delta.action != "insert" && delta.action != "remove") |
| 22446 |
throwDeltaError(delta, "delta.action must be 'insert' or 'remove'"); |
| 22447 |
if (!(delta.lines instanceof Array)) |
| 22448 |
throwDeltaError(delta, "delta.lines must be an Array"); |
| 22449 |
if (!delta.start || !delta.end) |
| 22450 |
throwDeltaError(delta, "delta.start/end must be an present"); |
| 22451 |
var start = delta.start; |
| 22452 |
if (!positionInDocument(docLines, delta.start)) |
| 22453 |
throwDeltaError(delta, "delta.start must be contained in document"); |
| 22454 |
var end = delta.end; |
| 22455 |
if (delta.action == "remove" && !positionInDocument(docLines, end)) |
| 22456 |
throwDeltaError(delta, "delta.end must contained in document for 'remove' actions"); |
| 22457 |
var numRangeRows = end.row - start.row; |
| 22458 |
var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0)); |
| 22459 |
if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars) |
| 22460 |
throwDeltaError(delta, "delta.range must match delta lines"); |
| 22461 |
} |
| 22462 |
|
| 22463 |
exports.applyDelta = function(docLines, delta, doNotValidate) { |
| 22464 |
|
| 22465 |
var row = delta.start.row; |
| 22466 |
var startColumn = delta.start.column; |
| 22467 |
var line = docLines[row] || ""; |
| 22468 |
switch (delta.action) { |
| 22469 |
case "insert": |
| 22470 |
var lines = delta.lines; |
| 22471 |
if (lines.length === 1) { |
| 22472 |
docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn); |
| 22473 |
} else { |
| 22474 |
var args = [row, 1].concat(delta.lines); |
| 22475 |
docLines.splice.apply(docLines, args); |
| 22476 |
docLines[row] = line.substring(0, startColumn) + docLines[row]; |
| 22477 |
docLines[row + delta.lines.length - 1] += line.substring(startColumn); |
| 22478 |
} |
| 22479 |
break; |
| 22480 |
case "remove": |
| 22481 |
var endColumn = delta.end.column; |
| 22482 |
var endRow = delta.end.row; |
| 22483 |
if (row === endRow) { |
| 22484 |
docLines[row] = line.substring(0, startColumn) + line.substring(endColumn); |
| 22485 |
} else { |
| 22486 |
docLines.splice( |
| 22487 |
row, endRow - row + 1, |
| 22488 |
line.substring(0, startColumn) + docLines[endRow].substring(endColumn) |
| 22489 |
); |
| 22490 |
} |
| 22491 |
break; |
| 22492 |
} |
| 22493 |
} |
| 22494 |
}); |
| 22495 |
|
| 22496 |
ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(acequire, exports, module) { |
| 22497 |
"use strict"; |
| 22498 |
|
| 22499 |
var oop = acequire("./lib/oop"); |
| 22500 |
var EventEmitter = acequire("./lib/event_emitter").EventEmitter; |
| 22501 |
|
| 22502 |
var Anchor = exports.Anchor = function(doc, row, column) { |
| 22503 |
this.$onChange = this.onChange.bind(this); |
| 22504 |
this.attach(doc); |
| 22505 |
|
| 22506 |
if (typeof column == "undefined") |
| 22507 |
this.setPosition(row.row, row.column); |
| 22508 |
else |
| 22509 |
this.setPosition(row, column); |
| 22510 |
}; |
| 22511 |
|
| 22512 |
(function() { |
| 22513 |
|
| 22514 |
oop.implement(this, EventEmitter); |
| 22515 |
this.getPosition = function() { |
| 22516 |
return this.$clipPositionToDocument(this.row, this.column); |
| 22517 |
}; |
| 22518 |
this.getDocument = function() { |
| 22519 |
return this.document; |
| 22520 |
}; |
| 22521 |
this.$insertRight = false; |
| 22522 |
this.onChange = function(delta) { |
| 22523 |
if (delta.start.row == delta.end.row && delta.start.row != this.row) |
| 22524 |
return; |
| 22525 |
|
| 22526 |
if (delta.start.row > this.row) |
| 22527 |
return; |
| 22528 |
|
| 22529 |
var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight); |
| 22530 |
this.setPosition(point.row, point.column, true); |
| 22531 |
}; |
| 22532 |
|
| 22533 |
function $pointsInOrder(point1, point2, equalPointsInOrder) { |
| 22534 |
var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column; |
| 22535 |
return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter); |
| 22536 |
} |
| 22537 |
|
| 22538 |
function $getTransformedPoint(delta, point, moveIfEqual) { |
| 22539 |
var deltaIsInsert = delta.action == "insert"; |
| 22540 |
var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row); |
| 22541 |
var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column); |
| 22542 |
var deltaStart = delta.start; |
| 22543 |
var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range. |
| 22544 |
if ($pointsInOrder(point, deltaStart, moveIfEqual)) { |
| 22545 |
return { |
| 22546 |
row: point.row, |
| 22547 |
column: point.column |
| 22548 |
}; |
| 22549 |
} |
| 22550 |
if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) { |
| 22551 |
return { |
| 22552 |
row: point.row + deltaRowShift, |
| 22553 |
column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0) |
| 22554 |
}; |
| 22555 |
} |
| 22556 |
|
| 22557 |
return { |
| 22558 |
row: deltaStart.row, |
| 22559 |
column: deltaStart.column |
| 22560 |
}; |
| 22561 |
} |
| 22562 |
this.setPosition = function(row, column, noClip) { |
| 22563 |
var pos; |
| 22564 |
if (noClip) { |
| 22565 |
pos = { |
| 22566 |
row: row, |
| 22567 |
column: column |
| 22568 |
}; |
| 22569 |
} else { |
| 22570 |
pos = this.$clipPositionToDocument(row, column); |
| 22571 |
} |
| 22572 |
|
| 22573 |
if (this.row == pos.row && this.column == pos.column) |
| 22574 |
return; |
| 22575 |
|
| 22576 |
var old = { |
| 22577 |
row: this.row, |
| 22578 |
column: this.column |
| 22579 |
}; |
| 22580 |
|
| 22581 |
this.row = pos.row; |
| 22582 |
this.column = pos.column; |
| 22583 |
this._signal("change", { |
| 22584 |
old: old, |
| 22585 |
value: pos |
| 22586 |
}); |
| 22587 |
}; |
| 22588 |
this.detach = function() { |
| 22589 |
this.document.removeEventListener("change", this.$onChange); |
| 22590 |
}; |
| 22591 |
this.attach = function(doc) { |
| 22592 |
this.document = doc || this.document; |
| 22593 |
this.document.on("change", this.$onChange); |
| 22594 |
}; |
| 22595 |
this.$clipPositionToDocument = function(row, column) { |
| 22596 |
var pos = {}; |
| 22597 |
|
| 22598 |
if (row >= this.document.getLength()) { |
| 22599 |
pos.row = Math.max(0, this.document.getLength() - 1); |
| 22600 |
pos.column = this.document.getLine(pos.row).length; |
| 22601 |
} |
| 22602 |
else if (row < 0) { |
| 22603 |
pos.row = 0; |
| 22604 |
pos.column = 0; |
| 22605 |
} |
| 22606 |
else { |
| 22607 |
pos.row = row; |
| 22608 |
pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column)); |
| 22609 |
} |
| 22610 |
|
| 22611 |
if (column < 0) |
| 22612 |
pos.column = 0; |
| 22613 |
|
| 22614 |
return pos; |
| 22615 |
}; |
| 22616 |
|
| 22617 |
}).call(Anchor.prototype); |
| 22618 |
|
| 22619 |
}); |
| 22620 |
|
| 22621 |
ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/apply_delta","ace/lib/event_emitter","ace/range","ace/anchor"], function(acequire, exports, module) { |
| 22622 |
"use strict"; |
| 22623 |
|
| 22624 |
var oop = acequire("./lib/oop"); |
| 22625 |
var applyDelta = acequire("./apply_delta").applyDelta; |
| 22626 |
var EventEmitter = acequire("./lib/event_emitter").EventEmitter; |
| 22627 |
var Range = acequire("./range").Range; |
| 22628 |
var Anchor = acequire("./anchor").Anchor; |
| 22629 |
|
| 22630 |
var Document = function(textOrLines) { |
| 22631 |
this.$lines = [""]; |
| 22632 |
if (textOrLines.length === 0) { |
| 22633 |
this.$lines = [""]; |
| 22634 |
} else if (Array.isArray(textOrLines)) { |
| 22635 |
this.insertMergedLines({row: 0, column: 0}, textOrLines); |
| 22636 |
} else { |
| 22637 |
this.insert({row: 0, column:0}, textOrLines); |
| 22638 |
} |
| 22639 |
}; |
| 22640 |
|
| 22641 |
(function() { |
| 22642 |
|
| 22643 |
oop.implement(this, EventEmitter); |
| 22644 |
this.setValue = function(text) { |
| 22645 |
var len = this.getLength() - 1; |
| 22646 |
this.remove(new Range(0, 0, len, this.getLine(len).length)); |
| 22647 |
this.insert({row: 0, column: 0}, text); |
| 22648 |
}; |
| 22649 |
this.getValue = function() { |
| 22650 |
return this.getAllLines().join(this.getNewLineCharacter()); |
| 22651 |
}; |
| 22652 |
this.createAnchor = function(row, column) { |
| 22653 |
return new Anchor(this, row, column); |
| 22654 |
}; |
| 22655 |
if ("aaa".split(/a/).length === 0) { |
| 22656 |
this.$split = function(text) { |
| 22657 |
return text.replace(/\r\n|\r/g, "\n").split("\n"); |
| 22658 |
}; |
| 22659 |
} else { |
| 22660 |
this.$split = function(text) { |
| 22661 |
return text.split(/\r\n|\r|\n/); |
| 22662 |
}; |
| 22663 |
} |
| 22664 |
|
| 22665 |
|
| 22666 |
this.$detectNewLine = function(text) { |
| 22667 |
var match = text.match(/^.*?(\r\n|\r|\n)/m); |
| 22668 |
this.$autoNewLine = match ? match[1] : "\n"; |
| 22669 |
this._signal("changeNewLineMode"); |
| 22670 |
}; |
| 22671 |
this.getNewLineCharacter = function() { |
| 22672 |
switch (this.$newLineMode) { |
| 22673 |
case "windows": |
| 22674 |
return "\r\n"; |
| 22675 |
case "unix": |
| 22676 |
return "\n"; |
| 22677 |
default: |
| 22678 |
return this.$autoNewLine || "\n"; |
| 22679 |
} |
| 22680 |
}; |
| 22681 |
|
| 22682 |
this.$autoNewLine = ""; |
| 22683 |
this.$newLineMode = "auto"; |
| 22684 |
this.setNewLineMode = function(newLineMode) { |
| 22685 |
if (this.$newLineMode === newLineMode) |
| 22686 |
return; |
| 22687 |
|
| 22688 |
this.$newLineMode = newLineMode; |
| 22689 |
this._signal("changeNewLineMode"); |
| 22690 |
}; |
| 22691 |
this.getNewLineMode = function() { |
| 22692 |
return this.$newLineMode; |
| 22693 |
}; |
| 22694 |
this.isNewLine = function(text) { |
| 22695 |
return (text == "\r\n" || text == "\r" || text == "\n"); |
| 22696 |
}; |
| 22697 |
this.getLine = function(row) { |
| 22698 |
return this.$lines[row] || ""; |
| 22699 |
}; |
| 22700 |
this.getLines = function(firstRow, lastRow) { |
| 22701 |
return this.$lines.slice(firstRow, lastRow + 1); |
| 22702 |
}; |
| 22703 |
this.getAllLines = function() { |
| 22704 |
return this.getLines(0, this.getLength()); |
| 22705 |
}; |
| 22706 |
this.getLength = function() { |
| 22707 |
return this.$lines.length; |
| 22708 |
}; |
| 22709 |
this.getTextRange = function(range) { |
| 22710 |
return this.getLinesForRange(range).join(this.getNewLineCharacter()); |
| 22711 |
}; |
| 22712 |
this.getLinesForRange = function(range) { |
| 22713 |
var lines; |
| 22714 |
if (range.start.row === range.end.row) { |
| 22715 |
lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)]; |
| 22716 |
} else { |
| 22717 |
lines = this.getLines(range.start.row, range.end.row); |
| 22718 |
lines[0] = (lines[0] || "").substring(range.start.column); |
| 22719 |
var l = lines.length - 1; |
| 22720 |
if (range.end.row - range.start.row == l) |
| 22721 |
lines[l] = lines[l].substring(0, range.end.column); |
| 22722 |
} |
| 22723 |
return lines; |
| 22724 |
}; |
| 22725 |
this.insertLines = function(row, lines) { |
| 22726 |
console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead."); |
| 22727 |
return this.insertFullLines(row, lines); |
| 22728 |
}; |
| 22729 |
this.removeLines = function(firstRow, lastRow) { |
| 22730 |
console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead."); |
| 22731 |
return this.removeFullLines(firstRow, lastRow); |
| 22732 |
}; |
| 22733 |
this.insertNewLine = function(position) { |
| 22734 |
console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, [\'\', \'\']) instead."); |
| 22735 |
return this.insertMergedLines(position, ["", ""]); |
| 22736 |
}; |
| 22737 |
this.insert = function(position, text) { |
| 22738 |
if (this.getLength() <= 1) |
| 22739 |
this.$detectNewLine(text); |
| 22740 |
|
| 22741 |
return this.insertMergedLines(position, this.$split(text)); |
| 22742 |
}; |
| 22743 |
this.insertInLine = function(position, text) { |
| 22744 |
var start = this.clippedPos(position.row, position.column); |
| 22745 |
var end = this.pos(position.row, position.column + text.length); |
| 22746 |
|
| 22747 |
this.applyDelta({ |
| 22748 |
start: start, |
| 22749 |
end: end, |
| 22750 |
action: "insert", |
| 22751 |
lines: [text] |
| 22752 |
}, true); |
| 22753 |
|
| 22754 |
return this.clonePos(end); |
| 22755 |
}; |
| 22756 |
|
| 22757 |
this.clippedPos = function(row, column) { |
| 22758 |
var length = this.getLength(); |
| 22759 |
if (row === undefined) { |
| 22760 |
row = length; |
| 22761 |
} else if (row < 0) { |
| 22762 |
row = 0; |
| 22763 |
} else if (row >= length) { |
| 22764 |
row = length - 1; |
| 22765 |
column = undefined; |
| 22766 |
} |
| 22767 |
var line = this.getLine(row); |
| 22768 |
if (column == undefined) |
| 22769 |
column = line.length; |
| 22770 |
column = Math.min(Math.max(column, 0), line.length); |
| 22771 |
return {row: row, column: column}; |
| 22772 |
}; |
| 22773 |
|
| 22774 |
this.clonePos = function(pos) { |
| 22775 |
return {row: pos.row, column: pos.column}; |
| 22776 |
}; |
| 22777 |
|
| 22778 |
this.pos = function(row, column) { |
| 22779 |
return {row: row, column: column}; |
| 22780 |
}; |
| 22781 |
|
| 22782 |
this.$clipPosition = function(position) { |
| 22783 |
var length = this.getLength(); |
| 22784 |
if (position.row >= length) { |
| 22785 |
position.row = Math.max(0, length - 1); |
| 22786 |
position.column = this.getLine(length - 1).length; |
| 22787 |
} else { |
| 22788 |
position.row = Math.max(0, position.row); |
| 22789 |
position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length); |
| 22790 |
} |
| 22791 |
return position; |
| 22792 |
}; |
| 22793 |
this.insertFullLines = function(row, lines) { |
| 22794 |
row = Math.min(Math.max(row, 0), this.getLength()); |
| 22795 |
var column = 0; |
| 22796 |
if (row < this.getLength()) { |
| 22797 |
lines = lines.concat([""]); |
| 22798 |
column = 0; |
| 22799 |
} else { |
| 22800 |
lines = [""].concat(lines); |
| 22801 |
row--; |
| 22802 |
column = this.$lines[row].length; |
| 22803 |
} |
| 22804 |
this.insertMergedLines({row: row, column: column}, lines); |
| 22805 |
}; |
| 22806 |
this.insertMergedLines = function(position, lines) { |
| 22807 |
var start = this.clippedPos(position.row, position.column); |
| 22808 |
var end = { |
| 22809 |
row: start.row + lines.length - 1, |
| 22810 |
column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length |
| 22811 |
}; |
| 22812 |
|
| 22813 |
this.applyDelta({ |
| 22814 |
start: start, |
| 22815 |
end: end, |
| 22816 |
action: "insert", |
| 22817 |
lines: lines |
| 22818 |
}); |
| 22819 |
|
| 22820 |
return this.clonePos(end); |
| 22821 |
}; |
| 22822 |
this.remove = function(range) { |
| 22823 |
var start = this.clippedPos(range.start.row, range.start.column); |
| 22824 |
var end = this.clippedPos(range.end.row, range.end.column); |
| 22825 |
this.applyDelta({ |
| 22826 |
start: start, |
| 22827 |
end: end, |
| 22828 |
action: "remove", |
| 22829 |
lines: this.getLinesForRange({start: start, end: end}) |
| 22830 |
}); |
| 22831 |
return this.clonePos(start); |
| 22832 |
}; |
| 22833 |
this.removeInLine = function(row, startColumn, endColumn) { |
| 22834 |
var start = this.clippedPos(row, startColumn); |
| 22835 |
var end = this.clippedPos(row, endColumn); |
| 22836 |
|
| 22837 |
this.applyDelta({ |
| 22838 |
start: start, |
| 22839 |
end: end, |
| 22840 |
action: "remove", |
| 22841 |
lines: this.getLinesForRange({start: start, end: end}) |
| 22842 |
}, true); |
| 22843 |
|
| 22844 |
return this.clonePos(start); |
| 22845 |
}; |
| 22846 |
this.removeFullLines = function(firstRow, lastRow) { |
| 22847 |
firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1); |
| 22848 |
lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1); |
| 22849 |
var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0; |
| 22850 |
var deleteLastNewLine = lastRow < this.getLength() - 1; |
| 22851 |
var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow ); |
| 22852 |
var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 ); |
| 22853 |
var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow ); |
| 22854 |
var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length ); |
| 22855 |
var range = new Range(startRow, startCol, endRow, endCol); |
| 22856 |
var deletedLines = this.$lines.slice(firstRow, lastRow + 1); |
| 22857 |
|
| 22858 |
this.applyDelta({ |
| 22859 |
start: range.start, |
| 22860 |
end: range.end, |
| 22861 |
action: "remove", |
| 22862 |
lines: this.getLinesForRange(range) |
| 22863 |
}); |
| 22864 |
return deletedLines; |
| 22865 |
}; |
| 22866 |
this.removeNewLine = function(row) { |
| 22867 |
if (row < this.getLength() - 1 && row >= 0) { |
| 22868 |
this.applyDelta({ |
| 22869 |
start: this.pos(row, this.getLine(row).length), |
| 22870 |
end: this.pos(row + 1, 0), |
| 22871 |
action: "remove", |
| 22872 |
lines: ["", ""] |
| 22873 |
}); |
| 22874 |
} |
| 22875 |
}; |
| 22876 |
this.replace = function(range, text) { |
| 22877 |
if (!(range instanceof Range)) |
| 22878 |
range = Range.fromPoints(range.start, range.end); |
| 22879 |
if (text.length === 0 && range.isEmpty()) |
| 22880 |
return range.start; |
| 22881 |
if (text == this.getTextRange(range)) |
| 22882 |
return range.end; |
| 22883 |
|
| 22884 |
this.remove(range); |
| 22885 |
var end; |
| 22886 |
if (text) { |
| 22887 |
end = this.insert(range.start, text); |
| 22888 |
} |
| 22889 |
else { |
| 22890 |
end = range.start; |
| 22891 |
} |
| 22892 |
|
| 22893 |
return end; |
| 22894 |
}; |
| 22895 |
this.applyDeltas = function(deltas) { |
| 22896 |
for (var i=0; i<deltas.length; i++) { |
| 22897 |
this.applyDelta(deltas[i]); |
| 22898 |
} |
| 22899 |
}; |
| 22900 |
this.revertDeltas = function(deltas) { |
| 22901 |
for (var i=deltas.length-1; i>=0; i--) { |
| 22902 |
this.revertDelta(deltas[i]); |
| 22903 |
} |
| 22904 |
}; |
| 22905 |
this.applyDelta = function(delta, doNotValidate) { |
| 22906 |
var isInsert = delta.action == "insert"; |
| 22907 |
if (isInsert ? delta.lines.length <= 1 && !delta.lines[0] |
| 22908 |
: !Range.comparePoints(delta.start, delta.end)) { |
| 22909 |
return; |
| 22910 |
} |
| 22911 |
|
| 22912 |
if (isInsert && delta.lines.length > 20000) |
| 22913 |
this.$splitAndapplyLargeDelta(delta, 20000); |
| 22914 |
applyDelta(this.$lines, delta, doNotValidate); |
| 22915 |
this._signal("change", delta); |
| 22916 |
}; |
| 22917 |
|
| 22918 |
this.$splitAndapplyLargeDelta = function(delta, MAX) { |
| 22919 |
var lines = delta.lines; |
| 22920 |
var l = lines.length; |
| 22921 |
var row = delta.start.row; |
| 22922 |
var column = delta.start.column; |
| 22923 |
var from = 0, to = 0; |
| 22924 |
do { |
| 22925 |
from = to; |
| 22926 |
to += MAX - 1; |
| 22927 |
var chunk = lines.slice(from, to); |
| 22928 |
if (to > l) { |
| 22929 |
delta.lines = chunk; |
| 22930 |
delta.start.row = row + from; |
| 22931 |
delta.start.column = column; |
| 22932 |
break; |
| 22933 |
} |
| 22934 |
chunk.push(""); |
| 22935 |
this.applyDelta({ |
| 22936 |
start: this.pos(row + from, column), |
| 22937 |
end: this.pos(row + to, column = 0), |
| 22938 |
action: delta.action, |
| 22939 |
lines: chunk |
| 22940 |
}, true); |
| 22941 |
} while(true); |
| 22942 |
}; |
| 22943 |
this.revertDelta = function(delta) { |
| 22944 |
this.applyDelta({ |
| 22945 |
start: this.clonePos(delta.start), |
| 22946 |
end: this.clonePos(delta.end), |
| 22947 |
action: (delta.action == "insert" ? "remove" : "insert"), |
| 22948 |
lines: delta.lines.slice() |
| 22949 |
}); |
| 22950 |
}; |
| 22951 |
this.indexToPosition = function(index, startRow) { |
| 22952 |
var lines = this.$lines || this.getAllLines(); |
| 22953 |
var newlineLength = this.getNewLineCharacter().length; |
| 22954 |
for (var i = startRow || 0, l = lines.length; i < l; i++) { |
| 22955 |
index -= lines[i].length + newlineLength; |
| 22956 |
if (index < 0) |
| 22957 |
return {row: i, column: index + lines[i].length + newlineLength}; |
| 22958 |
} |
| 22959 |
return {row: l-1, column: lines[l-1].length}; |
| 22960 |
}; |
| 22961 |
this.positionToIndex = function(pos, startRow) { |
| 22962 |
var lines = this.$lines || this.getAllLines(); |
| 22963 |
var newlineLength = this.getNewLineCharacter().length; |
| 22964 |
var index = 0; |
| 22965 |
var row = Math.min(pos.row, lines.length); |
| 22966 |
for (var i = startRow || 0; i < row; ++i) |
| 22967 |
index += lines[i].length + newlineLength; |
| 22968 |
|
| 22969 |
return index + pos.column; |
| 22970 |
}; |
| 22971 |
|
| 22972 |
}).call(Document.prototype); |
| 22973 |
|
| 22974 |
exports.Document = Document; |
| 22975 |
}); |
| 22976 |
|
| 22977 |
ace.define("ace/background_tokenizer",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(acequire, exports, module) { |
| 22978 |
"use strict"; |
| 22979 |
|
| 22980 |
var oop = acequire("./lib/oop"); |
| 22981 |
var EventEmitter = acequire("./lib/event_emitter").EventEmitter; |
| 22982 |
|
| 22983 |
var BackgroundTokenizer = function(tokenizer, editor) { |
| 22984 |
this.running = false; |
| 22985 |
this.lines = []; |
| 22986 |
this.states = []; |
| 22987 |
this.currentLine = 0; |
| 22988 |
this.tokenizer = tokenizer; |
| 22989 |
|
| 22990 |
var self = this; |
| 22991 |
|
| 22992 |
this.$worker = function() { |
| 22993 |
if (!self.running) { return; } |
| 22994 |
|
| 22995 |
var workerStart = new Date(); |
| 22996 |
var currentLine = self.currentLine; |
| 22997 |
var endLine = -1; |
| 22998 |
var doc = self.doc; |
| 22999 |
|
| 23000 |
var startLine = currentLine; |
| 23001 |
while (self.lines[currentLine]) |
| 23002 |
currentLine++; |
| 23003 |
|
| 23004 |
var len = doc.getLength(); |
| 23005 |
var processedLines = 0; |
| 23006 |
self.running = false; |
| 23007 |
while (currentLine < len) { |
| 23008 |
self.$tokenizeRow(currentLine); |
| 23009 |
endLine = currentLine; |
| 23010 |
do { |
| 23011 |
currentLine++; |
| 23012 |
} while (self.lines[currentLine]); |
| 23013 |
processedLines ++; |
| 23014 |
if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) { |
| 23015 |
self.running = setTimeout(self.$worker, 20); |
| 23016 |
break; |
| 23017 |
} |
| 23018 |
} |
| 23019 |
self.currentLine = currentLine; |
| 23020 |
|
| 23021 |
if (startLine <= endLine) |
| 23022 |
self.fireUpdateEvent(startLine, endLine); |
| 23023 |
}; |
| 23024 |
}; |
| 23025 |
|
| 23026 |
(function(){ |
| 23027 |
|
| 23028 |
oop.implement(this, EventEmitter); |
| 23029 |
this.setTokenizer = function(tokenizer) { |
| 23030 |
this.tokenizer = tokenizer; |
| 23031 |
this.lines = []; |
| 23032 |
this.states = []; |
| 23033 |
|
| 23034 |
this.start(0); |
| 23035 |
}; |
| 23036 |
this.setDocument = function(doc) { |
| 23037 |
this.doc = doc; |
| 23038 |
this.lines = []; |
| 23039 |
this.states = []; |
| 23040 |
|
| 23041 |
this.stop(); |
| 23042 |
}; |
| 23043 |
this.fireUpdateEvent = function(firstRow, lastRow) { |
| 23044 |
var data = { |
| 23045 |
first: firstRow, |
| 23046 |
last: lastRow |
| 23047 |
}; |
| 23048 |
this._signal("update", {data: data}); |
| 23049 |
}; |
| 23050 |
this.start = function(startRow) { |
| 23051 |
this.currentLine = Math.min(startRow || 0, this.currentLine, this.doc.getLength()); |
| 23052 |
this.lines.splice(this.currentLine, this.lines.length); |
| 23053 |
this.states.splice(this.currentLine, this.states.length); |
| 23054 |
|
| 23055 |
this.stop(); |
| 23056 |
this.running = setTimeout(this.$worker, 700); |
| 23057 |
}; |
| 23058 |
|
| 23059 |
this.scheduleStart = function() { |
| 23060 |
if (!this.running) |
| 23061 |
this.running = setTimeout(this.$worker, 700); |
| 23062 |
} |
| 23063 |
|
| 23064 |
this.$updateOnChange = function(delta) { |
| 23065 |
var startRow = delta.start.row; |
| 23066 |
var len = delta.end.row - startRow; |
| 23067 |
|
| 23068 |
if (len === 0) { |
| 23069 |
this.lines[startRow] = null; |
| 23070 |
} else if (delta.action == "remove") { |
| 23071 |
this.lines.splice(startRow, len + 1, null); |
| 23072 |
this.states.splice(startRow, len + 1, null); |
| 23073 |
} else { |
| 23074 |
var args = Array(len + 1); |
| 23075 |
args.unshift(startRow, 1); |
| 23076 |
this.lines.splice.apply(this.lines, args); |
| 23077 |
this.states.splice.apply(this.states, args); |
| 23078 |
} |
| 23079 |
|
| 23080 |
this.currentLine = Math.min(startRow, this.currentLine, this.doc.getLength()); |
| 23081 |
|
| 23082 |
this.stop(); |
| 23083 |
}; |
| 23084 |
this.stop = function() { |
| 23085 |
if (this.running) |
| 23086 |
clearTimeout(this.running); |
| 23087 |
this.running = false; |
| 23088 |
}; |
| 23089 |
this.getTokens = function(row) { |
| 23090 |
return this.lines[row] || this.$tokenizeRow(row); |
| 23091 |
}; |
| 23092 |
this.getState = function(row) { |
| 23093 |
if (this.currentLine == row) |
| 23094 |
this.$tokenizeRow(row); |
| 23095 |
return this.states[row] || "start"; |
| 23096 |
}; |
| 23097 |
|
| 23098 |
this.$tokenizeRow = function(row) { |
| 23099 |
var line = this.doc.getLine(row); |
| 23100 |
var state = this.states[row - 1]; |
| 23101 |
|
| 23102 |
var data = this.tokenizer.getLineTokens(line, state, row); |
| 23103 |
|
| 23104 |
if (this.states[row] + "" !== data.state + "") { |
| 23105 |
this.states[row] = data.state; |
| 23106 |
this.lines[row + 1] = null; |
| 23107 |
if (this.currentLine > row + 1) |
| 23108 |
this.currentLine = row + 1; |
| 23109 |
} else if (this.currentLine == row) { |
| 23110 |
this.currentLine = row + 1; |
| 23111 |
} |
| 23112 |
|
| 23113 |
return this.lines[row] = data.tokens; |
| 23114 |
}; |
| 23115 |
|
| 23116 |
}).call(BackgroundTokenizer.prototype); |
| 23117 |
|
| 23118 |
exports.BackgroundTokenizer = BackgroundTokenizer; |
| 23119 |
}); |
| 23120 |
|
| 23121 |
ace.define("ace/search_highlight",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(acequire, exports, module) { |
| 23122 |
"use strict"; |
| 23123 |
|
| 23124 |
var lang = acequire("./lib/lang"); |
| 23125 |
var oop = acequire("./lib/oop"); |
| 23126 |
var Range = acequire("./range").Range; |
| 23127 |
|
| 23128 |
var SearchHighlight = function(regExp, clazz, type) { |
| 23129 |
this.setRegexp(regExp); |
| 23130 |
this.clazz = clazz; |
| 23131 |
this.type = type || "text"; |
| 23132 |
}; |
| 23133 |
|
| 23134 |
(function() { |
| 23135 |
this.MAX_RANGES = 500; |
| 23136 |
|
| 23137 |
this.setRegexp = function(regExp) { |
| 23138 |
if (this.regExp+"" == regExp+"") |
| 23139 |
return; |
| 23140 |
this.regExp = regExp; |
| 23141 |
this.cache = []; |
| 23142 |
}; |
| 23143 |
|
| 23144 |
this.update = function(html, markerLayer, session, config) { |
| 23145 |
if (!this.regExp) |
| 23146 |
return; |
| 23147 |
var start = config.firstRow, end = config.lastRow; |
| 23148 |
|
| 23149 |
for (var i = start; i <= end; i++) { |
| 23150 |
var ranges = this.cache[i]; |
| 23151 |
if (ranges == null) { |
| 23152 |
ranges = lang.getMatchOffsets(session.getLine(i), this.regExp); |
| 23153 |
if (ranges.length > this.MAX_RANGES) |
| 23154 |
ranges = ranges.slice(0, this.MAX_RANGES); |
| 23155 |
ranges = ranges.map(function(match) { |
| 23156 |
return new Range(i, match.offset, i, match.offset + match.length); |
| 23157 |
}); |
| 23158 |
this.cache[i] = ranges.length ? ranges : ""; |
| 23159 |
} |
| 23160 |
|
| 23161 |
for (var j = ranges.length; j --; ) { |
| 23162 |
markerLayer.drawSingleLineMarker( |
| 23163 |
html, ranges[j].toScreenRange(session), this.clazz, config); |
| 23164 |
} |
| 23165 |
} |
| 23166 |
}; |
| 23167 |
|
| 23168 |
}).call(SearchHighlight.prototype); |
| 23169 |
|
| 23170 |
exports.SearchHighlight = SearchHighlight; |
| 23171 |
}); |
| 23172 |
|
| 23173 |
ace.define("ace/edit_session/fold_line",["require","exports","module","ace/range"], function(acequire, exports, module) { |
| 23174 |
"use strict"; |
| 23175 |
|
| 23176 |
var Range = acequire("../range").Range; |
| 23177 |
function FoldLine(foldData, folds) { |
| 23178 |
this.foldData = foldData; |
| 23179 |
if (Array.isArray(folds)) { |
| 23180 |
this.folds = folds; |
| 23181 |
} else { |
| 23182 |
folds = this.folds = [ folds ]; |
| 23183 |
} |
| 23184 |
|
| 23185 |
var last = folds[folds.length - 1]; |
| 23186 |
this.range = new Range(folds[0].start.row, folds[0].start.column, |
| 23187 |
last.end.row, last.end.column); |
| 23188 |
this.start = this.range.start; |
| 23189 |
this.end = this.range.end; |
| 23190 |
|
| 23191 |
this.folds.forEach(function(fold) { |
| 23192 |
fold.setFoldLine(this); |
| 23193 |
}, this); |
| 23194 |
} |
| 23195 |
|
| 23196 |
(function() { |
| 23197 |
this.shiftRow = function(shift) { |
| 23198 |
this.start.row += shift; |
| 23199 |
this.end.row += shift; |
| 23200 |
this.folds.forEach(function(fold) { |
| 23201 |
fold.start.row += shift; |
| 23202 |
fold.end.row += shift; |
| 23203 |
}); |
| 23204 |
}; |
| 23205 |
|
| 23206 |
this.addFold = function(fold) { |
| 23207 |
if (fold.sameRow) { |
| 23208 |
if (fold.start.row < this.startRow || fold.endRow > this.endRow) { |
| 23209 |
throw new Error("Can't add a fold to this FoldLine as it has no connection"); |
| 23210 |
} |
| 23211 |
this.folds.push(fold); |
| 23212 |
this.folds.sort(function(a, b) { |
| 23213 |
return -a.range.compareEnd(b.start.row, b.start.column); |
| 23214 |
}); |
| 23215 |
if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) { |
| 23216 |
this.end.row = fold.end.row; |
| 23217 |
this.end.column = fold.end.column; |
| 23218 |
} else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) { |
| 23219 |
this.start.row = fold.start.row; |
| 23220 |
this.start.column = fold.start.column; |
| 23221 |
} |
| 23222 |
} else if (fold.start.row == this.end.row) { |
| 23223 |
this.folds.push(fold); |
| 23224 |
this.end.row = fold.end.row; |
| 23225 |
this.end.column = fold.end.column; |
| 23226 |
} else if (fold.end.row == this.start.row) { |
| 23227 |
this.folds.unshift(fold); |
| 23228 |
this.start.row = fold.start.row; |
| 23229 |
this.start.column = fold.start.column; |
| 23230 |
} else { |
| 23231 |
throw new Error("Trying to add fold to FoldRow that doesn't have a matching row"); |
| 23232 |
} |
| 23233 |
fold.foldLine = this; |
| 23234 |
}; |
| 23235 |
|
| 23236 |
this.containsRow = function(row) { |
| 23237 |
return row >= this.start.row && row <= this.end.row; |
| 23238 |
}; |
| 23239 |
|
| 23240 |
this.walk = function(callback, endRow, endColumn) { |
| 23241 |
var lastEnd = 0, |
| 23242 |
folds = this.folds, |
| 23243 |
fold, |
| 23244 |
cmp, stop, isNewRow = true; |
| 23245 |
|
| 23246 |
if (endRow == null) { |
| 23247 |
endRow = this.end.row; |
| 23248 |
endColumn = this.end.column; |
| 23249 |
} |
| 23250 |
|
| 23251 |
for (var i = 0; i < folds.length; i++) { |
| 23252 |
fold = folds[i]; |
| 23253 |
|
| 23254 |
cmp = fold.range.compareStart(endRow, endColumn); |
| 23255 |
if (cmp == -1) { |
| 23256 |
callback(null, endRow, endColumn, lastEnd, isNewRow); |
| 23257 |
return; |
| 23258 |
} |
| 23259 |
|
| 23260 |
stop = callback(null, fold.start.row, fold.start.column, lastEnd, isNewRow); |
| 23261 |
stop = !stop && callback(fold.placeholder, fold.start.row, fold.start.column, lastEnd); |
| 23262 |
if (stop || cmp === 0) { |
| 23263 |
return; |
| 23264 |
} |
| 23265 |
isNewRow = !fold.sameRow; |
| 23266 |
lastEnd = fold.end.column; |
| 23267 |
} |
| 23268 |
callback(null, endRow, endColumn, lastEnd, isNewRow); |
| 23269 |
}; |
| 23270 |
|
| 23271 |
this.getNextFoldTo = function(row, column) { |
| 23272 |
var fold, cmp; |
| 23273 |
for (var i = 0; i < this.folds.length; i++) { |
| 23274 |
fold = this.folds[i]; |
| 23275 |
cmp = fold.range.compareEnd(row, column); |
| 23276 |
if (cmp == -1) { |
| 23277 |
return { |
| 23278 |
fold: fold, |
| 23279 |
kind: "after" |
| 23280 |
}; |
| 23281 |
} else if (cmp === 0) { |
| 23282 |
return { |
| 23283 |
fold: fold, |
| 23284 |
kind: "inside" |
| 23285 |
}; |
| 23286 |
} |
| 23287 |
} |
| 23288 |
return null; |
| 23289 |
}; |
| 23290 |
|
| 23291 |
this.addRemoveChars = function(row, column, len) { |
| 23292 |
var ret = this.getNextFoldTo(row, column), |
| 23293 |
fold, folds; |
| 23294 |
if (ret) { |
| 23295 |
fold = ret.fold; |
| 23296 |
if (ret.kind == "inside" |
| 23297 |
&& fold.start.column != column |
| 23298 |
&& fold.start.row != row) |
| 23299 |
{ |
| 23300 |
window.console && window.console.log(row, column, fold); |
| 23301 |
} else if (fold.start.row == row) { |
| 23302 |
folds = this.folds; |
| 23303 |
var i = folds.indexOf(fold); |
| 23304 |
if (i === 0) { |
| 23305 |
this.start.column += len; |
| 23306 |
} |
| 23307 |
for (i; i < folds.length; i++) { |
| 23308 |
fold = folds[i]; |
| 23309 |
fold.start.column += len; |
| 23310 |
if (!fold.sameRow) { |
| 23311 |
return; |
| 23312 |
} |
| 23313 |
fold.end.column += len; |
| 23314 |
} |
| 23315 |
this.end.column += len; |
| 23316 |
} |
| 23317 |
} |
| 23318 |
}; |
| 23319 |
|
| 23320 |
this.split = function(row, column) { |
| 23321 |
var pos = this.getNextFoldTo(row, column); |
| 23322 |
|
| 23323 |
if (!pos || pos.kind == "inside") |
| 23324 |
return null; |
| 23325 |
|
| 23326 |
var fold = pos.fold; |
| 23327 |
var folds = this.folds; |
| 23328 |
var foldData = this.foldData; |
| 23329 |
|
| 23330 |
var i = folds.indexOf(fold); |
| 23331 |
var foldBefore = folds[i - 1]; |
| 23332 |
this.end.row = foldBefore.end.row; |
| 23333 |
this.end.column = foldBefore.end.column; |
| 23334 |
folds = folds.splice(i, folds.length - i); |
| 23335 |
|
| 23336 |
var newFoldLine = new FoldLine(foldData, folds); |
| 23337 |
foldData.splice(foldData.indexOf(this) + 1, 0, newFoldLine); |
| 23338 |
return newFoldLine; |
| 23339 |
}; |
| 23340 |
|
| 23341 |
this.merge = function(foldLineNext) { |
| 23342 |
var folds = foldLineNext.folds; |
| 23343 |
for (var i = 0; i < folds.length; i++) { |
| 23344 |
this.addFold(folds[i]); |
| 23345 |
} |
| 23346 |
var foldData = this.foldData; |
| 23347 |
foldData.splice(foldData.indexOf(foldLineNext), 1); |
| 23348 |
}; |
| 23349 |
|
| 23350 |
this.toString = function() { |
| 23351 |
var ret = [this.range.toString() + ": [" ]; |
| 23352 |
|
| 23353 |
this.folds.forEach(function(fold) { |
| 23354 |
ret.push(" " + fold.toString()); |
| 23355 |
}); |
| 23356 |
ret.push("]"); |
| 23357 |
return ret.join("\n"); |
| 23358 |
}; |
| 23359 |
|
| 23360 |
this.idxToPosition = function(idx) { |
| 23361 |
var lastFoldEndColumn = 0; |
| 23362 |
|
| 23363 |
for (var i = 0; i < this.folds.length; i++) { |
| 23364 |
var fold = this.folds[i]; |
| 23365 |
|
| 23366 |
idx -= fold.start.column - lastFoldEndColumn; |
| 23367 |
if (idx < 0) { |
| 23368 |
return { |
| 23369 |
row: fold.start.row, |
| 23370 |
column: fold.start.column + idx |
| 23371 |
}; |
| 23372 |
} |
| 23373 |
|
| 23374 |
idx -= fold.placeholder.length; |
| 23375 |
if (idx < 0) { |
| 23376 |
return fold.start; |
| 23377 |
} |
| 23378 |
|
| 23379 |
lastFoldEndColumn = fold.end.column; |
| 23380 |
} |
| 23381 |
|
| 23382 |
return { |
| 23383 |
row: this.end.row, |
| 23384 |
column: this.end.column + idx |
| 23385 |
}; |
| 23386 |
}; |
| 23387 |
}).call(FoldLine.prototype); |
| 23388 |
|
| 23389 |
exports.FoldLine = FoldLine; |
| 23390 |
}); |
| 23391 |
|
| 23392 |
ace.define("ace/range_list",["require","exports","module","ace/range"], function(acequire, exports, module) { |
| 23393 |
"use strict"; |
| 23394 |
var Range = acequire("./range").Range; |
| 23395 |
var comparePoints = Range.comparePoints; |
| 23396 |
|
| 23397 |
var RangeList = function() { |
| 23398 |
this.ranges = []; |
| 23399 |
}; |
| 23400 |
|
| 23401 |
(function() { |
| 23402 |
this.comparePoints = comparePoints; |
| 23403 |
|
| 23404 |
this.pointIndex = function(pos, excludeEdges, startIndex) { |
| 23405 |
var list = this.ranges; |
| 23406 |
|
| 23407 |
for (var i = startIndex || 0; i < list.length; i++) { |
| 23408 |
var range = list[i]; |
| 23409 |
var cmpEnd = comparePoints(pos, range.end); |
| 23410 |
if (cmpEnd > 0) |
| 23411 |
continue; |
| 23412 |
var cmpStart = comparePoints(pos, range.start); |
| 23413 |
if (cmpEnd === 0) |
| 23414 |
return excludeEdges && cmpStart !== 0 ? -i-2 : i; |
| 23415 |
if (cmpStart > 0 || (cmpStart === 0 && !excludeEdges)) |
| 23416 |
return i; |
| 23417 |
|
| 23418 |
return -i-1; |
| 23419 |
} |
| 23420 |
return -i - 1; |
| 23421 |
}; |
| 23422 |
|
| 23423 |
this.add = function(range) { |
| 23424 |
var excludeEdges = !range.isEmpty(); |
| 23425 |
var startIndex = this.pointIndex(range.start, excludeEdges); |
| 23426 |
if (startIndex < 0) |
| 23427 |
startIndex = -startIndex - 1; |
| 23428 |
|
| 23429 |
var endIndex = this.pointIndex(range.end, excludeEdges, startIndex); |
| 23430 |
|
| 23431 |
if (endIndex < 0) |
| 23432 |
endIndex = -endIndex - 1; |
| 23433 |
else |
| 23434 |
endIndex++; |
| 23435 |
return this.ranges.splice(startIndex, endIndex - startIndex, range); |
| 23436 |
}; |
| 23437 |
|
| 23438 |
this.addList = function(list) { |
| 23439 |
var removed = []; |
| 23440 |
for (var i = list.length; i--; ) { |
| 23441 |
removed.push.apply(removed, this.add(list[i])); |
| 23442 |
} |
| 23443 |
return removed; |
| 23444 |
}; |
| 23445 |
|
| 23446 |
this.substractPoint = function(pos) { |
| 23447 |
var i = this.pointIndex(pos); |
| 23448 |
|
| 23449 |
if (i >= 0) |
| 23450 |
return this.ranges.splice(i, 1); |
| 23451 |
}; |
| 23452 |
this.merge = function() { |
| 23453 |
var removed = []; |
| 23454 |
var list = this.ranges; |
| 23455 |
|
| 23456 |
list = list.sort(function(a, b) { |
| 23457 |
return comparePoints(a.start, b.start); |
| 23458 |
}); |
| 23459 |
|
| 23460 |
var next = list[0], range; |
| 23461 |
for (var i = 1; i < list.length; i++) { |
| 23462 |
range = next; |
| 23463 |
next = list[i]; |
| 23464 |
var cmp = comparePoints(range.end, next.start); |
| 23465 |
if (cmp < 0) |
| 23466 |
continue; |
| 23467 |
|
| 23468 |
if (cmp == 0 && !range.isEmpty() && !next.isEmpty()) |
| 23469 |
continue; |
| 23470 |
|
| 23471 |
if (comparePoints(range.end, next.end) < 0) { |
| 23472 |
range.end.row = next.end.row; |
| 23473 |
range.end.column = next.end.column; |
| 23474 |
} |
| 23475 |
|
| 23476 |
list.splice(i, 1); |
| 23477 |
removed.push(next); |
| 23478 |
next = range; |
| 23479 |
i--; |
| 23480 |
} |
| 23481 |
|
| 23482 |
this.ranges = list; |
| 23483 |
|
| 23484 |
return removed; |
| 23485 |
}; |
| 23486 |
|
| 23487 |
this.contains = function(row, column) { |
| 23488 |
return this.pointIndex({row: row, column: column}) >= 0; |
| 23489 |
}; |
| 23490 |
|
| 23491 |
this.containsPoint = function(pos) { |
| 23492 |
return this.pointIndex(pos) >= 0; |
| 23493 |
}; |
| 23494 |
|
| 23495 |
this.rangeAtPoint = function(pos) { |
| 23496 |
var i = this.pointIndex(pos); |
| 23497 |
if (i >= 0) |
| 23498 |
return this.ranges[i]; |
| 23499 |
}; |
| 23500 |
|
| 23501 |
|
| 23502 |
this.clipRows = function(startRow, endRow) { |
| 23503 |
var list = this.ranges; |
| 23504 |
if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow) |
| 23505 |
return []; |
| 23506 |
|
| 23507 |
var startIndex = this.pointIndex({row: startRow, column: 0}); |
| 23508 |
if (startIndex < 0) |
| 23509 |
startIndex = -startIndex - 1; |
| 23510 |
var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex); |
| 23511 |
if (endIndex < 0) |
| 23512 |
endIndex = -endIndex - 1; |
| 23513 |
|
| 23514 |
var clipped = []; |
| 23515 |
for (var i = startIndex; i < endIndex; i++) { |
| 23516 |
clipped.push(list[i]); |
| 23517 |
} |
| 23518 |
return clipped; |
| 23519 |
}; |
| 23520 |
|
| 23521 |
this.removeAll = function() { |
| 23522 |
return this.ranges.splice(0, this.ranges.length); |
| 23523 |
}; |
| 23524 |
|
| 23525 |
this.attach = function(session) { |
| 23526 |
if (this.session) |
| 23527 |
this.detach(); |
| 23528 |
|
| 23529 |
this.session = session; |
| 23530 |
this.onChange = this.$onChange.bind(this); |
| 23531 |
|
| 23532 |
this.session.on('change', this.onChange); |
| 23533 |
}; |
| 23534 |
|
| 23535 |
this.detach = function() { |
| 23536 |
if (!this.session) |
| 23537 |
return; |
| 23538 |
this.session.removeListener('change', this.onChange); |
| 23539 |
this.session = null; |
| 23540 |
}; |
| 23541 |
|
| 23542 |
this.$onChange = function(delta) { |
| 23543 |
if (delta.action == "insert"){ |
| 23544 |
var start = delta.start; |
| 23545 |
var end = delta.end; |
| 23546 |
} else { |
| 23547 |
var end = delta.start; |
| 23548 |
var start = delta.end; |
| 23549 |
} |
| 23550 |
var startRow = start.row; |
| 23551 |
var endRow = end.row; |
| 23552 |
var lineDif = endRow - startRow; |
| 23553 |
|
| 23554 |
var colDiff = -start.column + end.column; |
| 23555 |
var ranges = this.ranges; |
| 23556 |
|
| 23557 |
for (var i = 0, n = ranges.length; i < n; i++) { |
| 23558 |
var r = ranges[i]; |
| 23559 |
if (r.end.row < startRow) |
| 23560 |
continue; |
| 23561 |
if (r.start.row > startRow) |
| 23562 |
break; |
| 23563 |
|
| 23564 |
if (r.start.row == startRow && r.start.column >= start.column ) { |
| 23565 |
if (r.start.column == start.column && this.$insertRight) { |
| 23566 |
} else { |
| 23567 |
r.start.column += colDiff; |
| 23568 |
r.start.row += lineDif; |
| 23569 |
} |
| 23570 |
} |
| 23571 |
if (r.end.row == startRow && r.end.column >= start.column) { |
| 23572 |
if (r.end.column == start.column && this.$insertRight) { |
| 23573 |
continue; |
| 23574 |
} |
| 23575 |
if (r.end.column == start.column && colDiff > 0 && i < n - 1) { |
| 23576 |
if (r.end.column > r.start.column && r.end.column == ranges[i+1].start.column) |
| 23577 |
r.end.column -= colDiff; |
| 23578 |
} |
| 23579 |
r.end.column += colDiff; |
| 23580 |
r.end.row += lineDif; |
| 23581 |
} |
| 23582 |
} |
| 23583 |
|
| 23584 |
if (lineDif != 0 && i < n) { |
| 23585 |
for (; i < n; i++) { |
| 23586 |
var r = ranges[i]; |
| 23587 |
r.start.row += lineDif; |
| 23588 |
r.end.row += lineDif; |
| 23589 |
} |
| 23590 |
} |
| 23591 |
}; |
| 23592 |
|
| 23593 |
}).call(RangeList.prototype); |
| 23594 |
|
| 23595 |
exports.RangeList = RangeList; |
| 23596 |
}); |
| 23597 |
|
| 23598 |
ace.define("ace/edit_session/fold",["require","exports","module","ace/range","ace/range_list","ace/lib/oop"], function(acequire, exports, module) { |
| 23599 |
"use strict"; |
| 23600 |
|
| 23601 |
var Range = acequire("../range").Range; |
| 23602 |
var RangeList = acequire("../range_list").RangeList; |
| 23603 |
var oop = acequire("../lib/oop") |
| 23604 |
var Fold = exports.Fold = function(range, placeholder) { |
| 23605 |
this.foldLine = null; |
| 23606 |
this.placeholder = placeholder; |
| 23607 |
this.range = range; |
| 23608 |
this.start = range.start; |
| 23609 |
this.end = range.end; |
| 23610 |
|
| 23611 |
this.sameRow = range.start.row == range.end.row; |
| 23612 |
this.subFolds = this.ranges = []; |
| 23613 |
}; |
| 23614 |
|
| 23615 |
oop.inherits(Fold, RangeList); |
| 23616 |
|
| 23617 |
(function() { |
| 23618 |
|
| 23619 |
this.toString = function() { |
| 23620 |
return '"' + this.placeholder + '" ' + this.range.toString(); |
| 23621 |
}; |
| 23622 |
|
| 23623 |
this.setFoldLine = function(foldLine) { |
| 23624 |
this.foldLine = foldLine; |
| 23625 |
this.subFolds.forEach(function(fold) { |
| 23626 |
fold.setFoldLine(foldLine); |
| 23627 |
}); |
| 23628 |
}; |
| 23629 |
|
| 23630 |
this.clone = function() { |
| 23631 |
var range = this.range.clone(); |
| 23632 |
var fold = new Fold(range, this.placeholder); |
| 23633 |
this.subFolds.forEach(function(subFold) { |
| 23634 |
fold.subFolds.push(subFold.clone()); |
| 23635 |
}); |
| 23636 |
fold.collapseChildren = this.collapseChildren; |
| 23637 |
return fold; |
| 23638 |
}; |
| 23639 |
|
| 23640 |
this.addSubFold = function(fold) { |
| 23641 |
if (this.range.isEqual(fold)) |
| 23642 |
return; |
| 23643 |
|
| 23644 |
if (!this.range.containsRange(fold)) |
| 23645 |
throw new Error("A fold can't intersect already existing fold" + fold.range + this.range); |
| 23646 |
consumeRange(fold, this.start); |
| 23647 |
|
| 23648 |
var row = fold.start.row, column = fold.start.column; |
| 23649 |
for (var i = 0, cmp = -1; i < this.subFolds.length; i++) { |
| 23650 |
cmp = this.subFolds[i].range.compare(row, column); |
| 23651 |
if (cmp != 1) |
| 23652 |
break; |
| 23653 |
} |
| 23654 |
var afterStart = this.subFolds[i]; |
| 23655 |
|
| 23656 |
if (cmp == 0) |
| 23657 |
return afterStart.addSubFold(fold); |
| 23658 |
var row = fold.range.end.row, column = fold.range.end.column; |
| 23659 |
for (var j = i, cmp = -1; j < this.subFolds.length; j++) { |
| 23660 |
cmp = this.subFolds[j].range.compare(row, column); |
| 23661 |
if (cmp != 1) |
| 23662 |
break; |
| 23663 |
} |
| 23664 |
var afterEnd = this.subFolds[j]; |
| 23665 |
|
| 23666 |
if (cmp == 0) |
| 23667 |
throw new Error("A fold can't intersect already existing fold" + fold.range + this.range); |
| 23668 |
|
| 23669 |
var consumedFolds = this.subFolds.splice(i, j - i, fold); |
| 23670 |
fold.setFoldLine(this.foldLine); |
| 23671 |
|
| 23672 |
return fold; |
| 23673 |
}; |
| 23674 |
|
| 23675 |
this.restoreRange = function(range) { |
| 23676 |
return restoreRange(range, this.start); |
| 23677 |
}; |
| 23678 |
|
| 23679 |
}).call(Fold.prototype); |
| 23680 |
|
| 23681 |
function consumePoint(point, anchor) { |
| 23682 |
point.row -= anchor.row; |
| 23683 |
if (point.row == 0) |
| 23684 |
point.column -= anchor.column; |
| 23685 |
} |
| 23686 |
function consumeRange(range, anchor) { |
| 23687 |
consumePoint(range.start, anchor); |
| 23688 |
consumePoint(range.end, anchor); |
| 23689 |
} |
| 23690 |
function restorePoint(point, anchor) { |
| 23691 |
if (point.row == 0) |
| 23692 |
point.column += anchor.column; |
| 23693 |
point.row += anchor.row; |
| 23694 |
} |
| 23695 |
function restoreRange(range, anchor) { |
| 23696 |
restorePoint(range.start, anchor); |
| 23697 |
restorePoint(range.end, anchor); |
| 23698 |
} |
| 23699 |
|
| 23700 |
}); |
| 23701 |
|
| 23702 |
ace.define("ace/edit_session/folding",["require","exports","module","ace/range","ace/edit_session/fold_line","ace/edit_session/fold","ace/token_iterator"], function(acequire, exports, module) { |
| 23703 |
"use strict"; |
| 23704 |
|
| 23705 |
var Range = acequire("../range").Range; |
| 23706 |
var FoldLine = acequire("./fold_line").FoldLine; |
| 23707 |
var Fold = acequire("./fold").Fold; |
| 23708 |
var TokenIterator = acequire("../token_iterator").TokenIterator; |
| 23709 |
|
| 23710 |
function Folding() { |
| 23711 |
this.getFoldAt = function(row, column, side) { |
| 23712 |
var foldLine = this.getFoldLine(row); |
| 23713 |
if (!foldLine) |
| 23714 |
return null; |
| 23715 |
|
| 23716 |
var folds = foldLine.folds; |
| 23717 |
for (var i = 0; i < folds.length; i++) { |
| 23718 |
var fold = folds[i]; |
| 23719 |
if (fold.range.contains(row, column)) { |
| 23720 |
if (side == 1 && fold.range.isEnd(row, column)) { |
| 23721 |
continue; |
| 23722 |
} else if (side == -1 && fold.range.isStart(row, column)) { |
| 23723 |
continue; |
| 23724 |
} |
| 23725 |
return fold; |
| 23726 |
} |
| 23727 |
} |
| 23728 |
}; |
| 23729 |
this.getFoldsInRange = function(range) { |
| 23730 |
var start = range.start; |
| 23731 |
var end = range.end; |
| 23732 |
var foldLines = this.$foldData; |
| 23733 |
var foundFolds = []; |
| 23734 |
|
| 23735 |
start.column += 1; |
| 23736 |
end.column -= 1; |
| 23737 |
|
| 23738 |
for (var i = 0; i < foldLines.length; i++) { |
| 23739 |
var cmp = foldLines[i].range.compareRange(range); |
| 23740 |
if (cmp == 2) { |
| 23741 |
continue; |
| 23742 |
} |
| 23743 |
else if (cmp == -2) { |
| 23744 |
break; |
| 23745 |
} |
| 23746 |
|
| 23747 |
var folds = foldLines[i].folds; |
| 23748 |
for (var j = 0; j < folds.length; j++) { |
| 23749 |
var fold = folds[j]; |
| 23750 |
cmp = fold.range.compareRange(range); |
| 23751 |
if (cmp == -2) { |
| 23752 |
break; |
| 23753 |
} else if (cmp == 2) { |
| 23754 |
continue; |
| 23755 |
} else |
| 23756 |
if (cmp == 42) { |
| 23757 |
break; |
| 23758 |
} |
| 23759 |
foundFolds.push(fold); |
| 23760 |
} |
| 23761 |
} |
| 23762 |
start.column -= 1; |
| 23763 |
end.column += 1; |
| 23764 |
|
| 23765 |
return foundFolds; |
| 23766 |
}; |
| 23767 |
|
| 23768 |
this.getFoldsInRangeList = function(ranges) { |
| 23769 |
if (Array.isArray(ranges)) { |
| 23770 |
var folds = []; |
| 23771 |
ranges.forEach(function(range) { |
| 23772 |
folds = folds.concat(this.getFoldsInRange(range)); |
| 23773 |
}, this); |
| 23774 |
} else { |
| 23775 |
var folds = this.getFoldsInRange(ranges); |
| 23776 |
} |
| 23777 |
return folds; |
| 23778 |
}; |
| 23779 |
this.getAllFolds = function() { |
| 23780 |
var folds = []; |
| 23781 |
var foldLines = this.$foldData; |
| 23782 |
|
| 23783 |
for (var i = 0; i < foldLines.length; i++) |
| 23784 |
for (var j = 0; j < foldLines[i].folds.length; j++) |
| 23785 |
folds.push(foldLines[i].folds[j]); |
| 23786 |
|
| 23787 |
return folds; |
| 23788 |
}; |
| 23789 |
this.getFoldStringAt = function(row, column, trim, foldLine) { |
| 23790 |
foldLine = foldLine || this.getFoldLine(row); |
| 23791 |
if (!foldLine) |
| 23792 |
return null; |
| 23793 |
|
| 23794 |
var lastFold = { |
| 23795 |
end: { column: 0 } |
| 23796 |
}; |
| 23797 |
var str, fold; |
| 23798 |
for (var i = 0; i < foldLine.folds.length; i++) { |
| 23799 |
fold = foldLine.folds[i]; |
| 23800 |
var cmp = fold.range.compareEnd(row, column); |
| 23801 |
if (cmp == -1) { |
| 23802 |
str = this |
| 23803 |
.getLine(fold.start.row) |
| 23804 |
.substring(lastFold.end.column, fold.start.column); |
| 23805 |
break; |
| 23806 |
} |
| 23807 |
else if (cmp === 0) { |
| 23808 |
return null; |
| 23809 |
} |
| 23810 |
lastFold = fold; |
| 23811 |
} |
| 23812 |
if (!str) |
| 23813 |
str = this.getLine(fold.start.row).substring(lastFold.end.column); |
| 23814 |
|
| 23815 |
if (trim == -1) |
| 23816 |
return str.substring(0, column - lastFold.end.column); |
| 23817 |
else if (trim == 1) |
| 23818 |
return str.substring(column - lastFold.end.column); |
| 23819 |
else |
| 23820 |
return str; |
| 23821 |
}; |
| 23822 |
|
| 23823 |
this.getFoldLine = function(docRow, startFoldLine) { |
| 23824 |
var foldData = this.$foldData; |
| 23825 |
var i = 0; |
| 23826 |
if (startFoldLine) |
| 23827 |
i = foldData.indexOf(startFoldLine); |
| 23828 |
if (i == -1) |
| 23829 |
i = 0; |
| 23830 |
for (i; i < foldData.length; i++) { |
| 23831 |
var foldLine = foldData[i]; |
| 23832 |
if (foldLine.start.row <= docRow && foldLine.end.row >= docRow) { |
| 23833 |
return foldLine; |
| 23834 |
} else if (foldLine.end.row > docRow) { |
| 23835 |
return null; |
| 23836 |
} |
| 23837 |
} |
| 23838 |
return null; |
| 23839 |
}; |
| 23840 |
this.getNextFoldLine = function(docRow, startFoldLine) { |
| 23841 |
var foldData = this.$foldData; |
| 23842 |
var i = 0; |
| 23843 |
if (startFoldLine) |
| 23844 |
i = foldData.indexOf(startFoldLine); |
| 23845 |
if (i == -1) |
| 23846 |
i = 0; |
| 23847 |
for (i; i < foldData.length; i++) { |
| 23848 |
var foldLine = foldData[i]; |
| 23849 |
if (foldLine.end.row >= docRow) { |
| 23850 |
return foldLine; |
| 23851 |
} |
| 23852 |
} |
| 23853 |
return null; |
| 23854 |
}; |
| 23855 |
|
| 23856 |
this.getFoldedRowCount = function(first, last) { |
| 23857 |
var foldData = this.$foldData, rowCount = last-first+1; |
| 23858 |
for (var i = 0; i < foldData.length; i++) { |
| 23859 |
var foldLine = foldData[i], |
| 23860 |
end = foldLine.end.row, |
| 23861 |
start = foldLine.start.row; |
| 23862 |
if (end >= last) { |
| 23863 |
if (start < last) { |
| 23864 |
if (start >= first) |
| 23865 |
rowCount -= last-start; |
| 23866 |
else |
| 23867 |
rowCount = 0; // in one fold |
| 23868 |
} |
| 23869 |
break; |
| 23870 |
} else if (end >= first){ |
| 23871 |
if (start >= first) // fold inside range |
| 23872 |
rowCount -= end-start; |
| 23873 |
else |
| 23874 |
rowCount -= end-first+1; |
| 23875 |
} |
| 23876 |
} |
| 23877 |
return rowCount; |
| 23878 |
}; |
| 23879 |
|
| 23880 |
this.$addFoldLine = function(foldLine) { |
| 23881 |
this.$foldData.push(foldLine); |
| 23882 |
this.$foldData.sort(function(a, b) { |
| 23883 |
return a.start.row - b.start.row; |
| 23884 |
}); |
| 23885 |
return foldLine; |
| 23886 |
}; |
| 23887 |
this.addFold = function(placeholder, range) { |
| 23888 |
var foldData = this.$foldData; |
| 23889 |
var added = false; |
| 23890 |
var fold; |
| 23891 |
|
| 23892 |
if (placeholder instanceof Fold) |
| 23893 |
fold = placeholder; |
| 23894 |
else { |
| 23895 |
fold = new Fold(range, placeholder); |
| 23896 |
fold.collapseChildren = range.collapseChildren; |
| 23897 |
} |
| 23898 |
this.$clipRangeToDocument(fold.range); |
| 23899 |
|
| 23900 |
var startRow = fold.start.row; |
| 23901 |
var startColumn = fold.start.column; |
| 23902 |
var endRow = fold.end.row; |
| 23903 |
var endColumn = fold.end.column; |
| 23904 |
if (!(startRow < endRow || |
| 23905 |
startRow == endRow && startColumn <= endColumn - 2)) |
| 23906 |
throw new Error("The range has to be at least 2 characters width"); |
| 23907 |
|
| 23908 |
var startFold = this.getFoldAt(startRow, startColumn, 1); |
| 23909 |
var endFold = this.getFoldAt(endRow, endColumn, -1); |
| 23910 |
if (startFold && endFold == startFold) |
| 23911 |
return startFold.addSubFold(fold); |
| 23912 |
|
| 23913 |
if (startFold && !startFold.range.isStart(startRow, startColumn)) |
| 23914 |
this.removeFold(startFold); |
| 23915 |
|
| 23916 |
if (endFold && !endFold.range.isEnd(endRow, endColumn)) |
| 23917 |
this.removeFold(endFold); |
| 23918 |
var folds = this.getFoldsInRange(fold.range); |
| 23919 |
if (folds.length > 0) { |
| 23920 |
this.removeFolds(folds); |
| 23921 |
folds.forEach(function(subFold) { |
| 23922 |
fold.addSubFold(subFold); |
| 23923 |
}); |
| 23924 |
} |
| 23925 |
|
| 23926 |
for (var i = 0; i < foldData.length; i++) { |
| 23927 |
var foldLine = foldData[i]; |
| 23928 |
if (endRow == foldLine.start.row) { |
| 23929 |
foldLine.addFold(fold); |
| 23930 |
added = true; |
| 23931 |
break; |
| 23932 |
} else if (startRow == foldLine.end.row) { |
| 23933 |
foldLine.addFold(fold); |
| 23934 |
added = true; |
| 23935 |
if (!fold.sameRow) { |
| 23936 |
var foldLineNext = foldData[i + 1]; |
| 23937 |
if (foldLineNext && foldLineNext.start.row == endRow) { |
| 23938 |
foldLine.merge(foldLineNext); |
| 23939 |
break; |
| 23940 |
} |
| 23941 |
} |
| 23942 |
break; |
| 23943 |
} else if (endRow <= foldLine.start.row) { |
| 23944 |
break; |
| 23945 |
} |
| 23946 |
} |
| 23947 |
|
| 23948 |
if (!added) |
| 23949 |
foldLine = this.$addFoldLine(new FoldLine(this.$foldData, fold)); |
| 23950 |
|
| 23951 |
if (this.$useWrapMode) |
| 23952 |
this.$updateWrapData(foldLine.start.row, foldLine.start.row); |
| 23953 |
else |
| 23954 |
this.$updateRowLengthCache(foldLine.start.row, foldLine.start.row); |
| 23955 |
this.$modified = true; |
| 23956 |
this._signal("changeFold", { data: fold, action: "add" }); |
| 23957 |
|
| 23958 |
return fold; |
| 23959 |
}; |
| 23960 |
|
| 23961 |
this.addFolds = function(folds) { |
| 23962 |
folds.forEach(function(fold) { |
| 23963 |
this.addFold(fold); |
| 23964 |
}, this); |
| 23965 |
}; |
| 23966 |
|
| 23967 |
this.removeFold = function(fold) { |
| 23968 |
var foldLine = fold.foldLine; |
| 23969 |
var startRow = foldLine.start.row; |
| 23970 |
var endRow = foldLine.end.row; |
| 23971 |
|
| 23972 |
var foldLines = this.$foldData; |
| 23973 |
var folds = foldLine.folds; |
| 23974 |
if (folds.length == 1) { |
| 23975 |
foldLines.splice(foldLines.indexOf(foldLine), 1); |
| 23976 |
} else |
| 23977 |
if (foldLine.range.isEnd(fold.end.row, fold.end.column)) { |
| 23978 |
folds.pop(); |
| 23979 |
foldLine.end.row = folds[folds.length - 1].end.row; |
| 23980 |
foldLine.end.column = folds[folds.length - 1].end.column; |
| 23981 |
} else |
| 23982 |
if (foldLine.range.isStart(fold.start.row, fold.start.column)) { |
| 23983 |
folds.shift(); |
| 23984 |
foldLine.start.row = folds[0].start.row; |
| 23985 |
foldLine.start.column = folds[0].start.column; |
| 23986 |
} else |
| 23987 |
if (fold.sameRow) { |
| 23988 |
folds.splice(folds.indexOf(fold), 1); |
| 23989 |
} else |
| 23990 |
{ |
| 23991 |
var newFoldLine = foldLine.split(fold.start.row, fold.start.column); |
| 23992 |
folds = newFoldLine.folds; |
| 23993 |
folds.shift(); |
| 23994 |
newFoldLine.start.row = folds[0].start.row; |
| 23995 |
newFoldLine.start.column = folds[0].start.column; |
| 23996 |
} |
| 23997 |
|
| 23998 |
if (!this.$updating) { |
| 23999 |
if (this.$useWrapMode) |
| 24000 |
this.$updateWrapData(startRow, endRow); |
| 24001 |
else |
| 24002 |
this.$updateRowLengthCache(startRow, endRow); |
| 24003 |
} |
| 24004 |
this.$modified = true; |
| 24005 |
this._signal("changeFold", { data: fold, action: "remove" }); |
| 24006 |
}; |
| 24007 |
|
| 24008 |
this.removeFolds = function(folds) { |
| 24009 |
var cloneFolds = []; |
| 24010 |
for (var i = 0; i < folds.length; i++) { |
| 24011 |
cloneFolds.push(folds[i]); |
| 24012 |
} |
| 24013 |
|
| 24014 |
cloneFolds.forEach(function(fold) { |
| 24015 |
this.removeFold(fold); |
| 24016 |
}, this); |
| 24017 |
this.$modified = true; |
| 24018 |
}; |
| 24019 |
|
| 24020 |
this.expandFold = function(fold) { |
| 24021 |
this.removeFold(fold); |
| 24022 |
fold.subFolds.forEach(function(subFold) { |
| 24023 |
fold.restoreRange(subFold); |
| 24024 |
this.addFold(subFold); |
| 24025 |
}, this); |
| 24026 |
if (fold.collapseChildren > 0) { |
| 24027 |
this.foldAll(fold.start.row+1, fold.end.row, fold.collapseChildren-1); |
| 24028 |
} |
| 24029 |
fold.subFolds = []; |
| 24030 |
}; |
| 24031 |
|
| 24032 |
this.expandFolds = function(folds) { |
| 24033 |
folds.forEach(function(fold) { |
| 24034 |
this.expandFold(fold); |
| 24035 |
}, this); |
| 24036 |
}; |
| 24037 |
|
| 24038 |
this.unfold = function(location, expandInner) { |
| 24039 |
var range, folds; |
| 24040 |
if (location == null) { |
| 24041 |
range = new Range(0, 0, this.getLength(), 0); |
| 24042 |
expandInner = true; |
| 24043 |
} else if (typeof location == "number") |
| 24044 |
range = new Range(location, 0, location, this.getLine(location).length); |
| 24045 |
else if ("row" in location) |
| 24046 |
range = Range.fromPoints(location, location); |
| 24047 |
else |
| 24048 |
range = location; |
| 24049 |
|
| 24050 |
folds = this.getFoldsInRangeList(range); |
| 24051 |
if (expandInner) { |
| 24052 |
this.removeFolds(folds); |
| 24053 |
} else { |
| 24054 |
var subFolds = folds; |
| 24055 |
while (subFolds.length) { |
| 24056 |
this.expandFolds(subFolds); |
| 24057 |
subFolds = this.getFoldsInRangeList(range); |
| 24058 |
} |
| 24059 |
} |
| 24060 |
if (folds.length) |
| 24061 |
return folds; |
| 24062 |
}; |
| 24063 |
this.isRowFolded = function(docRow, startFoldRow) { |
| 24064 |
return !!this.getFoldLine(docRow, startFoldRow); |
| 24065 |
}; |
| 24066 |
|
| 24067 |
this.getRowFoldEnd = function(docRow, startFoldRow) { |
| 24068 |
var foldLine = this.getFoldLine(docRow, startFoldRow); |
| 24069 |
return foldLine ? foldLine.end.row : docRow; |
| 24070 |
}; |
| 24071 |
|
| 24072 |
this.getRowFoldStart = function(docRow, startFoldRow) { |
| 24073 |
var foldLine = this.getFoldLine(docRow, startFoldRow); |
| 24074 |
return foldLine ? foldLine.start.row : docRow; |
| 24075 |
}; |
| 24076 |
|
| 24077 |
this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) { |
| 24078 |
if (startRow == null) |
| 24079 |
startRow = foldLine.start.row; |
| 24080 |
if (startColumn == null) |
| 24081 |
startColumn = 0; |
| 24082 |
if (endRow == null) |
| 24083 |
endRow = foldLine.end.row; |
| 24084 |
if (endColumn == null) |
| 24085 |
endColumn = this.getLine(endRow).length; |
| 24086 |
var doc = this.doc; |
| 24087 |
var textLine = ""; |
| 24088 |
|
| 24089 |
foldLine.walk(function(placeholder, row, column, lastColumn) { |
| 24090 |
if (row < startRow) |
| 24091 |
return; |
| 24092 |
if (row == startRow) { |
| 24093 |
if (column < startColumn) |
| 24094 |
return; |
| 24095 |
lastColumn = Math.max(startColumn, lastColumn); |
| 24096 |
} |
| 24097 |
|
| 24098 |
if (placeholder != null) { |
| 24099 |
textLine += placeholder; |
| 24100 |
} else { |
| 24101 |
textLine += doc.getLine(row).substring(lastColumn, column); |
| 24102 |
} |
| 24103 |
}, endRow, endColumn); |
| 24104 |
return textLine; |
| 24105 |
}; |
| 24106 |
|
| 24107 |
this.getDisplayLine = function(row, endColumn, startRow, startColumn) { |
| 24108 |
var foldLine = this.getFoldLine(row); |
| 24109 |
|
| 24110 |
if (!foldLine) { |
| 24111 |
var line; |
| 24112 |
line = this.doc.getLine(row); |
| 24113 |
return line.substring(startColumn || 0, endColumn || line.length); |
| 24114 |
} else { |
| 24115 |
return this.getFoldDisplayLine( |
| 24116 |
foldLine, row, endColumn, startRow, startColumn); |
| 24117 |
} |
| 24118 |
}; |
| 24119 |
|
| 24120 |
this.$cloneFoldData = function() { |
| 24121 |
var fd = []; |
| 24122 |
fd = this.$foldData.map(function(foldLine) { |
| 24123 |
var folds = foldLine.folds.map(function(fold) { |
| 24124 |
return fold.clone(); |
| 24125 |
}); |
| 24126 |
return new FoldLine(fd, folds); |
| 24127 |
}); |
| 24128 |
|
| 24129 |
return fd; |
| 24130 |
}; |
| 24131 |
|
| 24132 |
this.toggleFold = function(tryToUnfold) { |
| 24133 |
var selection = this.selection; |
| 24134 |
var range = selection.getRange(); |
| 24135 |
var fold; |
| 24136 |
var bracketPos; |
| 24137 |
|
| 24138 |
if (range.isEmpty()) { |
| 24139 |
var cursor = range.start; |
| 24140 |
fold = this.getFoldAt(cursor.row, cursor.column); |
| 24141 |
|
| 24142 |
if (fold) { |
| 24143 |
this.expandFold(fold); |
| 24144 |
return; |
| 24145 |
} else if (bracketPos = this.findMatchingBracket(cursor)) { |
| 24146 |
if (range.comparePoint(bracketPos) == 1) { |
| 24147 |
range.end = bracketPos; |
| 24148 |
} else { |
| 24149 |
range.start = bracketPos; |
| 24150 |
range.start.column++; |
| 24151 |
range.end.column--; |
| 24152 |
} |
| 24153 |
} else if (bracketPos = this.findMatchingBracket({row: cursor.row, column: cursor.column + 1})) { |
| 24154 |
if (range.comparePoint(bracketPos) == 1) |
| 24155 |
range.end = bracketPos; |
| 24156 |
else |
| 24157 |
range.start = bracketPos; |
| 24158 |
|
| 24159 |
range.start.column++; |
| 24160 |
} else { |
| 24161 |
range = this.getCommentFoldRange(cursor.row, cursor.column) || range; |
| 24162 |
} |
| 24163 |
} else { |
| 24164 |
var folds = this.getFoldsInRange(range); |
| 24165 |
if (tryToUnfold && folds.length) { |
| 24166 |
this.expandFolds(folds); |
| 24167 |
return; |
| 24168 |
} else if (folds.length == 1 ) { |
| 24169 |
fold = folds[0]; |
| 24170 |
} |
| 24171 |
} |
| 24172 |
|
| 24173 |
if (!fold) |
| 24174 |
fold = this.getFoldAt(range.start.row, range.start.column); |
| 24175 |
|
| 24176 |
if (fold && fold.range.toString() == range.toString()) { |
| 24177 |
this.expandFold(fold); |
| 24178 |
return; |
| 24179 |
} |
| 24180 |
|
| 24181 |
var placeholder = "..."; |
| 24182 |
if (!range.isMultiLine()) { |
| 24183 |
placeholder = this.getTextRange(range); |
| 24184 |
if (placeholder.length < 4) |
| 24185 |
return; |
| 24186 |
placeholder = placeholder.trim().substring(0, 2) + ".."; |
| 24187 |
} |
| 24188 |
|
| 24189 |
this.addFold(placeholder, range); |
| 24190 |
}; |
| 24191 |
|
| 24192 |
this.getCommentFoldRange = function(row, column, dir) { |
| 24193 |
var iterator = new TokenIterator(this, row, column); |
| 24194 |
var token = iterator.getCurrentToken(); |
| 24195 |
if (token && /^comment|string/.test(token.type)) { |
| 24196 |
var range = new Range(); |
| 24197 |
var re = new RegExp(token.type.replace(/\..*/, "\\.")); |
| 24198 |
if (dir != 1) { |
| 24199 |
do { |
| 24200 |
token = iterator.stepBackward(); |
| 24201 |
} while (token && re.test(token.type)); |
| 24202 |
iterator.stepForward(); |
| 24203 |
} |
| 24204 |
|
| 24205 |
range.start.row = iterator.getCurrentTokenRow(); |
| 24206 |
range.start.column = iterator.getCurrentTokenColumn() + 2; |
| 24207 |
|
| 24208 |
iterator = new TokenIterator(this, row, column); |
| 24209 |
|
| 24210 |
if (dir != -1) { |
| 24211 |
do { |
| 24212 |
token = iterator.stepForward(); |
| 24213 |
} while (token && re.test(token.type)); |
| 24214 |
token = iterator.stepBackward(); |
| 24215 |
} else |
| 24216 |
token = iterator.getCurrentToken(); |
| 24217 |
|
| 24218 |
range.end.row = iterator.getCurrentTokenRow(); |
| 24219 |
range.end.column = iterator.getCurrentTokenColumn() + token.value.length - 2; |
| 24220 |
return range; |
| 24221 |
} |
| 24222 |
}; |
| 24223 |
|
| 24224 |
this.foldAll = function(startRow, endRow, depth) { |
| 24225 |
if (depth == undefined) |
| 24226 |
depth = 100000; // JSON.stringify doesn't hanle Infinity |
| 24227 |
var foldWidgets = this.foldWidgets; |
| 24228 |
if (!foldWidgets) |
| 24229 |
return; // mode doesn't support folding |
| 24230 |
endRow = endRow || this.getLength(); |
| 24231 |
startRow = startRow || 0; |
| 24232 |
for (var row = startRow; row < endRow; row++) { |
| 24233 |
if (foldWidgets[row] == null) |
| 24234 |
foldWidgets[row] = this.getFoldWidget(row); |
| 24235 |
if (foldWidgets[row] != "start") |
| 24236 |
continue; |
| 24237 |
|
| 24238 |
var range = this.getFoldWidgetRange(row); |
| 24239 |
if (range && range.isMultiLine() |
| 24240 |
&& range.end.row <= endRow |
| 24241 |
&& range.start.row >= startRow |
| 24242 |
) { |
| 24243 |
row = range.end.row; |
| 24244 |
try { |
| 24245 |
var fold = this.addFold("...", range); |
| 24246 |
if (fold) |
| 24247 |
fold.collapseChildren = depth; |
| 24248 |
} catch(e) {} |
| 24249 |
} |
| 24250 |
} |
| 24251 |
}; |
| 24252 |
this.$foldStyles = { |
| 24253 |
"manual": 1, |
| 24254 |
"markbegin": 1, |
| 24255 |
"markbeginend": 1 |
| 24256 |
}; |
| 24257 |
this.$foldStyle = "markbegin"; |
| 24258 |
this.setFoldStyle = function(style) { |
| 24259 |
if (!this.$foldStyles[style]) |
| 24260 |
throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]"); |
| 24261 |
|
| 24262 |
if (this.$foldStyle == style) |
| 24263 |
return; |
| 24264 |
|
| 24265 |
this.$foldStyle = style; |
| 24266 |
|
| 24267 |
if (style == "manual") |
| 24268 |
this.unfold(); |
| 24269 |
var mode = this.$foldMode; |
| 24270 |
this.$setFolding(null); |
| 24271 |
this.$setFolding(mode); |
| 24272 |
}; |
| 24273 |
|
| 24274 |
this.$setFolding = function(foldMode) { |
| 24275 |
if (this.$foldMode == foldMode) |
| 24276 |
return; |
| 24277 |
|
| 24278 |
this.$foldMode = foldMode; |
| 24279 |
|
| 24280 |
this.off('change', this.$updateFoldWidgets); |
| 24281 |
this.off('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets); |
| 24282 |
this._signal("changeAnnotation"); |
| 24283 |
|
| 24284 |
if (!foldMode || this.$foldStyle == "manual") { |
| 24285 |
this.foldWidgets = null; |
| 24286 |
return; |
| 24287 |
} |
| 24288 |
|
| 24289 |
this.foldWidgets = []; |
| 24290 |
this.getFoldWidget = foldMode.getFoldWidget.bind(foldMode, this, this.$foldStyle); |
| 24291 |
this.getFoldWidgetRange = foldMode.getFoldWidgetRange.bind(foldMode, this, this.$foldStyle); |
| 24292 |
|
| 24293 |
this.$updateFoldWidgets = this.updateFoldWidgets.bind(this); |
| 24294 |
this.$tokenizerUpdateFoldWidgets = this.tokenizerUpdateFoldWidgets.bind(this); |
| 24295 |
this.on('change', this.$updateFoldWidgets); |
| 24296 |
this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets); |
| 24297 |
}; |
| 24298 |
|
| 24299 |
this.getParentFoldRangeData = function (row, ignoreCurrent) { |
| 24300 |
var fw = this.foldWidgets; |
| 24301 |
if (!fw || (ignoreCurrent && fw[row])) |
| 24302 |
return {}; |
| 24303 |
|
| 24304 |
var i = row - 1, firstRange; |
| 24305 |
while (i >= 0) { |
| 24306 |
var c = fw[i]; |
| 24307 |
if (c == null) |
| 24308 |
c = fw[i] = this.getFoldWidget(i); |
| 24309 |
|
| 24310 |
if (c == "start") { |
| 24311 |
var range = this.getFoldWidgetRange(i); |
| 24312 |
if (!firstRange) |
| 24313 |
firstRange = range; |
| 24314 |
if (range && range.end.row >= row) |
| 24315 |
break; |
| 24316 |
} |
| 24317 |
i--; |
| 24318 |
} |
| 24319 |
|
| 24320 |
return { |
| 24321 |
range: i !== -1 && range, |
| 24322 |
firstRange: firstRange |
| 24323 |
}; |
| 24324 |
}; |
| 24325 |
|
| 24326 |
this.onFoldWidgetClick = function(row, e) { |
| 24327 |
e = e.domEvent; |
| 24328 |
var options = { |
| 24329 |
children: e.shiftKey, |
| 24330 |
all: e.ctrlKey || e.metaKey, |
| 24331 |
siblings: e.altKey |
| 24332 |
}; |
| 24333 |
|
| 24334 |
var range = this.$toggleFoldWidget(row, options); |
| 24335 |
if (!range) { |
| 24336 |
var el = (e.target || e.srcElement); |
| 24337 |
if (el && /ace_fold-widget/.test(el.className)) |
| 24338 |
el.className += " ace_invalid"; |
| 24339 |
} |
| 24340 |
}; |
| 24341 |
|
| 24342 |
this.$toggleFoldWidget = function(row, options) { |
| 24343 |
if (!this.getFoldWidget) |
| 24344 |
return; |
| 24345 |
var type = this.getFoldWidget(row); |
| 24346 |
var line = this.getLine(row); |
| 24347 |
|
| 24348 |
var dir = type === "end" ? -1 : 1; |
| 24349 |
var fold = this.getFoldAt(row, dir === -1 ? 0 : line.length, dir); |
| 24350 |
|
| 24351 |
if (fold) { |
| 24352 |
if (options.children || options.all) |
| 24353 |
this.removeFold(fold); |
| 24354 |
else |
| 24355 |
this.expandFold(fold); |
| 24356 |
return; |
| 24357 |
} |
| 24358 |
|
| 24359 |
var range = this.getFoldWidgetRange(row, true); |
| 24360 |
if (range && !range.isMultiLine()) { |
| 24361 |
fold = this.getFoldAt(range.start.row, range.start.column, 1); |
| 24362 |
if (fold && range.isEqual(fold.range)) { |
| 24363 |
this.removeFold(fold); |
| 24364 |
return; |
| 24365 |
} |
| 24366 |
} |
| 24367 |
|
| 24368 |
if (options.siblings) { |
| 24369 |
var data = this.getParentFoldRangeData(row); |
| 24370 |
if (data.range) { |
| 24371 |
var startRow = data.range.start.row + 1; |
| 24372 |
var endRow = data.range.end.row; |
| 24373 |
} |
| 24374 |
this.foldAll(startRow, endRow, options.all ? 10000 : 0); |
| 24375 |
} else if (options.children) { |
| 24376 |
endRow = range ? range.end.row : this.getLength(); |
| 24377 |
this.foldAll(row + 1, endRow, options.all ? 10000 : 0); |
| 24378 |
} else if (range) { |
| 24379 |
if (options.all) |
| 24380 |
range.collapseChildren = 10000; |
| 24381 |
this.addFold("...", range); |
| 24382 |
} |
| 24383 |
|
| 24384 |
return range; |
| 24385 |
}; |
| 24386 |
|
| 24387 |
|
| 24388 |
|
| 24389 |
this.toggleFoldWidget = function(toggleParent) { |
| 24390 |
var row = this.selection.getCursor().row; |
| 24391 |
row = this.getRowFoldStart(row); |
| 24392 |
var range = this.$toggleFoldWidget(row, {}); |
| 24393 |
|
| 24394 |
if (range) |
| 24395 |
return; |
| 24396 |
var data = this.getParentFoldRangeData(row, true); |
| 24397 |
range = data.range || data.firstRange; |
| 24398 |
|
| 24399 |
if (range) { |
| 24400 |
row = range.start.row; |
| 24401 |
var fold = this.getFoldAt(row, this.getLine(row).length, 1); |
| 24402 |
|
| 24403 |
if (fold) { |
| 24404 |
this.removeFold(fold); |
| 24405 |
} else { |
| 24406 |
this.addFold("...", range); |
| 24407 |
} |
| 24408 |
} |
| 24409 |
}; |
| 24410 |
|
| 24411 |
this.updateFoldWidgets = function(delta) { |
| 24412 |
var firstRow = delta.start.row; |
| 24413 |
var len = delta.end.row - firstRow; |
| 24414 |
|
| 24415 |
if (len === 0) { |
| 24416 |
this.foldWidgets[firstRow] = null; |
| 24417 |
} else if (delta.action == 'remove') { |
| 24418 |
this.foldWidgets.splice(firstRow, len + 1, null); |
| 24419 |
} else { |
| 24420 |
var args = Array(len + 1); |
| 24421 |
args.unshift(firstRow, 1); |
| 24422 |
this.foldWidgets.splice.apply(this.foldWidgets, args); |
| 24423 |
} |
| 24424 |
}; |
| 24425 |
this.tokenizerUpdateFoldWidgets = function(e) { |
| 24426 |
var rows = e.data; |
| 24427 |
if (rows.first != rows.last) { |
| 24428 |
if (this.foldWidgets.length > rows.first) |
| 24429 |
this.foldWidgets.splice(rows.first, this.foldWidgets.length); |
| 24430 |
} |
| 24431 |
}; |
| 24432 |
} |
| 24433 |
|
| 24434 |
exports.Folding = Folding; |
| 24435 |
|
| 24436 |
}); |
| 24437 |
|
| 24438 |
ace.define("ace/edit_session/bracket_match",["require","exports","module","ace/token_iterator","ace/range"], function(acequire, exports, module) { |
| 24439 |
"use strict"; |
| 24440 |
|
| 24441 |
var TokenIterator = acequire("../token_iterator").TokenIterator; |
| 24442 |
var Range = acequire("../range").Range; |
| 24443 |
|
| 24444 |
|
| 24445 |
function BracketMatch() { |
| 24446 |
|
| 24447 |
this.findMatchingBracket = function(position, chr) { |
| 24448 |
if (position.column == 0) return null; |
| 24449 |
|
| 24450 |
var charBeforeCursor = chr || this.getLine(position.row).charAt(position.column-1); |
| 24451 |
if (charBeforeCursor == "") return null; |
| 24452 |
|
| 24453 |
var match = charBeforeCursor.match(/([\(\[\{])|([\)\]\}])/); |
| 24454 |
if (!match) |
| 24455 |
return null; |
| 24456 |
|
| 24457 |
if (match[1]) |
| 24458 |
return this.$findClosingBracket(match[1], position); |
| 24459 |
else |
| 24460 |
return this.$findOpeningBracket(match[2], position); |
| 24461 |
}; |
| 24462 |
|
| 24463 |
this.getBracketRange = function(pos) { |
| 24464 |
var line = this.getLine(pos.row); |
| 24465 |
var before = true, range; |
| 24466 |
|
| 24467 |
var chr = line.charAt(pos.column-1); |
| 24468 |
var match = chr && chr.match(/([\(\[\{])|([\)\]\}])/); |
| 24469 |
if (!match) { |
| 24470 |
chr = line.charAt(pos.column); |
| 24471 |
pos = {row: pos.row, column: pos.column + 1}; |
| 24472 |
match = chr && chr.match(/([\(\[\{])|([\)\]\}])/); |
| 24473 |
before = false; |
| 24474 |
} |
| 24475 |
if (!match) |
| 24476 |
return null; |
| 24477 |
|
| 24478 |
if (match[1]) { |
| 24479 |
var bracketPos = this.$findClosingBracket(match[1], pos); |
| 24480 |
if (!bracketPos) |
| 24481 |
return null; |
| 24482 |
range = Range.fromPoints(pos, bracketPos); |
| 24483 |
if (!before) { |
| 24484 |
range.end.column++; |
| 24485 |
range.start.column--; |
| 24486 |
} |
| 24487 |
range.cursor = range.end; |
| 24488 |
} else { |
| 24489 |
var bracketPos = this.$findOpeningBracket(match[2], pos); |
| 24490 |
if (!bracketPos) |
| 24491 |
return null; |
| 24492 |
range = Range.fromPoints(bracketPos, pos); |
| 24493 |
if (!before) { |
| 24494 |
range.start.column++; |
| 24495 |
range.end.column--; |
| 24496 |
} |
| 24497 |
range.cursor = range.start; |
| 24498 |
} |
| 24499 |
|
| 24500 |
return range; |
| 24501 |
}; |
| 24502 |
|
| 24503 |
this.$brackets = { |
| 24504 |
")": "(", |
| 24505 |
"(": ")", |
| 24506 |
"]": "[", |
| 24507 |
"[": "]", |
| 24508 |
"{": "}", |
| 24509 |
"}": "{" |
| 24510 |
}; |
| 24511 |
|
| 24512 |
this.$findOpeningBracket = function(bracket, position, typeRe) { |
| 24513 |
var openBracket = this.$brackets[bracket]; |
| 24514 |
var depth = 1; |
| 24515 |
|
| 24516 |
var iterator = new TokenIterator(this, position.row, position.column); |
| 24517 |
var token = iterator.getCurrentToken(); |
| 24518 |
if (!token) |
| 24519 |
token = iterator.stepForward(); |
| 24520 |
if (!token) |
| 24521 |
return; |
| 24522 |
|
| 24523 |
if (!typeRe){ |
| 24524 |
typeRe = new RegExp( |
| 24525 |
"(\\.?" + |
| 24526 |
token.type.replace(".", "\\.").replace("rparen", ".paren") |
| 24527 |
.replace(/\b(?:end)\b/, "(?:start|begin|end)") |
| 24528 |
+ ")+" |
| 24529 |
); |
| 24530 |
} |
| 24531 |
var valueIndex = position.column - iterator.getCurrentTokenColumn() - 2; |
| 24532 |
var value = token.value; |
| 24533 |
|
| 24534 |
while (true) { |
| 24535 |
|
| 24536 |
while (valueIndex >= 0) { |
| 24537 |
var chr = value.charAt(valueIndex); |
| 24538 |
if (chr == openBracket) { |
| 24539 |
depth -= 1; |
| 24540 |
if (depth == 0) { |
| 24541 |
return {row: iterator.getCurrentTokenRow(), |
| 24542 |
column: valueIndex + iterator.getCurrentTokenColumn()}; |
| 24543 |
} |
| 24544 |
} |
| 24545 |
else if (chr == bracket) { |
| 24546 |
depth += 1; |
| 24547 |
} |
| 24548 |
valueIndex -= 1; |
| 24549 |
} |
| 24550 |
do { |
| 24551 |
token = iterator.stepBackward(); |
| 24552 |
} while (token && !typeRe.test(token.type)); |
| 24553 |
|
| 24554 |
if (token == null) |
| 24555 |
break; |
| 24556 |
|
| 24557 |
value = token.value; |
| 24558 |
valueIndex = value.length - 1; |
| 24559 |
} |
| 24560 |
|
| 24561 |
return null; |
| 24562 |
}; |
| 24563 |
|
| 24564 |
this.$findClosingBracket = function(bracket, position, typeRe) { |
| 24565 |
var closingBracket = this.$brackets[bracket]; |
| 24566 |
var depth = 1; |
| 24567 |
|
| 24568 |
var iterator = new TokenIterator(this, position.row, position.column); |
| 24569 |
var token = iterator.getCurrentToken(); |
| 24570 |
if (!token) |
| 24571 |
token = iterator.stepForward(); |
| 24572 |
if (!token) |
| 24573 |
return; |
| 24574 |
|
| 24575 |
if (!typeRe){ |
| 24576 |
typeRe = new RegExp( |
| 24577 |
"(\\.?" + |
| 24578 |
token.type.replace(".", "\\.").replace("lparen", ".paren") |
| 24579 |
.replace(/\b(?:start|begin)\b/, "(?:start|begin|end)") |
| 24580 |
+ ")+" |
| 24581 |
); |
| 24582 |
} |
| 24583 |
var valueIndex = position.column - iterator.getCurrentTokenColumn(); |
| 24584 |
|
| 24585 |
while (true) { |
| 24586 |
|
| 24587 |
var value = token.value; |
| 24588 |
var valueLength = value.length; |
| 24589 |
while (valueIndex < valueLength) { |
| 24590 |
var chr = value.charAt(valueIndex); |
| 24591 |
if (chr == closingBracket) { |
| 24592 |
depth -= 1; |
| 24593 |
if (depth == 0) { |
| 24594 |
return {row: iterator.getCurrentTokenRow(), |
| 24595 |
column: valueIndex + iterator.getCurrentTokenColumn()}; |
| 24596 |
} |
| 24597 |
} |
| 24598 |
else if (chr == bracket) { |
| 24599 |
depth += 1; |
| 24600 |
} |
| 24601 |
valueIndex += 1; |
| 24602 |
} |
| 24603 |
do { |
| 24604 |
token = iterator.stepForward(); |
| 24605 |
} while (token && !typeRe.test(token.type)); |
| 24606 |
|
| 24607 |
if (token == null) |
| 24608 |
break; |
| 24609 |
|
| 24610 |
valueIndex = 0; |
| 24611 |
} |
| 24612 |
|
| 24613 |
return null; |
| 24614 |
}; |
| 24615 |
} |
| 24616 |
exports.BracketMatch = BracketMatch; |
| 24617 |
|
| 24618 |
}); |
| 24619 |
|
| 24620 |
ace.define("ace/edit_session",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/config","ace/lib/event_emitter","ace/selection","ace/mode/text","ace/range","ace/document","ace/background_tokenizer","ace/search_highlight","ace/edit_session/folding","ace/edit_session/bracket_match"], function(acequire, exports, module) { |
| 24621 |
"use strict"; |
| 24622 |
|
| 24623 |
var oop = acequire("./lib/oop"); |
| 24624 |
var lang = acequire("./lib/lang"); |
| 24625 |
var config = acequire("./config"); |
| 24626 |
var EventEmitter = acequire("./lib/event_emitter").EventEmitter; |
| 24627 |
var Selection = acequire("./selection").Selection; |
| 24628 |
var TextMode = acequire("./mode/text").Mode; |
| 24629 |
var Range = acequire("./range").Range; |
| 24630 |
var Document = acequire("./document").Document; |
| 24631 |
var BackgroundTokenizer = acequire("./background_tokenizer").BackgroundTokenizer; |
| 24632 |
var SearchHighlight = acequire("./search_highlight").SearchHighlight; |
| 24633 |
|
| 24634 |
var EditSession = function(text, mode) { |
| 24635 |
this.$breakpoints = []; |
| 24636 |
this.$decorations = []; |
| 24637 |
this.$frontMarkers = {}; |
| 24638 |
this.$backMarkers = {}; |
| 24639 |
this.$markerId = 1; |
| 24640 |
this.$undoSelect = true; |
| 24641 |
|
| 24642 |
this.$foldData = []; |
| 24643 |
this.$foldData.toString = function() { |
| 24644 |
return this.join("\n"); |
| 24645 |
}; |
| 24646 |
this.on("changeFold", this.onChangeFold.bind(this)); |
| 24647 |
this.$onChange = this.onChange.bind(this); |
| 24648 |
|
| 24649 |
if (typeof text != "object" || !text.getLine) |
| 24650 |
text = new Document(text); |
| 24651 |
|
| 24652 |
this.setDocument(text); |
| 24653 |
this.selection = new Selection(this); |
| 24654 |
|
| 24655 |
config.resetOptions(this); |
| 24656 |
this.setMode(mode); |
| 24657 |
config._signal("session", this); |
| 24658 |
}; |
| 24659 |
|
| 24660 |
|
| 24661 |
(function() { |
| 24662 |
|
| 24663 |
oop.implement(this, EventEmitter); |
| 24664 |
this.setDocument = function(doc) { |
| 24665 |
if (this.doc) |
| 24666 |
this.doc.removeListener("change", this.$onChange); |
| 24667 |
|
| 24668 |
this.doc = doc; |
| 24669 |
doc.on("change", this.$onChange); |
| 24670 |
|
| 24671 |
if (this.bgTokenizer) |
| 24672 |
this.bgTokenizer.setDocument(this.getDocument()); |
| 24673 |
|
| 24674 |
this.resetCaches(); |
| 24675 |
}; |
| 24676 |
this.getDocument = function() { |
| 24677 |
return this.doc; |
| 24678 |
}; |
| 24679 |
this.$resetRowCache = function(docRow) { |
| 24680 |
if (!docRow) { |
| 24681 |
this.$docRowCache = []; |
| 24682 |
this.$screenRowCache = []; |
| 24683 |
return; |
| 24684 |
} |
| 24685 |
var l = this.$docRowCache.length; |
| 24686 |
var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1; |
| 24687 |
if (l > i) { |
| 24688 |
this.$docRowCache.splice(i, l); |
| 24689 |
this.$screenRowCache.splice(i, l); |
| 24690 |
} |
| 24691 |
}; |
| 24692 |
|
| 24693 |
this.$getRowCacheIndex = function(cacheArray, val) { |
| 24694 |
var low = 0; |
| 24695 |
var hi = cacheArray.length - 1; |
| 24696 |
|
| 24697 |
while (low <= hi) { |
| 24698 |
var mid = (low + hi) >> 1; |
| 24699 |
var c = cacheArray[mid]; |
| 24700 |
|
| 24701 |
if (val > c) |
| 24702 |
low = mid + 1; |
| 24703 |
else if (val < c) |
| 24704 |
hi = mid - 1; |
| 24705 |
else |
| 24706 |
return mid; |
| 24707 |
} |
| 24708 |
|
| 24709 |
return low -1; |
| 24710 |
}; |
| 24711 |
|
| 24712 |
this.resetCaches = function() { |
| 24713 |
this.$modified = true; |
| 24714 |
this.$wrapData = []; |
| 24715 |
this.$rowLengthCache = []; |
| 24716 |
this.$resetRowCache(0); |
| 24717 |
if (this.bgTokenizer) |
| 24718 |
this.bgTokenizer.start(0); |
| 24719 |
}; |
| 24720 |
|
| 24721 |
this.onChangeFold = function(e) { |
| 24722 |
var fold = e.data; |
| 24723 |
this.$resetRowCache(fold.start.row); |
| 24724 |
}; |
| 24725 |
|
| 24726 |
this.onChange = function(delta) { |
| 24727 |
this.$modified = true; |
| 24728 |
|
| 24729 |
this.$resetRowCache(delta.start.row); |
| 24730 |
|
| 24731 |
var removedFolds = this.$updateInternalDataOnChange(delta); |
| 24732 |
if (!this.$fromUndo && this.$undoManager && !delta.ignore) { |
| 24733 |
this.$deltasDoc.push(delta); |
| 24734 |
if (removedFolds && removedFolds.length != 0) { |
| 24735 |
this.$deltasFold.push({ |
| 24736 |
action: "removeFolds", |
| 24737 |
folds: removedFolds |
| 24738 |
}); |
| 24739 |
} |
| 24740 |
|
| 24741 |
this.$informUndoManager.schedule(); |
| 24742 |
} |
| 24743 |
|
| 24744 |
this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta); |
| 24745 |
this._signal("change", delta); |
| 24746 |
}; |
| 24747 |
this.setValue = function(text) { |
| 24748 |
this.doc.setValue(text); |
| 24749 |
this.selection.moveTo(0, 0); |
| 24750 |
|
| 24751 |
this.$resetRowCache(0); |
| 24752 |
this.$deltas = []; |
| 24753 |
this.$deltasDoc = []; |
| 24754 |
this.$deltasFold = []; |
| 24755 |
this.setUndoManager(this.$undoManager); |
| 24756 |
this.getUndoManager().reset(); |
| 24757 |
}; |
| 24758 |
this.getValue = |
| 24759 |
this.toString = function() { |
| 24760 |
return this.doc.getValue(); |
| 24761 |
}; |
| 24762 |
this.getSelection = function() { |
| 24763 |
return this.selection; |
| 24764 |
}; |
| 24765 |
this.getState = function(row) { |
| 24766 |
return this.bgTokenizer.getState(row); |
| 24767 |
}; |
| 24768 |
this.getTokens = function(row) { |
| 24769 |
return this.bgTokenizer.getTokens(row); |
| 24770 |
}; |
| 24771 |
this.getTokenAt = function(row, column) { |
| 24772 |
var tokens = this.bgTokenizer.getTokens(row); |
| 24773 |
var token, c = 0; |
| 24774 |
if (column == null) { |
| 24775 |
i = tokens.length - 1; |
| 24776 |
c = this.getLine(row).length; |
| 24777 |
} else { |
| 24778 |
for (var i = 0; i < tokens.length; i++) { |
| 24779 |
c += tokens[i].value.length; |
| 24780 |
if (c >= column) |
| 24781 |
break; |
| 24782 |
} |
| 24783 |
} |
| 24784 |
token = tokens[i]; |
| 24785 |
if (!token) |
| 24786 |
return null; |
| 24787 |
token.index = i; |
| 24788 |
token.start = c - token.value.length; |
| 24789 |
return token; |
| 24790 |
}; |
| 24791 |
this.setUndoManager = function(undoManager) { |
| 24792 |
this.$undoManager = undoManager; |
| 24793 |
this.$deltas = []; |
| 24794 |
this.$deltasDoc = []; |
| 24795 |
this.$deltasFold = []; |
| 24796 |
|
| 24797 |
if (this.$informUndoManager) |
| 24798 |
this.$informUndoManager.cancel(); |
| 24799 |
|
| 24800 |
if (undoManager) { |
| 24801 |
var self = this; |
| 24802 |
|
| 24803 |
this.$syncInformUndoManager = function() { |
| 24804 |
self.$informUndoManager.cancel(); |
| 24805 |
|
| 24806 |
if (self.$deltasFold.length) { |
| 24807 |
self.$deltas.push({ |
| 24808 |
group: "fold", |
| 24809 |
deltas: self.$deltasFold |
| 24810 |
}); |
| 24811 |
self.$deltasFold = []; |
| 24812 |
} |
| 24813 |
|
| 24814 |
if (self.$deltasDoc.length) { |
| 24815 |
self.$deltas.push({ |
| 24816 |
group: "doc", |
| 24817 |
deltas: self.$deltasDoc |
| 24818 |
}); |
| 24819 |
self.$deltasDoc = []; |
| 24820 |
} |
| 24821 |
|
| 24822 |
if (self.$deltas.length > 0) { |
| 24823 |
undoManager.execute({ |
| 24824 |
action: "aceupdate", |
| 24825 |
args: [self.$deltas, self], |
| 24826 |
merge: self.mergeUndoDeltas |
| 24827 |
}); |
| 24828 |
} |
| 24829 |
self.mergeUndoDeltas = false; |
| 24830 |
self.$deltas = []; |
| 24831 |
}; |
| 24832 |
this.$informUndoManager = lang.delayedCall(this.$syncInformUndoManager); |
| 24833 |
} |
| 24834 |
}; |
| 24835 |
this.markUndoGroup = function() { |
| 24836 |
if (this.$syncInformUndoManager) |
| 24837 |
this.$syncInformUndoManager(); |
| 24838 |
}; |
| 24839 |
|
| 24840 |
this.$defaultUndoManager = { |
| 24841 |
undo: function() {}, |
| 24842 |
redo: function() {}, |
| 24843 |
reset: function() {} |
| 24844 |
}; |
| 24845 |
this.getUndoManager = function() { |
| 24846 |
return this.$undoManager || this.$defaultUndoManager; |
| 24847 |
}; |
| 24848 |
this.getTabString = function() { |
| 24849 |
if (this.getUseSoftTabs()) { |
| 24850 |
return lang.stringRepeat(" ", this.getTabSize()); |
| 24851 |
} else { |
| 24852 |
return "\t"; |
| 24853 |
} |
| 24854 |
}; |
| 24855 |
this.setUseSoftTabs = function(val) { |
| 24856 |
this.setOption("useSoftTabs", val); |
| 24857 |
}; |
| 24858 |
this.getUseSoftTabs = function() { |
| 24859 |
return this.$useSoftTabs && !this.$mode.$indentWithTabs; |
| 24860 |
}; |
| 24861 |
this.setTabSize = function(tabSize) { |
| 24862 |
this.setOption("tabSize", tabSize); |
| 24863 |
}; |
| 24864 |
this.getTabSize = function() { |
| 24865 |
return this.$tabSize; |
| 24866 |
}; |
| 24867 |
this.isTabStop = function(position) { |
| 24868 |
return this.$useSoftTabs && (position.column % this.$tabSize === 0); |
| 24869 |
}; |
| 24870 |
|
| 24871 |
this.$overwrite = false; |
| 24872 |
this.setOverwrite = function(overwrite) { |
| 24873 |
this.setOption("overwrite", overwrite); |
| 24874 |
}; |
| 24875 |
this.getOverwrite = function() { |
| 24876 |
return this.$overwrite; |
| 24877 |
}; |
| 24878 |
this.toggleOverwrite = function() { |
| 24879 |
this.setOverwrite(!this.$overwrite); |
| 24880 |
}; |
| 24881 |
this.addGutterDecoration = function(row, className) { |
| 24882 |
if (!this.$decorations[row]) |
| 24883 |
this.$decorations[row] = ""; |
| 24884 |
this.$decorations[row] += " " + className; |
| 24885 |
this._signal("changeBreakpoint", {}); |
| 24886 |
}; |
| 24887 |
this.removeGutterDecoration = function(row, className) { |
| 24888 |
this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, ""); |
| 24889 |
this._signal("changeBreakpoint", {}); |
| 24890 |
}; |
| 24891 |
this.getBreakpoints = function() { |
| 24892 |
return this.$breakpoints; |
| 24893 |
}; |
| 24894 |
this.setBreakpoints = function(rows) { |
| 24895 |
this.$breakpoints = []; |
| 24896 |
for (var i=0; i<rows.length; i++) { |
| 24897 |
this.$breakpoints[rows[i]] = "ace_breakpoint"; |
| 24898 |
} |
| 24899 |
this._signal("changeBreakpoint", {}); |
| 24900 |
}; |
| 24901 |
this.clearBreakpoints = function() { |
| 24902 |
this.$breakpoints = []; |
| 24903 |
this._signal("changeBreakpoint", {}); |
| 24904 |
}; |
| 24905 |
this.setBreakpoint = function(row, className) { |
| 24906 |
if (className === undefined) |
| 24907 |
className = "ace_breakpoint"; |
| 24908 |
if (className) |
| 24909 |
this.$breakpoints[row] = className; |
| 24910 |
else |
| 24911 |
delete this.$breakpoints[row]; |
| 24912 |
this._signal("changeBreakpoint", {}); |
| 24913 |
}; |
| 24914 |
this.clearBreakpoint = function(row) { |
| 24915 |
delete this.$breakpoints[row]; |
| 24916 |
this._signal("changeBreakpoint", {}); |
| 24917 |
}; |
| 24918 |
this.addMarker = function(range, clazz, type, inFront) { |
| 24919 |
var id = this.$markerId++; |
| 24920 |
|
| 24921 |
var marker = { |
| 24922 |
range : range, |
| 24923 |
type : type || "line", |
| 24924 |
renderer: typeof type == "function" ? type : null, |
| 24925 |
clazz : clazz, |
| 24926 |
inFront: !!inFront, |
| 24927 |
id: id |
| 24928 |
}; |
| 24929 |
|
| 24930 |
if (inFront) { |
| 24931 |
this.$frontMarkers[id] = marker; |
| 24932 |
this._signal("changeFrontMarker"); |
| 24933 |
} else { |
| 24934 |
this.$backMarkers[id] = marker; |
| 24935 |
this._signal("changeBackMarker"); |
| 24936 |
} |
| 24937 |
|
| 24938 |
return id; |
| 24939 |
}; |
| 24940 |
this.addDynamicMarker = function(marker, inFront) { |
| 24941 |
if (!marker.update) |
| 24942 |
return; |
| 24943 |
var id = this.$markerId++; |
| 24944 |
marker.id = id; |
| 24945 |
marker.inFront = !!inFront; |
| 24946 |
|
| 24947 |
if (inFront) { |
| 24948 |
this.$frontMarkers[id] = marker; |
| 24949 |
this._signal("changeFrontMarker"); |
| 24950 |
} else { |
| 24951 |
this.$backMarkers[id] = marker; |
| 24952 |
this._signal("changeBackMarker"); |
| 24953 |
} |
| 24954 |
|
| 24955 |
return marker; |
| 24956 |
}; |
| 24957 |
this.removeMarker = function(markerId) { |
| 24958 |
var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId]; |
| 24959 |
if (!marker) |
| 24960 |
return; |
| 24961 |
|
| 24962 |
var markers = marker.inFront ? this.$frontMarkers : this.$backMarkers; |
| 24963 |
if (marker) { |
| 24964 |
delete (markers[markerId]); |
| 24965 |
this._signal(marker.inFront ? "changeFrontMarker" : "changeBackMarker"); |
| 24966 |
} |
| 24967 |
}; |
| 24968 |
this.getMarkers = function(inFront) { |
| 24969 |
return inFront ? this.$frontMarkers : this.$backMarkers; |
| 24970 |
}; |
| 24971 |
|
| 24972 |
this.highlight = function(re) { |
| 24973 |
if (!this.$searchHighlight) { |
| 24974 |
var highlight = new SearchHighlight(null, "ace_selected-word", "text"); |
| 24975 |
this.$searchHighlight = this.addDynamicMarker(highlight); |
| 24976 |
} |
| 24977 |
this.$searchHighlight.setRegexp(re); |
| 24978 |
}; |
| 24979 |
this.highlightLines = function(startRow, endRow, clazz, inFront) { |
| 24980 |
if (typeof endRow != "number") { |
| 24981 |
clazz = endRow; |
| 24982 |
endRow = startRow; |
| 24983 |
} |
| 24984 |
if (!clazz) |
| 24985 |
clazz = "ace_step"; |
| 24986 |
|
| 24987 |
var range = new Range(startRow, 0, endRow, Infinity); |
| 24988 |
range.id = this.addMarker(range, clazz, "fullLine", inFront); |
| 24989 |
return range; |
| 24990 |
}; |
| 24991 |
this.setAnnotations = function(annotations) { |
| 24992 |
this.$annotations = annotations; |
| 24993 |
this._signal("changeAnnotation", {}); |
| 24994 |
}; |
| 24995 |
this.getAnnotations = function() { |
| 24996 |
return this.$annotations || []; |
| 24997 |
}; |
| 24998 |
this.clearAnnotations = function() { |
| 24999 |
this.setAnnotations([]); |
| 25000 |
}; |
| 25001 |
this.$detectNewLine = function(text) { |
| 25002 |
var match = text.match(/^.*?(\r?\n)/m); |
| 25003 |
if (match) { |
| 25004 |
this.$autoNewLine = match[1]; |
| 25005 |
} else { |
| 25006 |
this.$autoNewLine = "\n"; |
| 25007 |
} |
| 25008 |
}; |
| 25009 |
this.getWordRange = function(row, column) { |
| 25010 |
var line = this.getLine(row); |
| 25011 |
|
| 25012 |
var inToken = false; |
| 25013 |
if (column > 0) |
| 25014 |
inToken = !!line.charAt(column - 1).match(this.tokenRe); |
| 25015 |
|
| 25016 |
if (!inToken) |
| 25017 |
inToken = !!line.charAt(column).match(this.tokenRe); |
| 25018 |
|
| 25019 |
if (inToken) |
| 25020 |
var re = this.tokenRe; |
| 25021 |
else if (/^\s+$/.test(line.slice(column-1, column+1))) |
| 25022 |
var re = /\s/; |
| 25023 |
else |
| 25024 |
var re = this.nonTokenRe; |
| 25025 |
|
| 25026 |
var start = column; |
| 25027 |
if (start > 0) { |
| 25028 |
do { |
| 25029 |
start--; |
| 25030 |
} |
| 25031 |
while (start >= 0 && line.charAt(start).match(re)); |
| 25032 |
start++; |
| 25033 |
} |
| 25034 |
|
| 25035 |
var end = column; |
| 25036 |
while (end < line.length && line.charAt(end).match(re)) { |
| 25037 |
end++; |
| 25038 |
} |
| 25039 |
|
| 25040 |
return new Range(row, start, row, end); |
| 25041 |
}; |
| 25042 |
this.getAWordRange = function(row, column) { |
| 25043 |
var wordRange = this.getWordRange(row, column); |
| 25044 |
var line = this.getLine(wordRange.end.row); |
| 25045 |
|
| 25046 |
while (line.charAt(wordRange.end.column).match(/[ \t]/)) { |
| 25047 |
wordRange.end.column += 1; |
| 25048 |
} |
| 25049 |
return wordRange; |
| 25050 |
}; |
| 25051 |
this.setNewLineMode = function(newLineMode) { |
| 25052 |
this.doc.setNewLineMode(newLineMode); |
| 25053 |
}; |
| 25054 |
this.getNewLineMode = function() { |
| 25055 |
return this.doc.getNewLineMode(); |
| 25056 |
}; |
| 25057 |
this.setUseWorker = function(useWorker) { this.setOption("useWorker", useWorker); }; |
| 25058 |
this.getUseWorker = function() { return this.$useWorker; }; |
| 25059 |
this.onReloadTokenizer = function(e) { |
| 25060 |
var rows = e.data; |
| 25061 |
this.bgTokenizer.start(rows.first); |
| 25062 |
this._signal("tokenizerUpdate", e); |
| 25063 |
}; |
| 25064 |
|
| 25065 |
this.$modes = {}; |
| 25066 |
this.$mode = null; |
| 25067 |
this.$modeId = null; |
| 25068 |
this.setMode = function(mode, cb) { |
| 25069 |
if (mode && typeof mode === "object") { |
| 25070 |
if (mode.getTokenizer) |
| 25071 |
return this.$onChangeMode(mode); |
| 25072 |
var options = mode; |
| 25073 |
var path = options.path; |
| 25074 |
} else { |
| 25075 |
path = mode || "ace/mode/text"; |
| 25076 |
} |
| 25077 |
if (!this.$modes["ace/mode/text"]) |
| 25078 |
this.$modes["ace/mode/text"] = new TextMode(); |
| 25079 |
|
| 25080 |
if (this.$modes[path] && !options) { |
| 25081 |
this.$onChangeMode(this.$modes[path]); |
| 25082 |
cb && cb(); |
| 25083 |
return; |
| 25084 |
} |
| 25085 |
this.$modeId = path; |
| 25086 |
config.loadModule(["mode", path], function(m) { |
| 25087 |
if (this.$modeId !== path) |
| 25088 |
return cb && cb(); |
| 25089 |
if (this.$modes[path] && !options) { |
| 25090 |
this.$onChangeMode(this.$modes[path]); |
| 25091 |
} else if (m && m.Mode) { |
| 25092 |
m = new m.Mode(options); |
| 25093 |
if (!options) { |
| 25094 |
this.$modes[path] = m; |
| 25095 |
m.$id = path; |
| 25096 |
} |
| 25097 |
this.$onChangeMode(m); |
| 25098 |
} |
| 25099 |
cb && cb(); |
| 25100 |
}.bind(this)); |
| 25101 |
if (!this.$mode) |
| 25102 |
this.$onChangeMode(this.$modes["ace/mode/text"], true); |
| 25103 |
}; |
| 25104 |
|
| 25105 |
this.$onChangeMode = function(mode, $isPlaceholder) { |
| 25106 |
if (!$isPlaceholder) |
| 25107 |
this.$modeId = mode.$id; |
| 25108 |
if (this.$mode === mode) |
| 25109 |
return; |
| 25110 |
|
| 25111 |
this.$mode = mode; |
| 25112 |
|
| 25113 |
this.$stopWorker(); |
| 25114 |
|
| 25115 |
if (this.$useWorker) |
| 25116 |
this.$startWorker(); |
| 25117 |
|
| 25118 |
var tokenizer = mode.getTokenizer(); |
| 25119 |
|
| 25120 |
if(tokenizer.addEventListener !== undefined) { |
| 25121 |
var onReloadTokenizer = this.onReloadTokenizer.bind(this); |
| 25122 |
tokenizer.addEventListener("update", onReloadTokenizer); |
| 25123 |
} |
| 25124 |
|
| 25125 |
if (!this.bgTokenizer) { |
| 25126 |
this.bgTokenizer = new BackgroundTokenizer(tokenizer); |
| 25127 |
var _self = this; |
| 25128 |
this.bgTokenizer.addEventListener("update", function(e) { |
| 25129 |
_self._signal("tokenizerUpdate", e); |
| 25130 |
}); |
| 25131 |
} else { |
| 25132 |
this.bgTokenizer.setTokenizer(tokenizer); |
| 25133 |
} |
| 25134 |
|
| 25135 |
this.bgTokenizer.setDocument(this.getDocument()); |
| 25136 |
|
| 25137 |
this.tokenRe = mode.tokenRe; |
| 25138 |
this.nonTokenRe = mode.nonTokenRe; |
| 25139 |
|
| 25140 |
|
| 25141 |
if (!$isPlaceholder) { |
| 25142 |
if (mode.attachToSession) |
| 25143 |
mode.attachToSession(this); |
| 25144 |
this.$options.wrapMethod.set.call(this, this.$wrapMethod); |
| 25145 |
this.$setFolding(mode.foldingRules); |
| 25146 |
this.bgTokenizer.start(0); |
| 25147 |
this._emit("changeMode"); |
| 25148 |
} |
| 25149 |
}; |
| 25150 |
|
| 25151 |
this.$stopWorker = function() { |
| 25152 |
if (this.$worker) { |
| 25153 |
this.$worker.terminate(); |
| 25154 |
this.$worker = null; |
| 25155 |
} |
| 25156 |
}; |
| 25157 |
|
| 25158 |
this.$startWorker = function() { |
| 25159 |
try { |
| 25160 |
this.$worker = this.$mode.createWorker(this); |
| 25161 |
} catch (e) { |
| 25162 |
config.warn("Could not load worker", e); |
| 25163 |
this.$worker = null; |
| 25164 |
} |
| 25165 |
}; |
| 25166 |
this.getMode = function() { |
| 25167 |
return this.$mode; |
| 25168 |
}; |
| 25169 |
|
| 25170 |
this.$scrollTop = 0; |
| 25171 |
this.setScrollTop = function(scrollTop) { |
| 25172 |
if (this.$scrollTop === scrollTop || isNaN(scrollTop)) |
| 25173 |
return; |
| 25174 |
|
| 25175 |
this.$scrollTop = scrollTop; |
| 25176 |
this._signal("changeScrollTop", scrollTop); |
| 25177 |
}; |
| 25178 |
this.getScrollTop = function() { |
| 25179 |
return this.$scrollTop; |
| 25180 |
}; |
| 25181 |
|
| 25182 |
this.$scrollLeft = 0; |
| 25183 |
this.setScrollLeft = function(scrollLeft) { |
| 25184 |
if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft)) |
| 25185 |
return; |
| 25186 |
|
| 25187 |
this.$scrollLeft = scrollLeft; |
| 25188 |
this._signal("changeScrollLeft", scrollLeft); |
| 25189 |
}; |
| 25190 |
this.getScrollLeft = function() { |
| 25191 |
return this.$scrollLeft; |
| 25192 |
}; |
| 25193 |
this.getScreenWidth = function() { |
| 25194 |
this.$computeWidth(); |
| 25195 |
if (this.lineWidgets) |
| 25196 |
return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth); |
| 25197 |
return this.screenWidth; |
| 25198 |
}; |
| 25199 |
|
| 25200 |
this.getLineWidgetMaxWidth = function() { |
| 25201 |
if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth; |
| 25202 |
var width = 0; |
| 25203 |
this.lineWidgets.forEach(function(w) { |
| 25204 |
if (w && w.screenWidth > width) |
| 25205 |
width = w.screenWidth; |
| 25206 |
}); |
| 25207 |
return this.lineWidgetWidth = width; |
| 25208 |
}; |
| 25209 |
|
| 25210 |
this.$computeWidth = function(force) { |
| 25211 |
if (this.$modified || force) { |
| 25212 |
this.$modified = false; |
| 25213 |
|
| 25214 |
if (this.$useWrapMode) |
| 25215 |
return this.screenWidth = this.$wrapLimit; |
| 25216 |
|
| 25217 |
var lines = this.doc.getAllLines(); |
| 25218 |
var cache = this.$rowLengthCache; |
| 25219 |
var longestScreenLine = 0; |
| 25220 |
var foldIndex = 0; |
| 25221 |
var foldLine = this.$foldData[foldIndex]; |
| 25222 |
var foldStart = foldLine ? foldLine.start.row : Infinity; |
| 25223 |
var len = lines.length; |
| 25224 |
|
| 25225 |
for (var i = 0; i < len; i++) { |
| 25226 |
if (i > foldStart) { |
| 25227 |
i = foldLine.end.row + 1; |
| 25228 |
if (i >= len) |
| 25229 |
break; |
| 25230 |
foldLine = this.$foldData[foldIndex++]; |
| 25231 |
foldStart = foldLine ? foldLine.start.row : Infinity; |
| 25232 |
} |
| 25233 |
|
| 25234 |
if (cache[i] == null) |
| 25235 |
cache[i] = this.$getStringScreenWidth(lines[i])[0]; |
| 25236 |
|
| 25237 |
if (cache[i] > longestScreenLine) |
| 25238 |
longestScreenLine = cache[i]; |
| 25239 |
} |
| 25240 |
this.screenWidth = longestScreenLine; |
| 25241 |
} |
| 25242 |
}; |
| 25243 |
this.getLine = function(row) { |
| 25244 |
return this.doc.getLine(row); |
| 25245 |
}; |
| 25246 |
this.getLines = function(firstRow, lastRow) { |
| 25247 |
return this.doc.getLines(firstRow, lastRow); |
| 25248 |
}; |
| 25249 |
this.getLength = function() { |
| 25250 |
return this.doc.getLength(); |
| 25251 |
}; |
| 25252 |
this.getTextRange = function(range) { |
| 25253 |
return this.doc.getTextRange(range || this.selection.getRange()); |
| 25254 |
}; |
| 25255 |
this.insert = function(position, text) { |
| 25256 |
return this.doc.insert(position, text); |
| 25257 |
}; |
| 25258 |
this.remove = function(range) { |
| 25259 |
return this.doc.remove(range); |
| 25260 |
}; |
| 25261 |
this.removeFullLines = function(firstRow, lastRow){ |
| 25262 |
return this.doc.removeFullLines(firstRow, lastRow); |
| 25263 |
}; |
| 25264 |
this.undoChanges = function(deltas, dontSelect) { |
| 25265 |
if (!deltas.length) |
| 25266 |
return; |
| 25267 |
|
| 25268 |
this.$fromUndo = true; |
| 25269 |
var lastUndoRange = null; |
| 25270 |
for (var i = deltas.length - 1; i != -1; i--) { |
| 25271 |
var delta = deltas[i]; |
| 25272 |
if (delta.group == "doc") { |
| 25273 |
this.doc.revertDeltas(delta.deltas); |
| 25274 |
lastUndoRange = |
| 25275 |
this.$getUndoSelection(delta.deltas, true, lastUndoRange); |
| 25276 |
} else { |
| 25277 |
delta.deltas.forEach(function(foldDelta) { |
| 25278 |
this.addFolds(foldDelta.folds); |
| 25279 |
}, this); |
| 25280 |
} |
| 25281 |
} |
| 25282 |
this.$fromUndo = false; |
| 25283 |
lastUndoRange && |
| 25284 |
this.$undoSelect && |
| 25285 |
!dontSelect && |
| 25286 |
this.selection.setSelectionRange(lastUndoRange); |
| 25287 |
return lastUndoRange; |
| 25288 |
}; |
| 25289 |
this.redoChanges = function(deltas, dontSelect) { |
| 25290 |
if (!deltas.length) |
| 25291 |
return; |
| 25292 |
|
| 25293 |
this.$fromUndo = true; |
| 25294 |
var lastUndoRange = null; |
| 25295 |
for (var i = 0; i < deltas.length; i++) { |
| 25296 |
var delta = deltas[i]; |
| 25297 |
if (delta.group == "doc") { |
| 25298 |
this.doc.applyDeltas(delta.deltas); |
| 25299 |
lastUndoRange = |
| 25300 |
this.$getUndoSelection(delta.deltas, false, lastUndoRange); |
| 25301 |
} |
| 25302 |
} |
| 25303 |
this.$fromUndo = false; |
| 25304 |
lastUndoRange && |
| 25305 |
this.$undoSelect && |
| 25306 |
!dontSelect && |
| 25307 |
this.selection.setSelectionRange(lastUndoRange); |
| 25308 |
return lastUndoRange; |
| 25309 |
}; |
| 25310 |
this.setUndoSelect = function(enable) { |
| 25311 |
this.$undoSelect = enable; |
| 25312 |
}; |
| 25313 |
|
| 25314 |
this.$getUndoSelection = function(deltas, isUndo, lastUndoRange) { |
| 25315 |
function isInsert(delta) { |
| 25316 |
return isUndo ? delta.action !== "insert" : delta.action === "insert"; |
| 25317 |
} |
| 25318 |
|
| 25319 |
var delta = deltas[0]; |
| 25320 |
var range, point; |
| 25321 |
var lastDeltaIsInsert = false; |
| 25322 |
if (isInsert(delta)) { |
| 25323 |
range = Range.fromPoints(delta.start, delta.end); |
| 25324 |
lastDeltaIsInsert = true; |
| 25325 |
} else { |
| 25326 |
range = Range.fromPoints(delta.start, delta.start); |
| 25327 |
lastDeltaIsInsert = false; |
| 25328 |
} |
| 25329 |
|
| 25330 |
for (var i = 1; i < deltas.length; i++) { |
| 25331 |
delta = deltas[i]; |
| 25332 |
if (isInsert(delta)) { |
| 25333 |
point = delta.start; |
| 25334 |
if (range.compare(point.row, point.column) == -1) { |
| 25335 |
range.setStart(point); |
| 25336 |
} |
| 25337 |
point = delta.end; |
| 25338 |
if (range.compare(point.row, point.column) == 1) { |
| 25339 |
range.setEnd(point); |
| 25340 |
} |
| 25341 |
lastDeltaIsInsert = true; |
| 25342 |
} else { |
| 25343 |
point = delta.start; |
| 25344 |
if (range.compare(point.row, point.column) == -1) { |
| 25345 |
range = Range.fromPoints(delta.start, delta.start); |
| 25346 |
} |
| 25347 |
lastDeltaIsInsert = false; |
| 25348 |
} |
| 25349 |
} |
| 25350 |
if (lastUndoRange != null) { |
| 25351 |
if (Range.comparePoints(lastUndoRange.start, range.start) === 0) { |
| 25352 |
lastUndoRange.start.column += range.end.column - range.start.column; |
| 25353 |
lastUndoRange.end.column += range.end.column - range.start.column; |
| 25354 |
} |
| 25355 |
|
| 25356 |
var cmp = lastUndoRange.compareRange(range); |
| 25357 |
if (cmp == 1) { |
| 25358 |
range.setStart(lastUndoRange.start); |
| 25359 |
} else if (cmp == -1) { |
| 25360 |
range.setEnd(lastUndoRange.end); |
| 25361 |
} |
| 25362 |
} |
| 25363 |
|
| 25364 |
return range; |
| 25365 |
}; |
| 25366 |
this.replace = function(range, text) { |
| 25367 |
return this.doc.replace(range, text); |
| 25368 |
}; |
| 25369 |
this.moveText = function(fromRange, toPosition, copy) { |
| 25370 |
var text = this.getTextRange(fromRange); |
| 25371 |
var folds = this.getFoldsInRange(fromRange); |
| 25372 |
|
| 25373 |
var toRange = Range.fromPoints(toPosition, toPosition); |
| 25374 |
if (!copy) { |
| 25375 |
this.remove(fromRange); |
| 25376 |
var rowDiff = fromRange.start.row - fromRange.end.row; |
| 25377 |
var collDiff = rowDiff ? -fromRange.end.column : fromRange.start.column - fromRange.end.column; |
| 25378 |
if (collDiff) { |
| 25379 |
if (toRange.start.row == fromRange.end.row && toRange.start.column > fromRange.end.column) |
| 25380 |
toRange.start.column += collDiff; |
| 25381 |
if (toRange.end.row == fromRange.end.row && toRange.end.column > fromRange.end.column) |
| 25382 |
toRange.end.column += collDiff; |
| 25383 |
} |
| 25384 |
if (rowDiff && toRange.start.row >= fromRange.end.row) { |
| 25385 |
toRange.start.row += rowDiff; |
| 25386 |
toRange.end.row += rowDiff; |
| 25387 |
} |
| 25388 |
} |
| 25389 |
|
| 25390 |
toRange.end = this.insert(toRange.start, text); |
| 25391 |
if (folds.length) { |
| 25392 |
var oldStart = fromRange.start; |
| 25393 |
var newStart = toRange.start; |
| 25394 |
var rowDiff = newStart.row - oldStart.row; |
| 25395 |
var collDiff = newStart.column - oldStart.column; |
| 25396 |
this.addFolds(folds.map(function(x) { |
| 25397 |
x = x.clone(); |
| 25398 |
if (x.start.row == oldStart.row) |
| 25399 |
x.start.column += collDiff; |
| 25400 |
if (x.end.row == oldStart.row) |
| 25401 |
x.end.column += collDiff; |
| 25402 |
x.start.row += rowDiff; |
| 25403 |
x.end.row += rowDiff; |
| 25404 |
return x; |
| 25405 |
})); |
| 25406 |
} |
| 25407 |
|
| 25408 |
return toRange; |
| 25409 |
}; |
| 25410 |
this.indentRows = function(startRow, endRow, indentString) { |
| 25411 |
indentString = indentString.replace(/\t/g, this.getTabString()); |
| 25412 |
for (var row=startRow; row<=endRow; row++) |
| 25413 |
this.doc.insertInLine({row: row, column: 0}, indentString); |
| 25414 |
}; |
| 25415 |
this.outdentRows = function (range) { |
| 25416 |
var rowRange = range.collapseRows(); |
| 25417 |
var deleteRange = new Range(0, 0, 0, 0); |
| 25418 |
var size = this.getTabSize(); |
| 25419 |
|
| 25420 |
for (var i = rowRange.start.row; i <= rowRange.end.row; ++i) { |
| 25421 |
var line = this.getLine(i); |
| 25422 |
|
| 25423 |
deleteRange.start.row = i; |
| 25424 |
deleteRange.end.row = i; |
| 25425 |
for (var j = 0; j < size; ++j) |
| 25426 |
if (line.charAt(j) != ' ') |
| 25427 |
break; |
| 25428 |
if (j < size && line.charAt(j) == '\t') { |
| 25429 |
deleteRange.start.column = j; |
| 25430 |
deleteRange.end.column = j + 1; |
| 25431 |
} else { |
| 25432 |
deleteRange.start.column = 0; |
| 25433 |
deleteRange.end.column = j; |
| 25434 |
} |
| 25435 |
this.remove(deleteRange); |
| 25436 |
} |
| 25437 |
}; |
| 25438 |
|
| 25439 |
this.$moveLines = function(firstRow, lastRow, dir) { |
| 25440 |
firstRow = this.getRowFoldStart(firstRow); |
| 25441 |
lastRow = this.getRowFoldEnd(lastRow); |
| 25442 |
if (dir < 0) { |
| 25443 |
var row = this.getRowFoldStart(firstRow + dir); |
| 25444 |
if (row < 0) return 0; |
| 25445 |
var diff = row-firstRow; |
| 25446 |
} else if (dir > 0) { |
| 25447 |
var row = this.getRowFoldEnd(lastRow + dir); |
| 25448 |
if (row > this.doc.getLength()-1) return 0; |
| 25449 |
var diff = row-lastRow; |
| 25450 |
} else { |
| 25451 |
firstRow = this.$clipRowToDocument(firstRow); |
| 25452 |
lastRow = this.$clipRowToDocument(lastRow); |
| 25453 |
var diff = lastRow - firstRow + 1; |
| 25454 |
} |
| 25455 |
|
| 25456 |
var range = new Range(firstRow, 0, lastRow, Number.MAX_VALUE); |
| 25457 |
var folds = this.getFoldsInRange(range).map(function(x){ |
| 25458 |
x = x.clone(); |
| 25459 |
x.start.row += diff; |
| 25460 |
x.end.row += diff; |
| 25461 |
return x; |
| 25462 |
}); |
| 25463 |
|
| 25464 |
var lines = dir == 0 |
| 25465 |
? this.doc.getLines(firstRow, lastRow) |
| 25466 |
: this.doc.removeFullLines(firstRow, lastRow); |
| 25467 |
this.doc.insertFullLines(firstRow+diff, lines); |
| 25468 |
folds.length && this.addFolds(folds); |
| 25469 |
return diff; |
| 25470 |
}; |
| 25471 |
this.moveLinesUp = function(firstRow, lastRow) { |
| 25472 |
return this.$moveLines(firstRow, lastRow, -1); |
| 25473 |
}; |
| 25474 |
this.moveLinesDown = function(firstRow, lastRow) { |
| 25475 |
return this.$moveLines(firstRow, lastRow, 1); |
| 25476 |
}; |
| 25477 |
this.duplicateLines = function(firstRow, lastRow) { |
| 25478 |
return this.$moveLines(firstRow, lastRow, 0); |
| 25479 |
}; |
| 25480 |
|
| 25481 |
|
| 25482 |
this.$clipRowToDocument = function(row) { |
| 25483 |
return Math.max(0, Math.min(row, this.doc.getLength()-1)); |
| 25484 |
}; |
| 25485 |
|
| 25486 |
this.$clipColumnToRow = function(row, column) { |
| 25487 |
if (column < 0) |
| 25488 |
return 0; |
| 25489 |
return Math.min(this.doc.getLine(row).length, column); |
| 25490 |
}; |
| 25491 |
|
| 25492 |
|
| 25493 |
this.$clipPositionToDocument = function(row, column) { |
| 25494 |
column = Math.max(0, column); |
| 25495 |
|
| 25496 |
if (row < 0) { |
| 25497 |
row = 0; |
| 25498 |
column = 0; |
| 25499 |
} else { |
| 25500 |
var len = this.doc.getLength(); |
| 25501 |
if (row >= len) { |
| 25502 |
row = len - 1; |
| 25503 |
column = this.doc.getLine(len-1).length; |
| 25504 |
} else { |
| 25505 |
column = Math.min(this.doc.getLine(row).length, column); |
| 25506 |
} |
| 25507 |
} |
| 25508 |
|
| 25509 |
return { |
| 25510 |
row: row, |
| 25511 |
column: column |
| 25512 |
}; |
| 25513 |
}; |
| 25514 |
|
| 25515 |
this.$clipRangeToDocument = function(range) { |
| 25516 |
if (range.start.row < 0) { |
| 25517 |
range.start.row = 0; |
| 25518 |
range.start.column = 0; |
| 25519 |
} else { |
| 25520 |
range.start.column = this.$clipColumnToRow( |
| 25521 |
range.start.row, |
| 25522 |
range.start.column |
| 25523 |
); |
| 25524 |
} |
| 25525 |
|
| 25526 |
var len = this.doc.getLength() - 1; |
| 25527 |
if (range.end.row > len) { |
| 25528 |
range.end.row = len; |
| 25529 |
range.end.column = this.doc.getLine(len).length; |
| 25530 |
} else { |
| 25531 |
range.end.column = this.$clipColumnToRow( |
| 25532 |
range.end.row, |
| 25533 |
range.end.column |
| 25534 |
); |
| 25535 |
} |
| 25536 |
return range; |
| 25537 |
}; |
| 25538 |
this.$wrapLimit = 80; |
| 25539 |
this.$useWrapMode = false; |
| 25540 |
this.$wrapLimitRange = { |
| 25541 |
min : null, |
| 25542 |
max : null |
| 25543 |
}; |
| 25544 |
this.setUseWrapMode = function(useWrapMode) { |
| 25545 |
if (useWrapMode != this.$useWrapMode) { |
| 25546 |
this.$useWrapMode = useWrapMode; |
| 25547 |
this.$modified = true; |
| 25548 |
this.$resetRowCache(0); |
| 25549 |
if (useWrapMode) { |
| 25550 |
var len = this.getLength(); |
| 25551 |
this.$wrapData = Array(len); |
| 25552 |
this.$updateWrapData(0, len - 1); |
| 25553 |
} |
| 25554 |
|
| 25555 |
this._signal("changeWrapMode"); |
| 25556 |
} |
| 25557 |
}; |
| 25558 |
this.getUseWrapMode = function() { |
| 25559 |
return this.$useWrapMode; |
| 25560 |
}; |
| 25561 |
this.setWrapLimitRange = function(min, max) { |
| 25562 |
if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) { |
| 25563 |
this.$wrapLimitRange = { min: min, max: max }; |
| 25564 |
this.$modified = true; |
| 25565 |
if (this.$useWrapMode) |
| 25566 |
this._signal("changeWrapMode"); |
| 25567 |
} |
| 25568 |
}; |
| 25569 |
this.adjustWrapLimit = function(desiredLimit, $printMargin) { |
| 25570 |
var limits = this.$wrapLimitRange; |
| 25571 |
if (limits.max < 0) |
| 25572 |
limits = {min: $printMargin, max: $printMargin}; |
| 25573 |
var wrapLimit = this.$constrainWrapLimit(desiredLimit, limits.min, limits.max); |
| 25574 |
if (wrapLimit != this.$wrapLimit && wrapLimit > 1) { |
| 25575 |
this.$wrapLimit = wrapLimit; |
| 25576 |
this.$modified = true; |
| 25577 |
if (this.$useWrapMode) { |
| 25578 |
this.$updateWrapData(0, this.getLength() - 1); |
| 25579 |
this.$resetRowCache(0); |
| 25580 |
this._signal("changeWrapLimit"); |
| 25581 |
} |
| 25582 |
return true; |
| 25583 |
} |
| 25584 |
return false; |
| 25585 |
}; |
| 25586 |
|
| 25587 |
this.$constrainWrapLimit = function(wrapLimit, min, max) { |
| 25588 |
if (min) |
| 25589 |
wrapLimit = Math.max(min, wrapLimit); |
| 25590 |
|
| 25591 |
if (max) |
| 25592 |
wrapLimit = Math.min(max, wrapLimit); |
| 25593 |
|
| 25594 |
return wrapLimit; |
| 25595 |
}; |
| 25596 |
this.getWrapLimit = function() { |
| 25597 |
return this.$wrapLimit; |
| 25598 |
}; |
| 25599 |
this.setWrapLimit = function (limit) { |
| 25600 |
this.setWrapLimitRange(limit, limit); |
| 25601 |
}; |
| 25602 |
this.getWrapLimitRange = function() { |
| 25603 |
return { |
| 25604 |
min : this.$wrapLimitRange.min, |
| 25605 |
max : this.$wrapLimitRange.max |
| 25606 |
}; |
| 25607 |
}; |
| 25608 |
|
| 25609 |
this.$updateInternalDataOnChange = function(delta) { |
| 25610 |
var useWrapMode = this.$useWrapMode; |
| 25611 |
var action = delta.action; |
| 25612 |
var start = delta.start; |
| 25613 |
var end = delta.end; |
| 25614 |
var firstRow = start.row; |
| 25615 |
var lastRow = end.row; |
| 25616 |
var len = lastRow - firstRow; |
| 25617 |
var removedFolds = null; |
| 25618 |
|
| 25619 |
this.$updating = true; |
| 25620 |
if (len != 0) { |
| 25621 |
if (action === "remove") { |
| 25622 |
this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len); |
| 25623 |
|
| 25624 |
var foldLines = this.$foldData; |
| 25625 |
removedFolds = this.getFoldsInRange(delta); |
| 25626 |
this.removeFolds(removedFolds); |
| 25627 |
|
| 25628 |
var foldLine = this.getFoldLine(end.row); |
| 25629 |
var idx = 0; |
| 25630 |
if (foldLine) { |
| 25631 |
foldLine.addRemoveChars(end.row, end.column, start.column - end.column); |
| 25632 |
foldLine.shiftRow(-len); |
| 25633 |
|
| 25634 |
var foldLineBefore = this.getFoldLine(firstRow); |
| 25635 |
if (foldLineBefore && foldLineBefore !== foldLine) { |
| 25636 |
foldLineBefore.merge(foldLine); |
| 25637 |
foldLine = foldLineBefore; |
| 25638 |
} |
| 25639 |
idx = foldLines.indexOf(foldLine) + 1; |
| 25640 |
} |
| 25641 |
|
| 25642 |
for (idx; idx < foldLines.length; idx++) { |
| 25643 |
var foldLine = foldLines[idx]; |
| 25644 |
if (foldLine.start.row >= end.row) { |
| 25645 |
foldLine.shiftRow(-len); |
| 25646 |
} |
| 25647 |
} |
| 25648 |
|
| 25649 |
lastRow = firstRow; |
| 25650 |
} else { |
| 25651 |
var args = Array(len); |
| 25652 |
args.unshift(firstRow, 0); |
| 25653 |
var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache |
| 25654 |
arr.splice.apply(arr, args); |
| 25655 |
var foldLines = this.$foldData; |
| 25656 |
var foldLine = this.getFoldLine(firstRow); |
| 25657 |
var idx = 0; |
| 25658 |
if (foldLine) { |
| 25659 |
var cmp = foldLine.range.compareInside(start.row, start.column); |
| 25660 |
if (cmp == 0) { |
| 25661 |
foldLine = foldLine.split(start.row, start.column); |
| 25662 |
if (foldLine) { |
| 25663 |
foldLine.shiftRow(len); |
| 25664 |
foldLine.addRemoveChars(lastRow, 0, end.column - start.column); |
| 25665 |
} |
| 25666 |
} else |
| 25667 |
if (cmp == -1) { |
| 25668 |
foldLine.addRemoveChars(firstRow, 0, end.column - start.column); |
| 25669 |
foldLine.shiftRow(len); |
| 25670 |
} |
| 25671 |
idx = foldLines.indexOf(foldLine) + 1; |
| 25672 |
} |
| 25673 |
|
| 25674 |
for (idx; idx < foldLines.length; idx++) { |
| 25675 |
var foldLine = foldLines[idx]; |
| 25676 |
if (foldLine.start.row >= firstRow) { |
| 25677 |
foldLine.shiftRow(len); |
| 25678 |
} |
| 25679 |
} |
| 25680 |
} |
| 25681 |
} else { |
| 25682 |
len = Math.abs(delta.start.column - delta.end.column); |
| 25683 |
if (action === "remove") { |
| 25684 |
removedFolds = this.getFoldsInRange(delta); |
| 25685 |
this.removeFolds(removedFolds); |
| 25686 |
|
| 25687 |
len = -len; |
| 25688 |
} |
| 25689 |
var foldLine = this.getFoldLine(firstRow); |
| 25690 |
if (foldLine) { |
| 25691 |
foldLine.addRemoveChars(firstRow, start.column, len); |
| 25692 |
} |
| 25693 |
} |
| 25694 |
|
| 25695 |
if (useWrapMode && this.$wrapData.length != this.doc.getLength()) { |
| 25696 |
console.error("doc.getLength() and $wrapData.length have to be the same!"); |
| 25697 |
} |
| 25698 |
this.$updating = false; |
| 25699 |
|
| 25700 |
if (useWrapMode) |
| 25701 |
this.$updateWrapData(firstRow, lastRow); |
| 25702 |
else |
| 25703 |
this.$updateRowLengthCache(firstRow, lastRow); |
| 25704 |
|
| 25705 |
return removedFolds; |
| 25706 |
}; |
| 25707 |
|
| 25708 |
this.$updateRowLengthCache = function(firstRow, lastRow, b) { |
| 25709 |
this.$rowLengthCache[firstRow] = null; |
| 25710 |
this.$rowLengthCache[lastRow] = null; |
| 25711 |
}; |
| 25712 |
|
| 25713 |
this.$updateWrapData = function(firstRow, lastRow) { |
| 25714 |
var lines = this.doc.getAllLines(); |
| 25715 |
var tabSize = this.getTabSize(); |
| 25716 |
var wrapData = this.$wrapData; |
| 25717 |
var wrapLimit = this.$wrapLimit; |
| 25718 |
var tokens; |
| 25719 |
var foldLine; |
| 25720 |
|
| 25721 |
var row = firstRow; |
| 25722 |
lastRow = Math.min(lastRow, lines.length - 1); |
| 25723 |
while (row <= lastRow) { |
| 25724 |
foldLine = this.getFoldLine(row, foldLine); |
| 25725 |
if (!foldLine) { |
| 25726 |
tokens = this.$getDisplayTokens(lines[row]); |
| 25727 |
wrapData[row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize); |
| 25728 |
row ++; |
| 25729 |
} else { |
| 25730 |
tokens = []; |
| 25731 |
foldLine.walk(function(placeholder, row, column, lastColumn) { |
| 25732 |
var walkTokens; |
| 25733 |
if (placeholder != null) { |
| 25734 |
walkTokens = this.$getDisplayTokens( |
| 25735 |
placeholder, tokens.length); |
| 25736 |
walkTokens[0] = PLACEHOLDER_START; |
| 25737 |
for (var i = 1; i < walkTokens.length; i++) { |
| 25738 |
walkTokens[i] = PLACEHOLDER_BODY; |
| 25739 |
} |
| 25740 |
} else { |
| 25741 |
walkTokens = this.$getDisplayTokens( |
| 25742 |
lines[row].substring(lastColumn, column), |
| 25743 |
tokens.length); |
| 25744 |
} |
| 25745 |
tokens = tokens.concat(walkTokens); |
| 25746 |
}.bind(this), |
| 25747 |
foldLine.end.row, |
| 25748 |
lines[foldLine.end.row].length + 1 |
| 25749 |
); |
| 25750 |
|
| 25751 |
wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize); |
| 25752 |
row = foldLine.end.row + 1; |
| 25753 |
} |
| 25754 |
} |
| 25755 |
}; |
| 25756 |
var CHAR = 1, |
| 25757 |
CHAR_EXT = 2, |
| 25758 |
PLACEHOLDER_START = 3, |
| 25759 |
PLACEHOLDER_BODY = 4, |
| 25760 |
PUNCTUATION = 9, |
| 25761 |
SPACE = 10, |
| 25762 |
TAB = 11, |
| 25763 |
TAB_SPACE = 12; |
| 25764 |
|
| 25765 |
|
| 25766 |
this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) { |
| 25767 |
if (tokens.length == 0) { |
| 25768 |
return []; |
| 25769 |
} |
| 25770 |
|
| 25771 |
var splits = []; |
| 25772 |
var displayLength = tokens.length; |
| 25773 |
var lastSplit = 0, lastDocSplit = 0; |
| 25774 |
|
| 25775 |
var isCode = this.$wrapAsCode; |
| 25776 |
|
| 25777 |
var indentedSoftWrap = this.$indentedSoftWrap; |
| 25778 |
var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8) |
| 25779 |
|| indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2); |
| 25780 |
|
| 25781 |
function getWrapIndent() { |
| 25782 |
var indentation = 0; |
| 25783 |
if (maxIndent === 0) |
| 25784 |
return indentation; |
| 25785 |
if (indentedSoftWrap) { |
| 25786 |
for (var i = 0; i < tokens.length; i++) { |
| 25787 |
var token = tokens[i]; |
| 25788 |
if (token == SPACE) |
| 25789 |
indentation += 1; |
| 25790 |
else if (token == TAB) |
| 25791 |
indentation += tabSize; |
| 25792 |
else if (token == TAB_SPACE) |
| 25793 |
continue; |
| 25794 |
else |
| 25795 |
break; |
| 25796 |
} |
| 25797 |
} |
| 25798 |
if (isCode && indentedSoftWrap !== false) |
| 25799 |
indentation += tabSize; |
| 25800 |
return Math.min(indentation, maxIndent); |
| 25801 |
} |
| 25802 |
function addSplit(screenPos) { |
| 25803 |
var displayed = tokens.slice(lastSplit, screenPos); |
| 25804 |
var len = displayed.length; |
| 25805 |
displayed.join("") |
| 25806 |
.replace(/12/g, function() { |
| 25807 |
len -= 1; |
| 25808 |
}) |
| 25809 |
.replace(/2/g, function() { |
| 25810 |
len -= 1; |
| 25811 |
}); |
| 25812 |
|
| 25813 |
if (!splits.length) { |
| 25814 |
indent = getWrapIndent(); |
| 25815 |
splits.indent = indent; |
| 25816 |
} |
| 25817 |
lastDocSplit += len; |
| 25818 |
splits.push(lastDocSplit); |
| 25819 |
lastSplit = screenPos; |
| 25820 |
} |
| 25821 |
var indent = 0; |
| 25822 |
while (displayLength - lastSplit > wrapLimit - indent) { |
| 25823 |
var split = lastSplit + wrapLimit - indent; |
| 25824 |
if (tokens[split - 1] >= SPACE && tokens[split] >= SPACE) { |
| 25825 |
addSplit(split); |
| 25826 |
continue; |
| 25827 |
} |
| 25828 |
if (tokens[split] == PLACEHOLDER_START || tokens[split] == PLACEHOLDER_BODY) { |
| 25829 |
for (split; split != lastSplit - 1; split--) { |
| 25830 |
if (tokens[split] == PLACEHOLDER_START) { |
| 25831 |
break; |
| 25832 |
} |
| 25833 |
} |
| 25834 |
if (split > lastSplit) { |
| 25835 |
addSplit(split); |
| 25836 |
continue; |
| 25837 |
} |
| 25838 |
split = lastSplit + wrapLimit; |
| 25839 |
for (split; split < tokens.length; split++) { |
| 25840 |
if (tokens[split] != PLACEHOLDER_BODY) { |
| 25841 |
break; |
| 25842 |
} |
| 25843 |
} |
| 25844 |
if (split == tokens.length) { |
| 25845 |
break; // Breaks the while-loop. |
| 25846 |
} |
| 25847 |
addSplit(split); |
| 25848 |
continue; |
| 25849 |
} |
| 25850 |
var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1); |
| 25851 |
while (split > minSplit && tokens[split] < PLACEHOLDER_START) { |
| 25852 |
split --; |
| 25853 |
} |
| 25854 |
if (isCode) { |
| 25855 |
while (split > minSplit && tokens[split] < PLACEHOLDER_START) { |
| 25856 |
split --; |
| 25857 |
} |
| 25858 |
while (split > minSplit && tokens[split] == PUNCTUATION) { |
| 25859 |
split --; |
| 25860 |
} |
| 25861 |
} else { |
| 25862 |
while (split > minSplit && tokens[split] < SPACE) { |
| 25863 |
split --; |
| 25864 |
} |
| 25865 |
} |
| 25866 |
if (split > minSplit) { |
| 25867 |
addSplit(++split); |
| 25868 |
continue; |
| 25869 |
} |
| 25870 |
split = lastSplit + wrapLimit; |
| 25871 |
if (tokens[split] == CHAR_EXT) |
| 25872 |
split--; |
| 25873 |
addSplit(split - indent); |
| 25874 |
} |
| 25875 |
return splits; |
| 25876 |
}; |
| 25877 |
this.$getDisplayTokens = function(str, offset) { |
| 25878 |
var arr = []; |
| 25879 |
var tabSize; |
| 25880 |
offset = offset || 0; |
| 25881 |
|
| 25882 |
for (var i = 0; i < str.length; i++) { |
| 25883 |
var c = str.charCodeAt(i); |
| 25884 |
if (c == 9) { |
| 25885 |
tabSize = this.getScreenTabSize(arr.length + offset); |
| 25886 |
arr.push(TAB); |
| 25887 |
for (var n = 1; n < tabSize; n++) { |
| 25888 |
arr.push(TAB_SPACE); |
| 25889 |
} |
| 25890 |
} |
| 25891 |
else if (c == 32) { |
| 25892 |
arr.push(SPACE); |
| 25893 |
} else if((c > 39 && c < 48) || (c > 57 && c < 64)) { |
| 25894 |
arr.push(PUNCTUATION); |
| 25895 |
} |
| 25896 |
else if (c >= 0x1100 && isFullWidth(c)) { |
| 25897 |
arr.push(CHAR, CHAR_EXT); |
| 25898 |
} else { |
| 25899 |
arr.push(CHAR); |
| 25900 |
} |
| 25901 |
} |
| 25902 |
return arr; |
| 25903 |
}; |
| 25904 |
this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) { |
| 25905 |
if (maxScreenColumn == 0) |
| 25906 |
return [0, 0]; |
| 25907 |
if (maxScreenColumn == null) |
| 25908 |
maxScreenColumn = Infinity; |
| 25909 |
screenColumn = screenColumn || 0; |
| 25910 |
|
| 25911 |
var c, column; |
| 25912 |
for (column = 0; column < str.length; column++) { |
| 25913 |
c = str.charCodeAt(column); |
| 25914 |
if (c == 9) { |
| 25915 |
screenColumn += this.getScreenTabSize(screenColumn); |
| 25916 |
} |
| 25917 |
else if (c >= 0x1100 && isFullWidth(c)) { |
| 25918 |
screenColumn += 2; |
| 25919 |
} else { |
| 25920 |
screenColumn += 1; |
| 25921 |
} |
| 25922 |
if (screenColumn > maxScreenColumn) { |
| 25923 |
break; |
| 25924 |
} |
| 25925 |
} |
| 25926 |
|
| 25927 |
return [screenColumn, column]; |
| 25928 |
}; |
| 25929 |
|
| 25930 |
this.lineWidgets = null; |
| 25931 |
this.getRowLength = function(row) { |
| 25932 |
if (this.lineWidgets) |
| 25933 |
var h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0; |
| 25934 |
else |
| 25935 |
h = 0 |
| 25936 |
if (!this.$useWrapMode || !this.$wrapData[row]) { |
| 25937 |
return 1 + h; |
| 25938 |
} else { |
| 25939 |
return this.$wrapData[row].length + 1 + h; |
| 25940 |
} |
| 25941 |
}; |
| 25942 |
this.getRowLineCount = function(row) { |
| 25943 |
if (!this.$useWrapMode || !this.$wrapData[row]) { |
| 25944 |
return 1; |
| 25945 |
} else { |
| 25946 |
return this.$wrapData[row].length + 1; |
| 25947 |
} |
| 25948 |
}; |
| 25949 |
|
| 25950 |
this.getRowWrapIndent = function(screenRow) { |
| 25951 |
if (this.$useWrapMode) { |
| 25952 |
var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE); |
| 25953 |
var splits = this.$wrapData[pos.row]; |
| 25954 |
return splits.length && splits[0] < pos.column ? splits.indent : 0; |
| 25955 |
} else { |
| 25956 |
return 0; |
| 25957 |
} |
| 25958 |
} |
| 25959 |
this.getScreenLastRowColumn = function(screenRow) { |
| 25960 |
var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE); |
| 25961 |
return this.documentToScreenColumn(pos.row, pos.column); |
| 25962 |
}; |
| 25963 |
this.getDocumentLastRowColumn = function(docRow, docColumn) { |
| 25964 |
var screenRow = this.documentToScreenRow(docRow, docColumn); |
| 25965 |
return this.getScreenLastRowColumn(screenRow); |
| 25966 |
}; |
| 25967 |
this.getDocumentLastRowColumnPosition = function(docRow, docColumn) { |
| 25968 |
var screenRow = this.documentToScreenRow(docRow, docColumn); |
| 25969 |
return this.screenToDocumentPosition(screenRow, Number.MAX_VALUE / 10); |
| 25970 |
}; |
| 25971 |
this.getRowSplitData = function(row) { |
| 25972 |
if (!this.$useWrapMode) { |
| 25973 |
return undefined; |
| 25974 |
} else { |
| 25975 |
return this.$wrapData[row]; |
| 25976 |
} |
| 25977 |
}; |
| 25978 |
this.getScreenTabSize = function(screenColumn) { |
| 25979 |
return this.$tabSize - screenColumn % this.$tabSize; |
| 25980 |
}; |
| 25981 |
|
| 25982 |
|
| 25983 |
this.screenToDocumentRow = function(screenRow, screenColumn) { |
| 25984 |
return this.screenToDocumentPosition(screenRow, screenColumn).row; |
| 25985 |
}; |
| 25986 |
|
| 25987 |
|
| 25988 |
this.screenToDocumentColumn = function(screenRow, screenColumn) { |
| 25989 |
return this.screenToDocumentPosition(screenRow, screenColumn).column; |
| 25990 |
}; |
| 25991 |
this.screenToDocumentPosition = function(screenRow, screenColumn) { |
| 25992 |
if (screenRow < 0) |
| 25993 |
return {row: 0, column: 0}; |
| 25994 |
|
| 25995 |
var line; |
| 25996 |
var docRow = 0; |
| 25997 |
var docColumn = 0; |
| 25998 |
var column; |
| 25999 |
var row = 0; |
| 26000 |
var rowLength = 0; |
| 26001 |
|
| 26002 |
var rowCache = this.$screenRowCache; |
| 26003 |
var i = this.$getRowCacheIndex(rowCache, screenRow); |
| 26004 |
var l = rowCache.length; |
| 26005 |
if (l && i >= 0) { |
| 26006 |
var row = rowCache[i]; |
| 26007 |
var docRow = this.$docRowCache[i]; |
| 26008 |
var doCache = screenRow > rowCache[l - 1]; |
| 26009 |
} else { |
| 26010 |
var doCache = !l; |
| 26011 |
} |
| 26012 |
|
| 26013 |
var maxRow = this.getLength() - 1; |
| 26014 |
var foldLine = this.getNextFoldLine(docRow); |
| 26015 |
var foldStart = foldLine ? foldLine.start.row : Infinity; |
| 26016 |
|
| 26017 |
while (row <= screenRow) { |
| 26018 |
rowLength = this.getRowLength(docRow); |
| 26019 |
if (row + rowLength > screenRow || docRow >= maxRow) { |
| 26020 |
break; |
| 26021 |
} else { |
| 26022 |
row += rowLength; |
| 26023 |
docRow++; |
| 26024 |
if (docRow > foldStart) { |
| 26025 |
docRow = foldLine.end.row+1; |
| 26026 |
foldLine = this.getNextFoldLine(docRow, foldLine); |
| 26027 |
foldStart = foldLine ? foldLine.start.row : Infinity; |
| 26028 |
} |
| 26029 |
} |
| 26030 |
|
| 26031 |
if (doCache) { |
| 26032 |
this.$docRowCache.push(docRow); |
| 26033 |
this.$screenRowCache.push(row); |
| 26034 |
} |
| 26035 |
} |
| 26036 |
|
| 26037 |
if (foldLine && foldLine.start.row <= docRow) { |
| 26038 |
line = this.getFoldDisplayLine(foldLine); |
| 26039 |
docRow = foldLine.start.row; |
| 26040 |
} else if (row + rowLength <= screenRow || docRow > maxRow) { |
| 26041 |
return { |
| 26042 |
row: maxRow, |
| 26043 |
column: this.getLine(maxRow).length |
| 26044 |
}; |
| 26045 |
} else { |
| 26046 |
line = this.getLine(docRow); |
| 26047 |
foldLine = null; |
| 26048 |
} |
| 26049 |
var wrapIndent = 0; |
| 26050 |
if (this.$useWrapMode) { |
| 26051 |
var splits = this.$wrapData[docRow]; |
| 26052 |
if (splits) { |
| 26053 |
var splitIndex = Math.floor(screenRow - row); |
| 26054 |
column = splits[splitIndex]; |
| 26055 |
if(splitIndex > 0 && splits.length) { |
| 26056 |
wrapIndent = splits.indent; |
| 26057 |
docColumn = splits[splitIndex - 1] || splits[splits.length - 1]; |
| 26058 |
line = line.substring(docColumn); |
| 26059 |
} |
| 26060 |
} |
| 26061 |
} |
| 26062 |
|
| 26063 |
docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1]; |
| 26064 |
if (this.$useWrapMode && docColumn >= column) |
| 26065 |
docColumn = column - 1; |
| 26066 |
|
| 26067 |
if (foldLine) |
| 26068 |
return foldLine.idxToPosition(docColumn); |
| 26069 |
|
| 26070 |
return {row: docRow, column: docColumn}; |
| 26071 |
}; |
| 26072 |
this.documentToScreenPosition = function(docRow, docColumn) { |
| 26073 |
if (typeof docColumn === "undefined") |
| 26074 |
var pos = this.$clipPositionToDocument(docRow.row, docRow.column); |
| 26075 |
else |
| 26076 |
pos = this.$clipPositionToDocument(docRow, docColumn); |
| 26077 |
|
| 26078 |
docRow = pos.row; |
| 26079 |
docColumn = pos.column; |
| 26080 |
|
| 26081 |
var screenRow = 0; |
| 26082 |
var foldStartRow = null; |
| 26083 |
var fold = null; |
| 26084 |
fold = this.getFoldAt(docRow, docColumn, 1); |
| 26085 |
if (fold) { |
| 26086 |
docRow = fold.start.row; |
| 26087 |
docColumn = fold.start.column; |
| 26088 |
} |
| 26089 |
|
| 26090 |
var rowEnd, row = 0; |
| 26091 |
|
| 26092 |
|
| 26093 |
var rowCache = this.$docRowCache; |
| 26094 |
var i = this.$getRowCacheIndex(rowCache, docRow); |
| 26095 |
var l = rowCache.length; |
| 26096 |
if (l && i >= 0) { |
| 26097 |
var row = rowCache[i]; |
| 26098 |
var screenRow = this.$screenRowCache[i]; |
| 26099 |
var doCache = docRow > rowCache[l - 1]; |
| 26100 |
} else { |
| 26101 |
var doCache = !l; |
| 26102 |
} |
| 26103 |
|
| 26104 |
var foldLine = this.getNextFoldLine(row); |
| 26105 |
var foldStart = foldLine ?foldLine.start.row :Infinity; |
| 26106 |
|
| 26107 |
while (row < docRow) { |
| 26108 |
if (row >= foldStart) { |
| 26109 |
rowEnd = foldLine.end.row + 1; |
| 26110 |
if (rowEnd > docRow) |
| 26111 |
break; |
| 26112 |
foldLine = this.getNextFoldLine(rowEnd, foldLine); |
| 26113 |
foldStart = foldLine ?foldLine.start.row :Infinity; |
| 26114 |
} |
| 26115 |
else { |
| 26116 |
rowEnd = row + 1; |
| 26117 |
} |
| 26118 |
|
| 26119 |
screenRow += this.getRowLength(row); |
| 26120 |
row = rowEnd; |
| 26121 |
|
| 26122 |
if (doCache) { |
| 26123 |
this.$docRowCache.push(row); |
| 26124 |
this.$screenRowCache.push(screenRow); |
| 26125 |
} |
| 26126 |
} |
| 26127 |
var textLine = ""; |
| 26128 |
if (foldLine && row >= foldStart) { |
| 26129 |
textLine = this.getFoldDisplayLine(foldLine, docRow, docColumn); |
| 26130 |
foldStartRow = foldLine.start.row; |
| 26131 |
} else { |
| 26132 |
textLine = this.getLine(docRow).substring(0, docColumn); |
| 26133 |
foldStartRow = docRow; |
| 26134 |
} |
| 26135 |
var wrapIndent = 0; |
| 26136 |
if (this.$useWrapMode) { |
| 26137 |
var wrapRow = this.$wrapData[foldStartRow]; |
| 26138 |
if (wrapRow) { |
| 26139 |
var screenRowOffset = 0; |
| 26140 |
while (textLine.length >= wrapRow[screenRowOffset]) { |
| 26141 |
screenRow ++; |
| 26142 |
screenRowOffset++; |
| 26143 |
} |
| 26144 |
textLine = textLine.substring( |
| 26145 |
wrapRow[screenRowOffset - 1] || 0, textLine.length |
| 26146 |
); |
| 26147 |
wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0; |
| 26148 |
} |
| 26149 |
} |
| 26150 |
|
| 26151 |
return { |
| 26152 |
row: screenRow, |
| 26153 |
column: wrapIndent + this.$getStringScreenWidth(textLine)[0] |
| 26154 |
}; |
| 26155 |
}; |
| 26156 |
this.documentToScreenColumn = function(row, docColumn) { |
| 26157 |
return this.documentToScreenPosition(row, docColumn).column; |
| 26158 |
}; |
| 26159 |
this.documentToScreenRow = function(docRow, docColumn) { |
| 26160 |
return this.documentToScreenPosition(docRow, docColumn).row; |
| 26161 |
}; |
| 26162 |
this.getScreenLength = function() { |
| 26163 |
var screenRows = 0; |
| 26164 |
var fold = null; |
| 26165 |
if (!this.$useWrapMode) { |
| 26166 |
screenRows = this.getLength(); |
| 26167 |
var foldData = this.$foldData; |
| 26168 |
for (var i = 0; i < foldData.length; i++) { |
| 26169 |
fold = foldData[i]; |
| 26170 |
screenRows -= fold.end.row - fold.start.row; |
| 26171 |
} |
| 26172 |
} else { |
| 26173 |
var lastRow = this.$wrapData.length; |
| 26174 |
var row = 0, i = 0; |
| 26175 |
var fold = this.$foldData[i++]; |
| 26176 |
var foldStart = fold ? fold.start.row :Infinity; |
| 26177 |
|
| 26178 |
while (row < lastRow) { |
| 26179 |
var splits = this.$wrapData[row]; |
| 26180 |
screenRows += splits ? splits.length + 1 : 1; |
| 26181 |
row ++; |
| 26182 |
if (row > foldStart) { |
| 26183 |
row = fold.end.row+1; |
| 26184 |
fold = this.$foldData[i++]; |
| 26185 |
foldStart = fold ?fold.start.row :Infinity; |
| 26186 |
} |
| 26187 |
} |
| 26188 |
} |
| 26189 |
if (this.lineWidgets) |
| 26190 |
screenRows += this.$getWidgetScreenLength(); |
| 26191 |
|
| 26192 |
return screenRows; |
| 26193 |
}; |
| 26194 |
this.$setFontMetrics = function(fm) { |
| 26195 |
if (!this.$enableVarChar) return; |
| 26196 |
this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) { |
| 26197 |
if (maxScreenColumn === 0) |
| 26198 |
return [0, 0]; |
| 26199 |
if (!maxScreenColumn) |
| 26200 |
maxScreenColumn = Infinity; |
| 26201 |
screenColumn = screenColumn || 0; |
| 26202 |
|
| 26203 |
var c, column; |
| 26204 |
for (column = 0; column < str.length; column++) { |
| 26205 |
c = str.charAt(column); |
| 26206 |
if (c === "\t") { |
| 26207 |
screenColumn += this.getScreenTabSize(screenColumn); |
| 26208 |
} else { |
| 26209 |
screenColumn += fm.getCharacterWidth(c); |
| 26210 |
} |
| 26211 |
if (screenColumn > maxScreenColumn) { |
| 26212 |
break; |
| 26213 |
} |
| 26214 |
} |
| 26215 |
|
| 26216 |
return [screenColumn, column]; |
| 26217 |
}; |
| 26218 |
}; |
| 26219 |
|
| 26220 |
this.destroy = function() { |
| 26221 |
if (this.bgTokenizer) { |
| 26222 |
this.bgTokenizer.setDocument(null); |
| 26223 |
this.bgTokenizer = null; |
| 26224 |
} |
| 26225 |
this.$stopWorker(); |
| 26226 |
}; |
| 26227 |
function isFullWidth(c) { |
| 26228 |
if (c < 0x1100) |
| 26229 |
return false; |
| 26230 |
return c >= 0x1100 && c <= 0x115F || |
| 26231 |
c >= 0x11A3 && c <= 0x11A7 || |
| 26232 |
c >= 0x11FA && c <= 0x11FF || |
| 26233 |
c >= 0x2329 && c <= 0x232A || |
| 26234 |
c >= 0x2E80 && c <= 0x2E99 || |
| 26235 |
c >= 0x2E9B && c <= 0x2EF3 || |
| 26236 |
c >= 0x2F00 && c <= 0x2FD5 || |
| 26237 |
c >= 0x2FF0 && c <= 0x2FFB || |
| 26238 |
c >= 0x3000 && c <= 0x303E || |
| 26239 |
c >= 0x3041 && c <= 0x3096 || |
| 26240 |
c >= 0x3099 && c <= 0x30FF || |
| 26241 |
c >= 0x3105 && c <= 0x312D || |
| 26242 |
c >= 0x3131 && c <= 0x318E || |
| 26243 |
c >= 0x3190 && c <= 0x31BA || |
| 26244 |
c >= 0x31C0 && c <= 0x31E3 || |
| 26245 |
c >= 0x31F0 && c <= 0x321E || |
| 26246 |
c >= 0x3220 && c <= 0x3247 || |
| 26247 |
c >= 0x3250 && c <= 0x32FE || |
| 26248 |
c >= 0x3300 && c <= 0x4DBF || |
| 26249 |
c >= 0x4E00 && c <= 0xA48C || |
| 26250 |
c >= 0xA490 && c <= 0xA4C6 || |
| 26251 |
c >= 0xA960 && c <= 0xA97C || |
| 26252 |
c >= 0xAC00 && c <= 0xD7A3 || |
| 26253 |
c >= 0xD7B0 && c <= 0xD7C6 || |
| 26254 |
c >= 0xD7CB && c <= 0xD7FB || |
| 26255 |
c >= 0xF900 && c <= 0xFAFF || |
| 26256 |
c >= 0xFE10 && c <= 0xFE19 || |
| 26257 |
c >= 0xFE30 && c <= 0xFE52 || |
| 26258 |
c >= 0xFE54 && c <= 0xFE66 || |
| 26259 |
c >= 0xFE68 && c <= 0xFE6B || |
| 26260 |
c >= 0xFF01 && c <= 0xFF60 || |
| 26261 |
c >= 0xFFE0 && c <= 0xFFE6; |
| 26262 |
} |
| 26263 |
|
| 26264 |
}).call(EditSession.prototype); |
| 26265 |
|
| 26266 |
acequire("./edit_session/folding").Folding.call(EditSession.prototype); |
| 26267 |
acequire("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype); |
| 26268 |
|
| 26269 |
|
| 26270 |
config.defineOptions(EditSession.prototype, "session", { |
| 26271 |
wrap: { |
| 26272 |
set: function(value) { |
| 26273 |
if (!value || value == "off") |
| 26274 |
value = false; |
| 26275 |
else if (value == "free") |
| 26276 |
value = true; |
| 26277 |
else if (value == "printMargin") |
| 26278 |
value = -1; |
| 26279 |
else if (typeof value == "string") |
| 26280 |
value = parseInt(value, 10) || false; |
| 26281 |
|
| 26282 |
if (this.$wrap == value) |
| 26283 |
return; |
| 26284 |
this.$wrap = value; |
| 26285 |
if (!value) { |
| 26286 |
this.setUseWrapMode(false); |
| 26287 |
} else { |
| 26288 |
var col = typeof value == "number" ? value : null; |
| 26289 |
this.setWrapLimitRange(col, col); |
| 26290 |
this.setUseWrapMode(true); |
| 26291 |
} |
| 26292 |
}, |
| 26293 |
get: function() { |
| 26294 |
if (this.getUseWrapMode()) { |
| 26295 |
if (this.$wrap == -1) |
| 26296 |
return "printMargin"; |
| 26297 |
if (!this.getWrapLimitRange().min) |
| 26298 |
return "free"; |
| 26299 |
return this.$wrap; |
| 26300 |
} |
| 26301 |
return "off"; |
| 26302 |
}, |
| 26303 |
handlesSet: true |
| 26304 |
}, |
| 26305 |
wrapMethod: { |
| 26306 |
set: function(val) { |
| 26307 |
val = val == "auto" |
| 26308 |
? this.$mode.type != "text" |
| 26309 |
: val != "text"; |
| 26310 |
if (val != this.$wrapAsCode) { |
| 26311 |
this.$wrapAsCode = val; |
| 26312 |
if (this.$useWrapMode) { |
| 26313 |
this.$modified = true; |
| 26314 |
this.$resetRowCache(0); |
| 26315 |
this.$updateWrapData(0, this.getLength() - 1); |
| 26316 |
} |
| 26317 |
} |
| 26318 |
}, |
| 26319 |
initialValue: "auto" |
| 26320 |
}, |
| 26321 |
indentedSoftWrap: { initialValue: true }, |
| 26322 |
firstLineNumber: { |
| 26323 |
set: function() {this._signal("changeBreakpoint");}, |
| 26324 |
initialValue: 1 |
| 26325 |
}, |
| 26326 |
useWorker: { |
| 26327 |
set: function(useWorker) { |
| 26328 |
this.$useWorker = useWorker; |
| 26329 |
|
| 26330 |
this.$stopWorker(); |
| 26331 |
if (useWorker) |
| 26332 |
this.$startWorker(); |
| 26333 |
}, |
| 26334 |
initialValue: true |
| 26335 |
}, |
| 26336 |
useSoftTabs: {initialValue: true}, |
| 26337 |
tabSize: { |
| 26338 |
set: function(tabSize) { |
| 26339 |
if (isNaN(tabSize) || this.$tabSize === tabSize) return; |
| 26340 |
|
| 26341 |
this.$modified = true; |
| 26342 |
this.$rowLengthCache = []; |
| 26343 |
this.$tabSize = tabSize; |
| 26344 |
this._signal("changeTabSize"); |
| 26345 |
}, |
| 26346 |
initialValue: 4, |
| 26347 |
handlesSet: true |
| 26348 |
}, |
| 26349 |
overwrite: { |
| 26350 |
set: function(val) {this._signal("changeOverwrite");}, |
| 26351 |
initialValue: false |
| 26352 |
}, |
| 26353 |
newLineMode: { |
| 26354 |
set: function(val) {this.doc.setNewLineMode(val)}, |
| 26355 |
get: function() {return this.doc.getNewLineMode()}, |
| 26356 |
handlesSet: true |
| 26357 |
}, |
| 26358 |
mode: { |
| 26359 |
set: function(val) { this.setMode(val) }, |
| 26360 |
get: function() { return this.$modeId } |
| 26361 |
} |
| 26362 |
}); |
| 26363 |
|
| 26364 |
exports.EditSession = EditSession; |
| 26365 |
}); |
| 26366 |
|
| 26367 |
ace.define("ace/search",["require","exports","module","ace/lib/lang","ace/lib/oop","ace/range"], function(acequire, exports, module) { |
| 26368 |
"use strict"; |
| 26369 |
|
| 26370 |
var lang = acequire("./lib/lang"); |
| 26371 |
var oop = acequire("./lib/oop"); |
| 26372 |
var Range = acequire("./range").Range; |
| 26373 |
|
| 26374 |
var Search = function() { |
| 26375 |
this.$options = {}; |
| 26376 |
}; |
| 26377 |
|
| 26378 |
(function() { |
| 26379 |
this.set = function(options) { |
| 26380 |
oop.mixin(this.$options, options); |
| 26381 |
return this; |
| 26382 |
}; |
| 26383 |
this.getOptions = function() { |
| 26384 |
return lang.copyObject(this.$options); |
| 26385 |
}; |
| 26386 |
this.setOptions = function(options) { |
| 26387 |
this.$options = options; |
| 26388 |
}; |
| 26389 |
this.find = function(session) { |
| 26390 |
var options = this.$options; |
| 26391 |
var iterator = this.$matchIterator(session, options); |
| 26392 |
if (!iterator) |
| 26393 |
return false; |
| 26394 |
|
| 26395 |
var firstRange = null; |
| 26396 |
iterator.forEach(function(range, row, offset) { |
| 26397 |
if (!range.start) { |
| 26398 |
var column = range.offset + (offset || 0); |
| 26399 |
firstRange = new Range(row, column, row, column + range.length); |
| 26400 |
if (!range.length && options.start && options.start.start |
| 26401 |
&& options.skipCurrent != false && firstRange.isEqual(options.start) |
| 26402 |
) { |
| 26403 |
firstRange = null; |
| 26404 |
return false; |
| 26405 |
} |
| 26406 |
} else |
| 26407 |
firstRange = range; |
| 26408 |
return true; |
| 26409 |
}); |
| 26410 |
|
| 26411 |
return firstRange; |
| 26412 |
}; |
| 26413 |
this.findAll = function(session) { |
| 26414 |
var options = this.$options; |
| 26415 |
if (!options.needle) |
| 26416 |
return []; |
| 26417 |
this.$assembleRegExp(options); |
| 26418 |
|
| 26419 |
var range = options.range; |
| 26420 |
var lines = range |
| 26421 |
? session.getLines(range.start.row, range.end.row) |
| 26422 |
: session.doc.getAllLines(); |
| 26423 |
|
| 26424 |
var ranges = []; |
| 26425 |
var re = options.re; |
| 26426 |
if (options.$isMultiLine) { |
| 26427 |
var len = re.length; |
| 26428 |
var maxRow = lines.length - len; |
| 26429 |
var prevRange; |
| 26430 |
outer: for (var row = re.offset || 0; row <= maxRow; row++) { |
| 26431 |
for (var j = 0; j < len; j++) |
| 26432 |
if (lines[row + j].search(re[j]) == -1) |
| 26433 |
continue outer; |
| 26434 |
|
| 26435 |
var startLine = lines[row]; |
| 26436 |
var line = lines[row + len - 1]; |
| 26437 |
var startIndex = startLine.length - startLine.match(re[0])[0].length; |
| 26438 |
var endIndex = line.match(re[len - 1])[0].length; |
| 26439 |
|
| 26440 |
if (prevRange && prevRange.end.row === row && |
| 26441 |
prevRange.end.column > startIndex |
| 26442 |
) { |
| 26443 |
continue; |
| 26444 |
} |
| 26445 |
ranges.push(prevRange = new Range( |
| 26446 |
row, startIndex, row + len - 1, endIndex |
| 26447 |
)); |
| 26448 |
if (len > 2) |
| 26449 |
row = row + len - 2; |
| 26450 |
} |
| 26451 |
} else { |
| 26452 |
for (var i = 0; i < lines.length; i++) { |
| 26453 |
var matches = lang.getMatchOffsets(lines[i], re); |
| 26454 |
for (var j = 0; j < matches.length; j++) { |
| 26455 |
var match = matches[j]; |
| 26456 |
ranges.push(new Range(i, match.offset, i, match.offset + match.length)); |
| 26457 |
} |
| 26458 |
} |
| 26459 |
} |
| 26460 |
|
| 26461 |
if (range) { |
| 26462 |
var startColumn = range.start.column; |
| 26463 |
var endColumn = range.start.column; |
| 26464 |
var i = 0, j = ranges.length - 1; |
| 26465 |
while (i < j && ranges[i].start.column < startColumn && ranges[i].start.row == range.start.row) |
| 26466 |
i++; |
| 26467 |
|
| 26468 |
while (i < j && ranges[j].end.column > endColumn && ranges[j].end.row == range.end.row) |
| 26469 |
j--; |
| 26470 |
|
| 26471 |
ranges = ranges.slice(i, j + 1); |
| 26472 |
for (i = 0, j = ranges.length; i < j; i++) { |
| 26473 |
ranges[i].start.row += range.start.row; |
| 26474 |
ranges[i].end.row += range.start.row; |
| 26475 |
} |
| 26476 |
} |
| 26477 |
|
| 26478 |
return ranges; |
| 26479 |
}; |
| 26480 |
this.replace = function(input, replacement) { |
| 26481 |
var options = this.$options; |
| 26482 |
|
| 26483 |
var re = this.$assembleRegExp(options); |
| 26484 |
if (options.$isMultiLine) |
| 26485 |
return replacement; |
| 26486 |
|
| 26487 |
if (!re) |
| 26488 |
return; |
| 26489 |
|
| 26490 |
var match = re.exec(input); |
| 26491 |
if (!match || match[0].length != input.length) |
| 26492 |
return null; |
| 26493 |
|
| 26494 |
replacement = input.replace(re, replacement); |
| 26495 |
if (options.preserveCase) { |
| 26496 |
replacement = replacement.split(""); |
| 26497 |
for (var i = Math.min(input.length, input.length); i--; ) { |
| 26498 |
var ch = input[i]; |
| 26499 |
if (ch && ch.toLowerCase() != ch) |
| 26500 |
replacement[i] = replacement[i].toUpperCase(); |
| 26501 |
else |
| 26502 |
replacement[i] = replacement[i].toLowerCase(); |
| 26503 |
} |
| 26504 |
replacement = replacement.join(""); |
| 26505 |
} |
| 26506 |
|
| 26507 |
return replacement; |
| 26508 |
}; |
| 26509 |
|
| 26510 |
this.$matchIterator = function(session, options) { |
| 26511 |
var re = this.$assembleRegExp(options); |
| 26512 |
if (!re) |
| 26513 |
return false; |
| 26514 |
|
| 26515 |
var callback; |
| 26516 |
if (options.$isMultiLine) { |
| 26517 |
var len = re.length; |
| 26518 |
var matchIterator = function(line, row, offset) { |
| 26519 |
var startIndex = line.search(re[0]); |
| 26520 |
if (startIndex == -1) |
| 26521 |
return; |
| 26522 |
for (var i = 1; i < len; i++) { |
| 26523 |
line = session.getLine(row + i); |
| 26524 |
if (line.search(re[i]) == -1) |
| 26525 |
return; |
| 26526 |
} |
| 26527 |
|
| 26528 |
var endIndex = line.match(re[len - 1])[0].length; |
| 26529 |
|
| 26530 |
var range = new Range(row, startIndex, row + len - 1, endIndex); |
| 26531 |
if (re.offset == 1) { |
| 26532 |
range.start.row--; |
| 26533 |
range.start.column = Number.MAX_VALUE; |
| 26534 |
} else if (offset) |
| 26535 |
range.start.column += offset; |
| 26536 |
|
| 26537 |
if (callback(range)) |
| 26538 |
return true; |
| 26539 |
}; |
| 26540 |
} else if (options.backwards) { |
| 26541 |
var matchIterator = function(line, row, startIndex) { |
| 26542 |
var matches = lang.getMatchOffsets(line, re); |
| 26543 |
for (var i = matches.length-1; i >= 0; i--) |
| 26544 |
if (callback(matches[i], row, startIndex)) |
| 26545 |
return true; |
| 26546 |
}; |
| 26547 |
} else { |
| 26548 |
var matchIterator = function(line, row, startIndex) { |
| 26549 |
var matches = lang.getMatchOffsets(line, re); |
| 26550 |
for (var i = 0; i < matches.length; i++) |
| 26551 |
if (callback(matches[i], row, startIndex)) |
| 26552 |
return true; |
| 26553 |
}; |
| 26554 |
} |
| 26555 |
|
| 26556 |
var lineIterator = this.$lineIterator(session, options); |
| 26557 |
|
| 26558 |
return { |
| 26559 |
forEach: function(_callback) { |
| 26560 |
callback = _callback; |
| 26561 |
lineIterator.forEach(matchIterator); |
| 26562 |
} |
| 26563 |
}; |
| 26564 |
}; |
| 26565 |
|
| 26566 |
this.$assembleRegExp = function(options, $disableFakeMultiline) { |
| 26567 |
if (options.needle instanceof RegExp) |
| 26568 |
return options.re = options.needle; |
| 26569 |
|
| 26570 |
var needle = options.needle; |
| 26571 |
|
| 26572 |
if (!options.needle) |
| 26573 |
return options.re = false; |
| 26574 |
|
| 26575 |
if (!options.regExp) |
| 26576 |
needle = lang.escapeRegExp(needle); |
| 26577 |
|
| 26578 |
if (options.wholeWord) |
| 26579 |
needle = "\\b" + needle + "\\b"; |
| 26580 |
|
| 26581 |
var modifier = options.caseSensitive ? "gm" : "gmi"; |
| 26582 |
|
| 26583 |
options.$isMultiLine = !$disableFakeMultiline && /[\n\r]/.test(needle); |
| 26584 |
if (options.$isMultiLine) |
| 26585 |
return options.re = this.$assembleMultilineRegExp(needle, modifier); |
| 26586 |
|
| 26587 |
try { |
| 26588 |
var re = new RegExp(needle, modifier); |
| 26589 |
} catch(e) { |
| 26590 |
re = false; |
| 26591 |
} |
| 26592 |
return options.re = re; |
| 26593 |
}; |
| 26594 |
|
| 26595 |
this.$assembleMultilineRegExp = function(needle, modifier) { |
| 26596 |
var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n"); |
| 26597 |
var re = []; |
| 26598 |
for (var i = 0; i < parts.length; i++) try { |
| 26599 |
re.push(new RegExp(parts[i], modifier)); |
| 26600 |
} catch(e) { |
| 26601 |
return false; |
| 26602 |
} |
| 26603 |
if (parts[0] == "") { |
| 26604 |
re.shift(); |
| 26605 |
re.offset = 1; |
| 26606 |
} else { |
| 26607 |
re.offset = 0; |
| 26608 |
} |
| 26609 |
return re; |
| 26610 |
}; |
| 26611 |
|
| 26612 |
this.$lineIterator = function(session, options) { |
| 26613 |
var backwards = options.backwards == true; |
| 26614 |
var skipCurrent = options.skipCurrent != false; |
| 26615 |
|
| 26616 |
var range = options.range; |
| 26617 |
var start = options.start; |
| 26618 |
if (!start) |
| 26619 |
start = range ? range[backwards ? "end" : "start"] : session.selection.getRange(); |
| 26620 |
|
| 26621 |
if (start.start) |
| 26622 |
start = start[skipCurrent != backwards ? "end" : "start"]; |
| 26623 |
|
| 26624 |
var firstRow = range ? range.start.row : 0; |
| 26625 |
var lastRow = range ? range.end.row : session.getLength() - 1; |
| 26626 |
|
| 26627 |
var forEach = backwards ? function(callback) { |
| 26628 |
var row = start.row; |
| 26629 |
|
| 26630 |
var line = session.getLine(row).substring(0, start.column); |
| 26631 |
if (callback(line, row)) |
| 26632 |
return; |
| 26633 |
|
| 26634 |
for (row--; row >= firstRow; row--) |
| 26635 |
if (callback(session.getLine(row), row)) |
| 26636 |
return; |
| 26637 |
|
| 26638 |
if (options.wrap == false) |
| 26639 |
return; |
| 26640 |
|
| 26641 |
for (row = lastRow, firstRow = start.row; row >= firstRow; row--) |
| 26642 |
if (callback(session.getLine(row), row)) |
| 26643 |
return; |
| 26644 |
} : function(callback) { |
| 26645 |
var row = start.row; |
| 26646 |
|
| 26647 |
var line = session.getLine(row).substr(start.column); |
| 26648 |
if (callback(line, row, start.column)) |
| 26649 |
return; |
| 26650 |
|
| 26651 |
for (row = row+1; row <= lastRow; row++) |
| 26652 |
if (callback(session.getLine(row), row)) |
| 26653 |
return; |
| 26654 |
|
| 26655 |
if (options.wrap == false) |
| 26656 |
return; |
| 26657 |
|
| 26658 |
for (row = firstRow, lastRow = start.row; row <= lastRow; row++) |
| 26659 |
if (callback(session.getLine(row), row)) |
| 26660 |
return; |
| 26661 |
}; |
| 26662 |
|
| 26663 |
return {forEach: forEach}; |
| 26664 |
}; |
| 26665 |
|
| 26666 |
}).call(Search.prototype); |
| 26667 |
|
| 26668 |
exports.Search = Search; |
| 26669 |
}); |
| 26670 |
|
| 26671 |
ace.define("ace/keyboard/hash_handler",["require","exports","module","ace/lib/keys","ace/lib/useragent"], function(acequire, exports, module) { |
| 26672 |
"use strict"; |
| 26673 |
|
| 26674 |
var keyUtil = acequire("../lib/keys"); |
| 26675 |
var useragent = acequire("../lib/useragent"); |
| 26676 |
var KEY_MODS = keyUtil.KEY_MODS; |
| 26677 |
|
| 26678 |
function HashHandler(config, platform) { |
| 26679 |
this.platform = platform || (useragent.isMac ? "mac" : "win"); |
| 26680 |
this.commands = {}; |
| 26681 |
this.commandKeyBinding = {}; |
| 26682 |
this.addCommands(config); |
| 26683 |
this.$singleCommand = true; |
| 26684 |
} |
| 26685 |
|
| 26686 |
function MultiHashHandler(config, platform) { |
| 26687 |
HashHandler.call(this, config, platform); |
| 26688 |
this.$singleCommand = false; |
| 26689 |
} |
| 26690 |
|
| 26691 |
MultiHashHandler.prototype = HashHandler.prototype; |
| 26692 |
|
| 26693 |
(function() { |
| 26694 |
|
| 26695 |
|
| 26696 |
this.addCommand = function(command) { |
| 26697 |
if (this.commands[command.name]) |
| 26698 |
this.removeCommand(command); |
| 26699 |
|
| 26700 |
this.commands[command.name] = command; |
| 26701 |
|
| 26702 |
if (command.bindKey) |
| 26703 |
this._buildKeyHash(command); |
| 26704 |
}; |
| 26705 |
|
| 26706 |
this.removeCommand = function(command, keepCommand) { |
| 26707 |
var name = command && (typeof command === 'string' ? command : command.name); |
| 26708 |
command = this.commands[name]; |
| 26709 |
if (!keepCommand) |
| 26710 |
delete this.commands[name]; |
| 26711 |
var ckb = this.commandKeyBinding; |
| 26712 |
for (var keyId in ckb) { |
| 26713 |
var cmdGroup = ckb[keyId]; |
| 26714 |
if (cmdGroup == command) { |
| 26715 |
delete ckb[keyId]; |
| 26716 |
} else if (Array.isArray(cmdGroup)) { |
| 26717 |
var i = cmdGroup.indexOf(command); |
| 26718 |
if (i != -1) { |
| 26719 |
cmdGroup.splice(i, 1); |
| 26720 |
if (cmdGroup.length == 1) |
| 26721 |
ckb[keyId] = cmdGroup[0]; |
| 26722 |
} |
| 26723 |
} |
| 26724 |
} |
| 26725 |
}; |
| 26726 |
|
| 26727 |
this.bindKey = function(key, command, position) { |
| 26728 |
if (typeof key == "object" && key) { |
| 26729 |
if (position == undefined) |
| 26730 |
position = key.position; |
| 26731 |
key = key[this.platform]; |
| 26732 |
} |
| 26733 |
if (!key) |
| 26734 |
return; |
| 26735 |
if (typeof command == "function") |
| 26736 |
return this.addCommand({exec: command, bindKey: key, name: command.name || key}); |
| 26737 |
|
| 26738 |
key.split("|").forEach(function(keyPart) { |
| 26739 |
var chain = ""; |
| 26740 |
if (keyPart.indexOf(" ") != -1) { |
| 26741 |
var parts = keyPart.split(/\s+/); |
| 26742 |
keyPart = parts.pop(); |
| 26743 |
parts.forEach(function(keyPart) { |
| 26744 |
var binding = this.parseKeys(keyPart); |
| 26745 |
var id = KEY_MODS[binding.hashId] + binding.key; |
| 26746 |
chain += (chain ? " " : "") + id; |
| 26747 |
this._addCommandToBinding(chain, "chainKeys"); |
| 26748 |
}, this); |
| 26749 |
chain += " "; |
| 26750 |
} |
| 26751 |
var binding = this.parseKeys(keyPart); |
| 26752 |
var id = KEY_MODS[binding.hashId] + binding.key; |
| 26753 |
this._addCommandToBinding(chain + id, command, position); |
| 26754 |
}, this); |
| 26755 |
}; |
| 26756 |
|
| 26757 |
function getPosition(command) { |
| 26758 |
return typeof command == "object" && command.bindKey |
| 26759 |
&& command.bindKey.position || 0; |
| 26760 |
} |
| 26761 |
this._addCommandToBinding = function(keyId, command, position) { |
| 26762 |
var ckb = this.commandKeyBinding, i; |
| 26763 |
if (!command) { |
| 26764 |
delete ckb[keyId]; |
| 26765 |
} else if (!ckb[keyId] || this.$singleCommand) { |
| 26766 |
ckb[keyId] = command; |
| 26767 |
} else { |
| 26768 |
if (!Array.isArray(ckb[keyId])) { |
| 26769 |
ckb[keyId] = [ckb[keyId]]; |
| 26770 |
} else if ((i = ckb[keyId].indexOf(command)) != -1) { |
| 26771 |
ckb[keyId].splice(i, 1); |
| 26772 |
} |
| 26773 |
|
| 26774 |
if (typeof position != "number") { |
| 26775 |
if (position || command.isDefault) |
| 26776 |
position = -100; |
| 26777 |
else |
| 26778 |
position = getPosition(command); |
| 26779 |
} |
| 26780 |
var commands = ckb[keyId]; |
| 26781 |
for (i = 0; i < commands.length; i++) { |
| 26782 |
var other = commands[i]; |
| 26783 |
var otherPos = getPosition(other); |
| 26784 |
if (otherPos > position) |
| 26785 |
break; |
| 26786 |
} |
| 26787 |
commands.splice(i, 0, command); |
| 26788 |
} |
| 26789 |
}; |
| 26790 |
|
| 26791 |
this.addCommands = function(commands) { |
| 26792 |
commands && Object.keys(commands).forEach(function(name) { |
| 26793 |
var command = commands[name]; |
| 26794 |
if (!command) |
| 26795 |
return; |
| 26796 |
|
| 26797 |
if (typeof command === "string") |
| 26798 |
return this.bindKey(command, name); |
| 26799 |
|
| 26800 |
if (typeof command === "function") |
| 26801 |
command = { exec: command }; |
| 26802 |
|
| 26803 |
if (typeof command !== "object") |
| 26804 |
return; |
| 26805 |
|
| 26806 |
if (!command.name) |
| 26807 |
command.name = name; |
| 26808 |
|
| 26809 |
this.addCommand(command); |
| 26810 |
}, this); |
| 26811 |
}; |
| 26812 |
|
| 26813 |
this.removeCommands = function(commands) { |
| 26814 |
Object.keys(commands).forEach(function(name) { |
| 26815 |
this.removeCommand(commands[name]); |
| 26816 |
}, this); |
| 26817 |
}; |
| 26818 |
|
| 26819 |
this.bindKeys = function(keyList) { |
| 26820 |
Object.keys(keyList).forEach(function(key) { |
| 26821 |
this.bindKey(key, keyList[key]); |
| 26822 |
}, this); |
| 26823 |
}; |
| 26824 |
|
| 26825 |
this._buildKeyHash = function(command) { |
| 26826 |
this.bindKey(command.bindKey, command); |
| 26827 |
}; |
| 26828 |
this.parseKeys = function(keys) { |
| 26829 |
var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x}); |
| 26830 |
var key = parts.pop(); |
| 26831 |
|
| 26832 |
var keyCode = keyUtil[key]; |
| 26833 |
if (keyUtil.FUNCTION_KEYS[keyCode]) |
| 26834 |
key = keyUtil.FUNCTION_KEYS[keyCode].toLowerCase(); |
| 26835 |
else if (!parts.length) |
| 26836 |
return {key: key, hashId: -1}; |
| 26837 |
else if (parts.length == 1 && parts[0] == "shift") |
| 26838 |
return {key: key.toUpperCase(), hashId: -1}; |
| 26839 |
|
| 26840 |
var hashId = 0; |
| 26841 |
for (var i = parts.length; i--;) { |
| 26842 |
var modifier = keyUtil.KEY_MODS[parts[i]]; |
| 26843 |
if (modifier == null) { |
| 26844 |
if (typeof console != "undefined") |
| 26845 |
console.error("invalid modifier " + parts[i] + " in " + keys); |
| 26846 |
return false; |
| 26847 |
} |
| 26848 |
hashId |= modifier; |
| 26849 |
} |
| 26850 |
return {key: key, hashId: hashId}; |
| 26851 |
}; |
| 26852 |
|
| 26853 |
this.findKeyCommand = function findKeyCommand(hashId, keyString) { |
| 26854 |
var key = KEY_MODS[hashId] + keyString; |
| 26855 |
return this.commandKeyBinding[key]; |
| 26856 |
}; |
| 26857 |
|
| 26858 |
this.handleKeyboard = function(data, hashId, keyString, keyCode) { |
| 26859 |
if (keyCode < 0) return; |
| 26860 |
var key = KEY_MODS[hashId] + keyString; |
| 26861 |
var command = this.commandKeyBinding[key]; |
| 26862 |
if (data.$keyChain) { |
| 26863 |
data.$keyChain += " " + key; |
| 26864 |
command = this.commandKeyBinding[data.$keyChain] || command; |
| 26865 |
} |
| 26866 |
|
| 26867 |
if (command) { |
| 26868 |
if (command == "chainKeys" || command[command.length - 1] == "chainKeys") { |
| 26869 |
data.$keyChain = data.$keyChain || key; |
| 26870 |
return {command: "null"}; |
| 26871 |
} |
| 26872 |
} |
| 26873 |
|
| 26874 |
if (data.$keyChain) { |
| 26875 |
if ((!hashId || hashId == 4) && keyString.length == 1) |
| 26876 |
data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input |
| 26877 |
else if (hashId == -1 || keyCode > 0) |
| 26878 |
data.$keyChain = ""; // reset keyChain |
| 26879 |
} |
| 26880 |
return {command: command}; |
| 26881 |
}; |
| 26882 |
|
| 26883 |
this.getStatusText = function(editor, data) { |
| 26884 |
return data.$keyChain || ""; |
| 26885 |
}; |
| 26886 |
|
| 26887 |
}).call(HashHandler.prototype); |
| 26888 |
|
| 26889 |
exports.HashHandler = HashHandler; |
| 26890 |
exports.MultiHashHandler = MultiHashHandler; |
| 26891 |
}); |
| 26892 |
|
| 26893 |
ace.define("ace/commands/command_manager",["require","exports","module","ace/lib/oop","ace/keyboard/hash_handler","ace/lib/event_emitter"], function(acequire, exports, module) { |
| 26894 |
"use strict"; |
| 26895 |
|
| 26896 |
var oop = acequire("../lib/oop"); |
| 26897 |
var MultiHashHandler = acequire("../keyboard/hash_handler").MultiHashHandler; |
| 26898 |
var EventEmitter = acequire("../lib/event_emitter").EventEmitter; |
| 26899 |
|
| 26900 |
var CommandManager = function(platform, commands) { |
| 26901 |
MultiHashHandler.call(this, commands, platform); |
| 26902 |
this.byName = this.commands; |
| 26903 |
this.setDefaultHandler("exec", function(e) { |
| 26904 |
return e.command.exec(e.editor, e.args || {}); |
| 26905 |
}); |
| 26906 |
}; |
| 26907 |
|
| 26908 |
oop.inherits(CommandManager, MultiHashHandler); |
| 26909 |
|
| 26910 |
(function() { |
| 26911 |
|
| 26912 |
oop.implement(this, EventEmitter); |
| 26913 |
|
| 26914 |
this.exec = function(command, editor, args) { |
| 26915 |
if (Array.isArray(command)) { |
| 26916 |
for (var i = command.length; i--; ) { |
| 26917 |
if (this.exec(command[i], editor, args)) return true; |
| 26918 |
} |
| 26919 |
return false; |
| 26920 |
} |
| 26921 |
|
| 26922 |
if (typeof command === "string") |
| 26923 |
command = this.commands[command]; |
| 26924 |
|
| 26925 |
if (!command) |
| 26926 |
return false; |
| 26927 |
|
| 26928 |
if (editor && editor.$readOnly && !command.readOnly) |
| 26929 |
return false; |
| 26930 |
|
| 26931 |
var e = {editor: editor, command: command, args: args}; |
| 26932 |
e.returnValue = this._emit("exec", e); |
| 26933 |
this._signal("afterExec", e); |
| 26934 |
|
| 26935 |
return e.returnValue === false ? false : true; |
| 26936 |
}; |
| 26937 |
|
| 26938 |
this.toggleRecording = function(editor) { |
| 26939 |
if (this.$inReplay) |
| 26940 |
return; |
| 26941 |
|
| 26942 |
editor && editor._emit("changeStatus"); |
| 26943 |
if (this.recording) { |
| 26944 |
this.macro.pop(); |
| 26945 |
this.removeEventListener("exec", this.$addCommandToMacro); |
| 26946 |
|
| 26947 |
if (!this.macro.length) |
| 26948 |
this.macro = this.oldMacro; |
| 26949 |
|
| 26950 |
return this.recording = false; |
| 26951 |
} |
| 26952 |
if (!this.$addCommandToMacro) { |
| 26953 |
this.$addCommandToMacro = function(e) { |
| 26954 |
this.macro.push([e.command, e.args]); |
| 26955 |
}.bind(this); |
| 26956 |
} |
| 26957 |
|
| 26958 |
this.oldMacro = this.macro; |
| 26959 |
this.macro = []; |
| 26960 |
this.on("exec", this.$addCommandToMacro); |
| 26961 |
return this.recording = true; |
| 26962 |
}; |
| 26963 |
|
| 26964 |
this.replay = function(editor) { |
| 26965 |
if (this.$inReplay || !this.macro) |
| 26966 |
return; |
| 26967 |
|
| 26968 |
if (this.recording) |
| 26969 |
return this.toggleRecording(editor); |
| 26970 |
|
| 26971 |
try { |
| 26972 |
this.$inReplay = true; |
| 26973 |
this.macro.forEach(function(x) { |
| 26974 |
if (typeof x == "string") |
| 26975 |
this.exec(x, editor); |
| 26976 |
else |
| 26977 |
this.exec(x[0], editor, x[1]); |
| 26978 |
}, this); |
| 26979 |
} finally { |
| 26980 |
this.$inReplay = false; |
| 26981 |
} |
| 26982 |
}; |
| 26983 |
|
| 26984 |
this.trimMacro = function(m) { |
| 26985 |
return m.map(function(x){ |
| 26986 |
if (typeof x[0] != "string") |
| 26987 |
x[0] = x[0].name; |
| 26988 |
if (!x[1]) |
| 26989 |
x = x[0]; |
| 26990 |
return x; |
| 26991 |
}); |
| 26992 |
}; |
| 26993 |
|
| 26994 |
}).call(CommandManager.prototype); |
| 26995 |
|
| 26996 |
exports.CommandManager = CommandManager; |
| 26997 |
|
| 26998 |
}); |
| 26999 |
|
| 27000 |
ace.define("ace/commands/default_commands",["require","exports","module","ace/lib/lang","ace/config","ace/range"], function(acequire, exports, module) { |
| 27001 |
"use strict"; |
| 27002 |
|
| 27003 |
var lang = acequire("../lib/lang"); |
| 27004 |
var config = acequire("../config"); |
| 27005 |
var Range = acequire("../range").Range; |
| 27006 |
|
| 27007 |
function bindKey(win, mac) { |
| 27008 |
return {win: win, mac: mac}; |
| 27009 |
} |
| 27010 |
exports.commands = [{ |
| 27011 |
name: "showSettingsMenu", |
| 27012 |
bindKey: bindKey("Ctrl-,", "Command-,"), |
| 27013 |
exec: function(editor) { |
| 27014 |
config.loadModule("ace/ext/settings_menu", function(module) { |
| 27015 |
module.init(editor); |
| 27016 |
editor.showSettingsMenu(); |
| 27017 |
}); |
| 27018 |
}, |
| 27019 |
readOnly: true |
| 27020 |
}, { |
| 27021 |
name: "goToNextError", |
| 27022 |
bindKey: bindKey("Alt-E", "Ctrl-E"), |
| 27023 |
exec: function(editor) { |
| 27024 |
config.loadModule("ace/ext/error_marker", function(module) { |
| 27025 |
module.showErrorMarker(editor, 1); |
| 27026 |
}); |
| 27027 |
}, |
| 27028 |
scrollIntoView: "animate", |
| 27029 |
readOnly: true |
| 27030 |
}, { |
| 27031 |
name: "goToPreviousError", |
| 27032 |
bindKey: bindKey("Alt-Shift-E", "Ctrl-Shift-E"), |
| 27033 |
exec: function(editor) { |
| 27034 |
config.loadModule("ace/ext/error_marker", function(module) { |
| 27035 |
module.showErrorMarker(editor, -1); |
| 27036 |
}); |
| 27037 |
}, |
| 27038 |
scrollIntoView: "animate", |
| 27039 |
readOnly: true |
| 27040 |
}, { |
| 27041 |
name: "selectall", |
| 27042 |
bindKey: bindKey("Ctrl-A", "Command-A"), |
| 27043 |
exec: function(editor) { editor.selectAll(); }, |
| 27044 |
readOnly: true |
| 27045 |
}, { |
| 27046 |
name: "centerselection", |
| 27047 |
bindKey: bindKey(null, "Ctrl-L"), |
| 27048 |
exec: function(editor) { editor.centerSelection(); }, |
| 27049 |
readOnly: true |
| 27050 |
}, { |
| 27051 |
name: "gotoline", |
| 27052 |
bindKey: bindKey("Ctrl-L", "Command-L"), |
| 27053 |
exec: function(editor) { |
| 27054 |
var line = parseInt(prompt("Enter line number:"), 10); |
| 27055 |
if (!isNaN(line)) { |
| 27056 |
editor.gotoLine(line); |
| 27057 |
} |
| 27058 |
}, |
| 27059 |
readOnly: true |
| 27060 |
}, { |
| 27061 |
name: "fold", |
| 27062 |
bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"), |
| 27063 |
exec: function(editor) { editor.session.toggleFold(false); }, |
| 27064 |
multiSelectAction: "forEach", |
| 27065 |
scrollIntoView: "center", |
| 27066 |
readOnly: true |
| 27067 |
}, { |
| 27068 |
name: "unfold", |
| 27069 |
bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"), |
| 27070 |
exec: function(editor) { editor.session.toggleFold(true); }, |
| 27071 |
multiSelectAction: "forEach", |
| 27072 |
scrollIntoView: "center", |
| 27073 |
readOnly: true |
| 27074 |
}, { |
| 27075 |
name: "toggleFoldWidget", |
| 27076 |
bindKey: bindKey("F2", "F2"), |
| 27077 |
exec: function(editor) { editor.session.toggleFoldWidget(); }, |
| 27078 |
multiSelectAction: "forEach", |
| 27079 |
scrollIntoView: "center", |
| 27080 |
readOnly: true |
| 27081 |
}, { |
| 27082 |
name: "toggleParentFoldWidget", |
| 27083 |
bindKey: bindKey("Alt-F2", "Alt-F2"), |
| 27084 |
exec: function(editor) { editor.session.toggleFoldWidget(true); }, |
| 27085 |
multiSelectAction: "forEach", |
| 27086 |
scrollIntoView: "center", |
| 27087 |
readOnly: true |
| 27088 |
}, { |
| 27089 |
name: "foldall", |
| 27090 |
bindKey: bindKey(null, "Ctrl-Command-Option-0"), |
| 27091 |
exec: function(editor) { editor.session.foldAll(); }, |
| 27092 |
scrollIntoView: "center", |
| 27093 |
readOnly: true |
| 27094 |
}, { |
| 27095 |
name: "foldOther", |
| 27096 |
bindKey: bindKey("Alt-0", "Command-Option-0"), |
| 27097 |
exec: function(editor) { |
| 27098 |
editor.session.foldAll(); |
| 27099 |
editor.session.unfold(editor.selection.getAllRanges()); |
| 27100 |
}, |
| 27101 |
scrollIntoView: "center", |
| 27102 |
readOnly: true |
| 27103 |
}, { |
| 27104 |
name: "unfoldall", |
| 27105 |
bindKey: bindKey("Alt-Shift-0", "Command-Option-Shift-0"), |
| 27106 |
exec: function(editor) { editor.session.unfold(); }, |
| 27107 |
scrollIntoView: "center", |
| 27108 |
readOnly: true |
| 27109 |
}, { |
| 27110 |
name: "findnext", |
| 27111 |
bindKey: bindKey("Ctrl-K", "Command-G"), |
| 27112 |
exec: function(editor) { editor.findNext(); }, |
| 27113 |
multiSelectAction: "forEach", |
| 27114 |
scrollIntoView: "center", |
| 27115 |
readOnly: true |
| 27116 |
}, { |
| 27117 |
name: "findprevious", |
| 27118 |
bindKey: bindKey("Ctrl-Shift-K", "Command-Shift-G"), |
| 27119 |
exec: function(editor) { editor.findPrevious(); }, |
| 27120 |
multiSelectAction: "forEach", |
| 27121 |
scrollIntoView: "center", |
| 27122 |
readOnly: true |
| 27123 |
}, { |
| 27124 |
name: "selectOrFindNext", |
| 27125 |
bindKey: bindKey("Alt-K", "Ctrl-G"), |
| 27126 |
exec: function(editor) { |
| 27127 |
if (editor.selection.isEmpty()) |
| 27128 |
editor.selection.selectWord(); |
| 27129 |
else |
| 27130 |
editor.findNext(); |
| 27131 |
}, |
| 27132 |
readOnly: true |
| 27133 |
}, { |
| 27134 |
name: "selectOrFindPrevious", |
| 27135 |
bindKey: bindKey("Alt-Shift-K", "Ctrl-Shift-G"), |
| 27136 |
exec: function(editor) { |
| 27137 |
if (editor.selection.isEmpty()) |
| 27138 |
editor.selection.selectWord(); |
| 27139 |
else |
| 27140 |
editor.findPrevious(); |
| 27141 |
}, |
| 27142 |
readOnly: true |
| 27143 |
}, { |
| 27144 |
name: "find", |
| 27145 |
bindKey: bindKey("Ctrl-F", "Command-F"), |
| 27146 |
exec: function(editor) { |
| 27147 |
config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor)}); |
| 27148 |
}, |
| 27149 |
readOnly: true |
| 27150 |
}, { |
| 27151 |
name: "overwrite", |
| 27152 |
bindKey: "Insert", |
| 27153 |
exec: function(editor) { editor.toggleOverwrite(); }, |
| 27154 |
readOnly: true |
| 27155 |
}, { |
| 27156 |
name: "selecttostart", |
| 27157 |
bindKey: bindKey("Ctrl-Shift-Home", "Command-Shift-Up"), |
| 27158 |
exec: function(editor) { editor.getSelection().selectFileStart(); }, |
| 27159 |
multiSelectAction: "forEach", |
| 27160 |
readOnly: true, |
| 27161 |
scrollIntoView: "animate", |
| 27162 |
aceCommandGroup: "fileJump" |
| 27163 |
}, { |
| 27164 |
name: "gotostart", |
| 27165 |
bindKey: bindKey("Ctrl-Home", "Command-Home|Command-Up"), |
| 27166 |
exec: function(editor) { editor.navigateFileStart(); }, |
| 27167 |
multiSelectAction: "forEach", |
| 27168 |
readOnly: true, |
| 27169 |
scrollIntoView: "animate", |
| 27170 |
aceCommandGroup: "fileJump" |
| 27171 |
}, { |
| 27172 |
name: "selectup", |
| 27173 |
bindKey: bindKey("Shift-Up", "Shift-Up"), |
| 27174 |
exec: function(editor) { editor.getSelection().selectUp(); }, |
| 27175 |
multiSelectAction: "forEach", |
| 27176 |
scrollIntoView: "cursor", |
| 27177 |
readOnly: true |
| 27178 |
}, { |
| 27179 |
name: "golineup", |
| 27180 |
bindKey: bindKey("Up", "Up|Ctrl-P"), |
| 27181 |
exec: function(editor, args) { editor.navigateUp(args.times); }, |
| 27182 |
multiSelectAction: "forEach", |
| 27183 |
scrollIntoView: "cursor", |
| 27184 |
readOnly: true |
| 27185 |
}, { |
| 27186 |
name: "selecttoend", |
| 27187 |
bindKey: bindKey("Ctrl-Shift-End", "Command-Shift-Down"), |
| 27188 |
exec: function(editor) { editor.getSelection().selectFileEnd(); }, |
| 27189 |
multiSelectAction: "forEach", |
| 27190 |
readOnly: true, |
| 27191 |
scrollIntoView: "animate", |
| 27192 |
aceCommandGroup: "fileJump" |
| 27193 |
}, { |
| 27194 |
name: "gotoend", |
| 27195 |
bindKey: bindKey("Ctrl-End", "Command-End|Command-Down"), |
| 27196 |
exec: function(editor) { editor.navigateFileEnd(); }, |
| 27197 |
multiSelectAction: "forEach", |
| 27198 |
readOnly: true, |
| 27199 |
scrollIntoView: "animate", |
| 27200 |
aceCommandGroup: "fileJump" |
| 27201 |
}, { |
| 27202 |
name: "selectdown", |
| 27203 |
bindKey: bindKey("Shift-Down", "Shift-Down"), |
| 27204 |
exec: function(editor) { editor.getSelection().selectDown(); }, |
| 27205 |
multiSelectAction: "forEach", |
| 27206 |
scrollIntoView: "cursor", |
| 27207 |
readOnly: true |
| 27208 |
}, { |
| 27209 |
name: "golinedown", |
| 27210 |
bindKey: bindKey("Down", "Down|Ctrl-N"), |
| 27211 |
exec: function(editor, args) { editor.navigateDown(args.times); }, |
| 27212 |
multiSelectAction: "forEach", |
| 27213 |
scrollIntoView: "cursor", |
| 27214 |
readOnly: true |
| 27215 |
}, { |
| 27216 |
name: "selectwordleft", |
| 27217 |
bindKey: bindKey("Ctrl-Shift-Left", "Option-Shift-Left"), |
| 27218 |
exec: function(editor) { editor.getSelection().selectWordLeft(); }, |
| 27219 |
multiSelectAction: "forEach", |
| 27220 |
scrollIntoView: "cursor", |
| 27221 |
readOnly: true |
| 27222 |
}, { |
| 27223 |
name: "gotowordleft", |
| 27224 |
bindKey: bindKey("Ctrl-Left", "Option-Left"), |
| 27225 |
exec: function(editor) { editor.navigateWordLeft(); }, |
| 27226 |
multiSelectAction: "forEach", |
| 27227 |
scrollIntoView: "cursor", |
| 27228 |
readOnly: true |
| 27229 |
}, { |
| 27230 |
name: "selecttolinestart", |
| 27231 |
bindKey: bindKey("Alt-Shift-Left", "Command-Shift-Left"), |
| 27232 |
exec: function(editor) { editor.getSelection().selectLineStart(); }, |
| 27233 |
multiSelectAction: "forEach", |
| 27234 |
scrollIntoView: "cursor", |
| 27235 |
readOnly: true |
| 27236 |
}, { |
| 27237 |
name: "gotolinestart", |
| 27238 |
bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"), |
| 27239 |
exec: function(editor) { editor.navigateLineStart(); }, |
| 27240 |
multiSelectAction: "forEach", |
| 27241 |
scrollIntoView: "cursor", |
| 27242 |
readOnly: true |
| 27243 |
}, { |
| 27244 |
name: "selectleft", |
| 27245 |
bindKey: bindKey("Shift-Left", "Shift-Left"), |
| 27246 |
exec: function(editor) { editor.getSelection().selectLeft(); }, |
| 27247 |
multiSelectAction: "forEach", |
| 27248 |
scrollIntoView: "cursor", |
| 27249 |
readOnly: true |
| 27250 |
}, { |
| 27251 |
name: "gotoleft", |
| 27252 |
bindKey: bindKey("Left", "Left|Ctrl-B"), |
| 27253 |
exec: function(editor, args) { editor.navigateLeft(args.times); }, |
| 27254 |
multiSelectAction: "forEach", |
| 27255 |
scrollIntoView: "cursor", |
| 27256 |
readOnly: true |
| 27257 |
}, { |
| 27258 |
name: "selectwordright", |
| 27259 |
bindKey: bindKey("Ctrl-Shift-Right", "Option-Shift-Right"), |
| 27260 |
exec: function(editor) { editor.getSelection().selectWordRight(); }, |
| 27261 |
multiSelectAction: "forEach", |
| 27262 |
scrollIntoView: "cursor", |
| 27263 |
readOnly: true |
| 27264 |
}, { |
| 27265 |
name: "gotowordright", |
| 27266 |
bindKey: bindKey("Ctrl-Right", "Option-Right"), |
| 27267 |
exec: function(editor) { editor.navigateWordRight(); }, |
| 27268 |
multiSelectAction: "forEach", |
| 27269 |
scrollIntoView: "cursor", |
| 27270 |
readOnly: true |
| 27271 |
}, { |
| 27272 |
name: "selecttolineend", |
| 27273 |
bindKey: bindKey("Alt-Shift-Right", "Command-Shift-Right"), |
| 27274 |
exec: function(editor) { editor.getSelection().selectLineEnd(); }, |
| 27275 |
multiSelectAction: "forEach", |
| 27276 |
scrollIntoView: "cursor", |
| 27277 |
readOnly: true |
| 27278 |
}, { |
| 27279 |
name: "gotolineend", |
| 27280 |
bindKey: bindKey("Alt-Right|End", "Command-Right|End|Ctrl-E"), |
| 27281 |
exec: function(editor) { editor.navigateLineEnd(); }, |
| 27282 |
multiSelectAction: "forEach", |
| 27283 |
scrollIntoView: "cursor", |
| 27284 |
readOnly: true |
| 27285 |
}, { |
| 27286 |
name: "selectright", |
| 27287 |
bindKey: bindKey("Shift-Right", "Shift-Right"), |
| 27288 |
exec: function(editor) { editor.getSelection().selectRight(); }, |
| 27289 |
multiSelectAction: "forEach", |
| 27290 |
scrollIntoView: "cursor", |
| 27291 |
readOnly: true |
| 27292 |
}, { |
| 27293 |
name: "gotoright", |
| 27294 |
bindKey: bindKey("Right", "Right|Ctrl-F"), |
| 27295 |
exec: function(editor, args) { editor.navigateRight(args.times); }, |
| 27296 |
multiSelectAction: "forEach", |
| 27297 |
scrollIntoView: "cursor", |
| 27298 |
readOnly: true |
| 27299 |
}, { |
| 27300 |
name: "selectpagedown", |
| 27301 |
bindKey: "Shift-PageDown", |
| 27302 |
exec: function(editor) { editor.selectPageDown(); }, |
| 27303 |
readOnly: true |
| 27304 |
}, { |
| 27305 |
name: "pagedown", |
| 27306 |
bindKey: bindKey(null, "Option-PageDown"), |
| 27307 |
exec: function(editor) { editor.scrollPageDown(); }, |
| 27308 |
readOnly: true |
| 27309 |
}, { |
| 27310 |
name: "gotopagedown", |
| 27311 |
bindKey: bindKey("PageDown", "PageDown|Ctrl-V"), |
| 27312 |
exec: function(editor) { editor.gotoPageDown(); }, |
| 27313 |
readOnly: true |
| 27314 |
}, { |
| 27315 |
name: "selectpageup", |
| 27316 |
bindKey: "Shift-PageUp", |
| 27317 |
exec: function(editor) { editor.selectPageUp(); }, |
| 27318 |
readOnly: true |
| 27319 |
}, { |
| 27320 |
name: "pageup", |
| 27321 |
bindKey: bindKey(null, "Option-PageUp"), |
| 27322 |
exec: function(editor) { editor.scrollPageUp(); }, |
| 27323 |
readOnly: true |
| 27324 |
}, { |
| 27325 |
name: "gotopageup", |
| 27326 |
bindKey: "PageUp", |
| 27327 |
exec: function(editor) { editor.gotoPageUp(); }, |
| 27328 |
readOnly: true |
| 27329 |
}, { |
| 27330 |
name: "scrollup", |
| 27331 |
bindKey: bindKey("Ctrl-Up", null), |
| 27332 |
exec: function(e) { e.renderer.scrollBy(0, -2 * e.renderer.layerConfig.lineHeight); }, |
| 27333 |
readOnly: true |
| 27334 |
}, { |
| 27335 |
name: "scrolldown", |
| 27336 |
bindKey: bindKey("Ctrl-Down", null), |
| 27337 |
exec: function(e) { e.renderer.scrollBy(0, 2 * e.renderer.layerConfig.lineHeight); }, |
| 27338 |
readOnly: true |
| 27339 |
}, { |
| 27340 |
name: "selectlinestart", |
| 27341 |
bindKey: "Shift-Home", |
| 27342 |
exec: function(editor) { editor.getSelection().selectLineStart(); }, |
| 27343 |
multiSelectAction: "forEach", |
| 27344 |
scrollIntoView: "cursor", |
| 27345 |
readOnly: true |
| 27346 |
}, { |
| 27347 |
name: "selectlineend", |
| 27348 |
bindKey: "Shift-End", |
| 27349 |
exec: function(editor) { editor.getSelection().selectLineEnd(); }, |
| 27350 |
multiSelectAction: "forEach", |
| 27351 |
scrollIntoView: "cursor", |
| 27352 |
readOnly: true |
| 27353 |
}, { |
| 27354 |
name: "togglerecording", |
| 27355 |
bindKey: bindKey("Ctrl-Alt-E", "Command-Option-E"), |
| 27356 |
exec: function(editor) { editor.commands.toggleRecording(editor); }, |
| 27357 |
readOnly: true |
| 27358 |
}, { |
| 27359 |
name: "replaymacro", |
| 27360 |
bindKey: bindKey("Ctrl-Shift-E", "Command-Shift-E"), |
| 27361 |
exec: function(editor) { editor.commands.replay(editor); }, |
| 27362 |
readOnly: true |
| 27363 |
}, { |
| 27364 |
name: "jumptomatching", |
| 27365 |
bindKey: bindKey("Ctrl-P", "Ctrl-P"), |
| 27366 |
exec: function(editor) { editor.jumpToMatching(); }, |
| 27367 |
multiSelectAction: "forEach", |
| 27368 |
scrollIntoView: "animate", |
| 27369 |
readOnly: true |
| 27370 |
}, { |
| 27371 |
name: "selecttomatching", |
| 27372 |
bindKey: bindKey("Ctrl-Shift-P", "Ctrl-Shift-P"), |
| 27373 |
exec: function(editor) { editor.jumpToMatching(true); }, |
| 27374 |
multiSelectAction: "forEach", |
| 27375 |
scrollIntoView: "animate", |
| 27376 |
readOnly: true |
| 27377 |
}, { |
| 27378 |
name: "expandToMatching", |
| 27379 |
bindKey: bindKey("Ctrl-Shift-M", "Ctrl-Shift-M"), |
| 27380 |
exec: function(editor) { editor.jumpToMatching(true, true); }, |
| 27381 |
multiSelectAction: "forEach", |
| 27382 |
scrollIntoView: "animate", |
| 27383 |
readOnly: true |
| 27384 |
}, { |
| 27385 |
name: "passKeysToBrowser", |
| 27386 |
bindKey: bindKey(null, null), |
| 27387 |
exec: function() {}, |
| 27388 |
passEvent: true, |
| 27389 |
readOnly: true |
| 27390 |
}, { |
| 27391 |
name: "copy", |
| 27392 |
exec: function(editor) { |
| 27393 |
}, |
| 27394 |
readOnly: true |
| 27395 |
}, |
| 27396 |
{ |
| 27397 |
name: "cut", |
| 27398 |
exec: function(editor) { |
| 27399 |
var range = editor.getSelectionRange(); |
| 27400 |
editor._emit("cut", range); |
| 27401 |
|
| 27402 |
if (!editor.selection.isEmpty()) { |
| 27403 |
editor.session.remove(range); |
| 27404 |
editor.clearSelection(); |
| 27405 |
} |
| 27406 |
}, |
| 27407 |
scrollIntoView: "cursor", |
| 27408 |
multiSelectAction: "forEach" |
| 27409 |
}, { |
| 27410 |
name: "paste", |
| 27411 |
exec: function(editor, args) { |
| 27412 |
editor.$handlePaste(args); |
| 27413 |
}, |
| 27414 |
scrollIntoView: "cursor" |
| 27415 |
}, { |
| 27416 |
name: "removeline", |
| 27417 |
bindKey: bindKey("Ctrl-D", "Command-D"), |
| 27418 |
exec: function(editor) { editor.removeLines(); }, |
| 27419 |
scrollIntoView: "cursor", |
| 27420 |
multiSelectAction: "forEachLine" |
| 27421 |
}, { |
| 27422 |
name: "duplicateSelection", |
| 27423 |
bindKey: bindKey("Ctrl-Shift-D", "Command-Shift-D"), |
| 27424 |
exec: function(editor) { editor.duplicateSelection(); }, |
| 27425 |
scrollIntoView: "cursor", |
| 27426 |
multiSelectAction: "forEach" |
| 27427 |
}, { |
| 27428 |
name: "sortlines", |
| 27429 |
bindKey: bindKey("Ctrl-Alt-S", "Command-Alt-S"), |
| 27430 |
exec: function(editor) { editor.sortLines(); }, |
| 27431 |
scrollIntoView: "selection", |
| 27432 |
multiSelectAction: "forEachLine" |
| 27433 |
}, { |
| 27434 |
name: "togglecomment", |
| 27435 |
bindKey: bindKey("Ctrl-/", "Command-/"), |
| 27436 |
exec: function(editor) { editor.toggleCommentLines(); }, |
| 27437 |
multiSelectAction: "forEachLine", |
| 27438 |
scrollIntoView: "selectionPart" |
| 27439 |
}, { |
| 27440 |
name: "toggleBlockComment", |
| 27441 |
bindKey: bindKey("Ctrl-Shift-/", "Command-Shift-/"), |
| 27442 |
exec: function(editor) { editor.toggleBlockComment(); }, |
| 27443 |
multiSelectAction: "forEach", |
| 27444 |
scrollIntoView: "selectionPart" |
| 27445 |
}, { |
| 27446 |
name: "modifyNumberUp", |
| 27447 |
bindKey: bindKey("Ctrl-Shift-Up", "Alt-Shift-Up"), |
| 27448 |
exec: function(editor) { editor.modifyNumber(1); }, |
| 27449 |
scrollIntoView: "cursor", |
| 27450 |
multiSelectAction: "forEach" |
| 27451 |
}, { |
| 27452 |
name: "modifyNumberDown", |
| 27453 |
bindKey: bindKey("Ctrl-Shift-Down", "Alt-Shift-Down"), |
| 27454 |
exec: function(editor) { editor.modifyNumber(-1); }, |
| 27455 |
scrollIntoView: "cursor", |
| 27456 |
multiSelectAction: "forEach" |
| 27457 |
}, { |
| 27458 |
name: "replace", |
| 27459 |
bindKey: bindKey("Ctrl-H", "Command-Option-F"), |
| 27460 |
exec: function(editor) { |
| 27461 |
config.loadModule("ace/ext/searchbox", function(e) {e.Search(editor, true)}); |
| 27462 |
} |
| 27463 |
}, { |
| 27464 |
name: "undo", |
| 27465 |
bindKey: bindKey("Ctrl-Z", "Command-Z"), |
| 27466 |
exec: function(editor) { editor.undo(); } |
| 27467 |
}, { |
| 27468 |
name: "redo", |
| 27469 |
bindKey: bindKey("Ctrl-Shift-Z|Ctrl-Y", "Command-Shift-Z|Command-Y"), |
| 27470 |
exec: function(editor) { editor.redo(); } |
| 27471 |
}, { |
| 27472 |
name: "copylinesup", |
| 27473 |
bindKey: bindKey("Alt-Shift-Up", "Command-Option-Up"), |
| 27474 |
exec: function(editor) { editor.copyLinesUp(); }, |
| 27475 |
scrollIntoView: "cursor" |
| 27476 |
}, { |
| 27477 |
name: "movelinesup", |
| 27478 |
bindKey: bindKey("Alt-Up", "Option-Up"), |
| 27479 |
exec: function(editor) { editor.moveLinesUp(); }, |
| 27480 |
scrollIntoView: "cursor" |
| 27481 |
}, { |
| 27482 |
name: "copylinesdown", |
| 27483 |
bindKey: bindKey("Alt-Shift-Down", "Command-Option-Down"), |
| 27484 |
exec: function(editor) { editor.copyLinesDown(); }, |
| 27485 |
scrollIntoView: "cursor" |
| 27486 |
}, { |
| 27487 |
name: "movelinesdown", |
| 27488 |
bindKey: bindKey("Alt-Down", "Option-Down"), |
| 27489 |
exec: function(editor) { editor.moveLinesDown(); }, |
| 27490 |
scrollIntoView: "cursor" |
| 27491 |
}, { |
| 27492 |
name: "del", |
| 27493 |
bindKey: bindKey("Delete", "Delete|Ctrl-D|Shift-Delete"), |
| 27494 |
exec: function(editor) { editor.remove("right"); }, |
| 27495 |
multiSelectAction: "forEach", |
| 27496 |
scrollIntoView: "cursor" |
| 27497 |
}, { |
| 27498 |
name: "backspace", |
| 27499 |
bindKey: bindKey( |
| 27500 |
"Shift-Backspace|Backspace", |
| 27501 |
"Ctrl-Backspace|Shift-Backspace|Backspace|Ctrl-H" |
| 27502 |
), |
| 27503 |
exec: function(editor) { editor.remove("left"); }, |
| 27504 |
multiSelectAction: "forEach", |
| 27505 |
scrollIntoView: "cursor" |
| 27506 |
}, { |
| 27507 |
name: "cut_or_delete", |
| 27508 |
bindKey: bindKey("Shift-Delete", null), |
| 27509 |
exec: function(editor) { |
| 27510 |
if (editor.selection.isEmpty()) { |
| 27511 |
editor.remove("left"); |
| 27512 |
} else { |
| 27513 |
return false; |
| 27514 |
} |
| 27515 |
}, |
| 27516 |
multiSelectAction: "forEach", |
| 27517 |
scrollIntoView: "cursor" |
| 27518 |
}, { |
| 27519 |
name: "removetolinestart", |
| 27520 |
bindKey: bindKey("Alt-Backspace", "Command-Backspace"), |
| 27521 |
exec: function(editor) { editor.removeToLineStart(); }, |
| 27522 |
multiSelectAction: "forEach", |
| 27523 |
scrollIntoView: "cursor" |
| 27524 |
}, { |
| 27525 |
name: "removetolineend", |
| 27526 |
bindKey: bindKey("Alt-Delete", "Ctrl-K"), |
| 27527 |
exec: function(editor) { editor.removeToLineEnd(); }, |
| 27528 |
multiSelectAction: "forEach", |
| 27529 |
scrollIntoView: "cursor" |
| 27530 |
}, { |
| 27531 |
name: "removewordleft", |
| 27532 |
bindKey: bindKey("Ctrl-Backspace", "Alt-Backspace|Ctrl-Alt-Backspace"), |
| 27533 |
exec: function(editor) { editor.removeWordLeft(); }, |
| 27534 |
multiSelectAction: "forEach", |
| 27535 |
scrollIntoView: "cursor" |
| 27536 |
}, { |
| 27537 |
name: "removewordright", |
| 27538 |
bindKey: bindKey("Ctrl-Delete", "Alt-Delete"), |
| 27539 |
exec: function(editor) { editor.removeWordRight(); }, |
| 27540 |
multiSelectAction: "forEach", |
| 27541 |
scrollIntoView: "cursor" |
| 27542 |
}, { |
| 27543 |
name: "outdent", |
| 27544 |
bindKey: bindKey("Shift-Tab", "Shift-Tab"), |
| 27545 |
exec: function(editor) { editor.blockOutdent(); }, |
| 27546 |
multiSelectAction: "forEach", |
| 27547 |
scrollIntoView: "selectionPart" |
| 27548 |
}, { |
| 27549 |
name: "indent", |
| 27550 |
bindKey: bindKey("Tab", "Tab"), |
| 27551 |
exec: function(editor) { editor.indent(); }, |
| 27552 |
multiSelectAction: "forEach", |
| 27553 |
scrollIntoView: "selectionPart" |
| 27554 |
}, { |
| 27555 |
name: "blockoutdent", |
| 27556 |
bindKey: bindKey("Ctrl-[", "Ctrl-["), |
| 27557 |
exec: function(editor) { editor.blockOutdent(); }, |
| 27558 |
multiSelectAction: "forEachLine", |
| 27559 |
scrollIntoView: "selectionPart" |
| 27560 |
}, { |
| 27561 |
name: "blockindent", |
| 27562 |
bindKey: bindKey("Ctrl-]", "Ctrl-]"), |
| 27563 |
exec: function(editor) { editor.blockIndent(); }, |
| 27564 |
multiSelectAction: "forEachLine", |
| 27565 |
scrollIntoView: "selectionPart" |
| 27566 |
}, { |
| 27567 |
name: "insertstring", |
| 27568 |
exec: function(editor, str) { editor.insert(str); }, |
| 27569 |
multiSelectAction: "forEach", |
| 27570 |
scrollIntoView: "cursor" |
| 27571 |
}, { |
| 27572 |
name: "inserttext", |
| 27573 |
exec: function(editor, args) { |
| 27574 |
editor.insert(lang.stringRepeat(args.text || "", args.times || 1)); |
| 27575 |
}, |
| 27576 |
multiSelectAction: "forEach", |
| 27577 |
scrollIntoView: "cursor" |
| 27578 |
}, { |
| 27579 |
name: "splitline", |
| 27580 |
bindKey: bindKey(null, "Ctrl-O"), |
| 27581 |
exec: function(editor) { editor.splitLine(); }, |
| 27582 |
multiSelectAction: "forEach", |
| 27583 |
scrollIntoView: "cursor" |
| 27584 |
}, { |
| 27585 |
name: "transposeletters", |
| 27586 |
bindKey: bindKey("Ctrl-T", "Ctrl-T"), |
| 27587 |
exec: function(editor) { editor.transposeLetters(); }, |
| 27588 |
multiSelectAction: function(editor) {editor.transposeSelections(1); }, |
| 27589 |
scrollIntoView: "cursor" |
| 27590 |
}, { |
| 27591 |
name: "touppercase", |
| 27592 |
bindKey: bindKey("Ctrl-U", "Ctrl-U"), |
| 27593 |
exec: function(editor) { editor.toUpperCase(); }, |
| 27594 |
multiSelectAction: "forEach", |
| 27595 |
scrollIntoView: "cursor" |
| 27596 |
}, { |
| 27597 |
name: "tolowercase", |
| 27598 |
bindKey: bindKey("Ctrl-Shift-U", "Ctrl-Shift-U"), |
| 27599 |
exec: function(editor) { editor.toLowerCase(); }, |
| 27600 |
multiSelectAction: "forEach", |
| 27601 |
scrollIntoView: "cursor" |
| 27602 |
}, { |
| 27603 |
name: "expandtoline", |
| 27604 |
bindKey: bindKey("Ctrl-Shift-L", "Command-Shift-L"), |
| 27605 |
exec: function(editor) { |
| 27606 |
var range = editor.selection.getRange(); |
| 27607 |
|
| 27608 |
range.start.column = range.end.column = 0; |
| 27609 |
range.end.row++; |
| 27610 |
editor.selection.setRange(range, false); |
| 27611 |
}, |
| 27612 |
multiSelectAction: "forEach", |
| 27613 |
scrollIntoView: "cursor", |
| 27614 |
readOnly: true |
| 27615 |
}, { |
| 27616 |
name: "joinlines", |
| 27617 |
bindKey: bindKey(null, null), |
| 27618 |
exec: function(editor) { |
| 27619 |
var isBackwards = editor.selection.isBackwards(); |
| 27620 |
var selectionStart = isBackwards ? editor.selection.getSelectionLead() : editor.selection.getSelectionAnchor(); |
| 27621 |
var selectionEnd = isBackwards ? editor.selection.getSelectionAnchor() : editor.selection.getSelectionLead(); |
| 27622 |
var firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length; |
| 27623 |
var selectedText = editor.session.doc.getTextRange(editor.selection.getRange()); |
| 27624 |
var selectedCount = selectedText.replace(/\n\s*/, " ").length; |
| 27625 |
var insertLine = editor.session.doc.getLine(selectionStart.row); |
| 27626 |
|
| 27627 |
for (var i = selectionStart.row + 1; i <= selectionEnd.row + 1; i++) { |
| 27628 |
var curLine = lang.stringTrimLeft(lang.stringTrimRight(editor.session.doc.getLine(i))); |
| 27629 |
if (curLine.length !== 0) { |
| 27630 |
curLine = " " + curLine; |
| 27631 |
} |
| 27632 |
insertLine += curLine; |
| 27633 |
} |
| 27634 |
|
| 27635 |
if (selectionEnd.row + 1 < (editor.session.doc.getLength() - 1)) { |
| 27636 |
insertLine += editor.session.doc.getNewLineCharacter(); |
| 27637 |
} |
| 27638 |
|
| 27639 |
editor.clearSelection(); |
| 27640 |
editor.session.doc.replace(new Range(selectionStart.row, 0, selectionEnd.row + 2, 0), insertLine); |
| 27641 |
|
| 27642 |
if (selectedCount > 0) { |
| 27643 |
editor.selection.moveCursorTo(selectionStart.row, selectionStart.column); |
| 27644 |
editor.selection.selectTo(selectionStart.row, selectionStart.column + selectedCount); |
| 27645 |
} else { |
| 27646 |
firstLineEndCol = editor.session.doc.getLine(selectionStart.row).length > firstLineEndCol ? (firstLineEndCol + 1) : firstLineEndCol; |
| 27647 |
editor.selection.moveCursorTo(selectionStart.row, firstLineEndCol); |
| 27648 |
} |
| 27649 |
}, |
| 27650 |
multiSelectAction: "forEach", |
| 27651 |
readOnly: true |
| 27652 |
}, { |
| 27653 |
name: "invertSelection", |
| 27654 |
bindKey: bindKey(null, null), |
| 27655 |
exec: function(editor) { |
| 27656 |
var endRow = editor.session.doc.getLength() - 1; |
| 27657 |
var endCol = editor.session.doc.getLine(endRow).length; |
| 27658 |
var ranges = editor.selection.rangeList.ranges; |
| 27659 |
var newRanges = []; |
| 27660 |
if (ranges.length < 1) { |
| 27661 |
ranges = [editor.selection.getRange()]; |
| 27662 |
} |
| 27663 |
|
| 27664 |
for (var i = 0; i < ranges.length; i++) { |
| 27665 |
if (i == (ranges.length - 1)) { |
| 27666 |
if (!(ranges[i].end.row === endRow && ranges[i].end.column === endCol)) { |
| 27667 |
newRanges.push(new Range(ranges[i].end.row, ranges[i].end.column, endRow, endCol)); |
| 27668 |
} |
| 27669 |
} |
| 27670 |
|
| 27671 |
if (i === 0) { |
| 27672 |
if (!(ranges[i].start.row === 0 && ranges[i].start.column === 0)) { |
| 27673 |
newRanges.push(new Range(0, 0, ranges[i].start.row, ranges[i].start.column)); |
| 27674 |
} |
| 27675 |
} else { |
| 27676 |
newRanges.push(new Range(ranges[i-1].end.row, ranges[i-1].end.column, ranges[i].start.row, ranges[i].start.column)); |
| 27677 |
} |
| 27678 |
} |
| 27679 |
|
| 27680 |
editor.exitMultiSelectMode(); |
| 27681 |
editor.clearSelection(); |
| 27682 |
|
| 27683 |
for(var i = 0; i < newRanges.length; i++) { |
| 27684 |
editor.selection.addRange(newRanges[i], false); |
| 27685 |
} |
| 27686 |
}, |
| 27687 |
readOnly: true, |
| 27688 |
scrollIntoView: "none" |
| 27689 |
}]; |
| 27690 |
|
| 27691 |
}); |
| 27692 |
|
| 27693 |
ace.define("ace/editor",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/keyboard/textinput","ace/mouse/mouse_handler","ace/mouse/fold_handler","ace/keyboard/keybinding","ace/edit_session","ace/search","ace/range","ace/lib/event_emitter","ace/commands/command_manager","ace/commands/default_commands","ace/config","ace/token_iterator"], function(acequire, exports, module) { |
| 27694 |
"use strict"; |
| 27695 |
|
| 27696 |
acequire("./lib/fixoldbrowsers"); |
| 27697 |
|
| 27698 |
var oop = acequire("./lib/oop"); |
| 27699 |
var dom = acequire("./lib/dom"); |
| 27700 |
var lang = acequire("./lib/lang"); |
| 27701 |
var useragent = acequire("./lib/useragent"); |
| 27702 |
var TextInput = acequire("./keyboard/textinput").TextInput; |
| 27703 |
var MouseHandler = acequire("./mouse/mouse_handler").MouseHandler; |
| 27704 |
var FoldHandler = acequire("./mouse/fold_handler").FoldHandler; |
| 27705 |
var KeyBinding = acequire("./keyboard/keybinding").KeyBinding; |
| 27706 |
var EditSession = acequire("./edit_session").EditSession; |
| 27707 |
var Search = acequire("./search").Search; |
| 27708 |
var Range = acequire("./range").Range; |
| 27709 |
var EventEmitter = acequire("./lib/event_emitter").EventEmitter; |
| 27710 |
var CommandManager = acequire("./commands/command_manager").CommandManager; |
| 27711 |
var defaultCommands = acequire("./commands/default_commands").commands; |
| 27712 |
var config = acequire("./config"); |
| 27713 |
var TokenIterator = acequire("./token_iterator").TokenIterator; |
| 27714 |
var Editor = function(renderer, session) { |
| 27715 |
var container = renderer.getContainerElement(); |
| 27716 |
this.container = container; |
| 27717 |
this.renderer = renderer; |
| 27718 |
|
| 27719 |
this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands); |
| 27720 |
this.textInput = new TextInput(renderer.getTextAreaContainer(), this); |
| 27721 |
this.renderer.textarea = this.textInput.getElement(); |
| 27722 |
this.keyBinding = new KeyBinding(this); |
| 27723 |
this.$mouseHandler = new MouseHandler(this); |
| 27724 |
new FoldHandler(this); |
| 27725 |
|
| 27726 |
this.$blockScrolling = 0; |
| 27727 |
this.$search = new Search().set({ |
| 27728 |
wrap: true |
| 27729 |
}); |
| 27730 |
|
| 27731 |
this.$historyTracker = this.$historyTracker.bind(this); |
| 27732 |
this.commands.on("exec", this.$historyTracker); |
| 27733 |
|
| 27734 |
this.$initOperationListeners(); |
| 27735 |
|
| 27736 |
this._$emitInputEvent = lang.delayedCall(function() { |
| 27737 |
this._signal("input", {}); |
| 27738 |
if (this.session && this.session.bgTokenizer) |
| 27739 |
this.session.bgTokenizer.scheduleStart(); |
| 27740 |
}.bind(this)); |
| 27741 |
|
| 27742 |
this.on("change", function(_, _self) { |
| 27743 |
_self._$emitInputEvent.schedule(31); |
| 27744 |
}); |
| 27745 |
|
| 27746 |
this.setSession(session || new EditSession("")); |
| 27747 |
config.resetOptions(this); |
| 27748 |
config._signal("editor", this); |
| 27749 |
}; |
| 27750 |
|
| 27751 |
(function(){ |
| 27752 |
|
| 27753 |
oop.implement(this, EventEmitter); |
| 27754 |
|
| 27755 |
this.$initOperationListeners = function() { |
| 27756 |
function last(a) {return a[a.length - 1]} |
| 27757 |
|
| 27758 |
this.selections = []; |
| 27759 |
this.commands.on("exec", this.startOperation.bind(this), true); |
| 27760 |
this.commands.on("afterExec", this.endOperation.bind(this), true); |
| 27761 |
|
| 27762 |
this.$opResetTimer = lang.delayedCall(this.endOperation.bind(this)); |
| 27763 |
|
| 27764 |
this.on("change", function() { |
| 27765 |
this.curOp || this.startOperation(); |
| 27766 |
this.curOp.docChanged = true; |
| 27767 |
}.bind(this), true); |
| 27768 |
|
| 27769 |
this.on("changeSelection", function() { |
| 27770 |
this.curOp || this.startOperation(); |
| 27771 |
this.curOp.selectionChanged = true; |
| 27772 |
}.bind(this), true); |
| 27773 |
}; |
| 27774 |
|
| 27775 |
this.curOp = null; |
| 27776 |
this.prevOp = {}; |
| 27777 |
this.startOperation = function(commadEvent) { |
| 27778 |
if (this.curOp) { |
| 27779 |
if (!commadEvent || this.curOp.command) |
| 27780 |
return; |
| 27781 |
this.prevOp = this.curOp; |
| 27782 |
} |
| 27783 |
if (!commadEvent) { |
| 27784 |
this.previousCommand = null; |
| 27785 |
commadEvent = {}; |
| 27786 |
} |
| 27787 |
|
| 27788 |
this.$opResetTimer.schedule(); |
| 27789 |
this.curOp = { |
| 27790 |
command: commadEvent.command || {}, |
| 27791 |
args: commadEvent.args, |
| 27792 |
scrollTop: this.renderer.scrollTop |
| 27793 |
}; |
| 27794 |
if (this.curOp.command.name && this.curOp.command.scrollIntoView !== undefined) |
| 27795 |
this.$blockScrolling++; |
| 27796 |
}; |
| 27797 |
|
| 27798 |
this.endOperation = function(e) { |
| 27799 |
if (this.curOp) { |
| 27800 |
if (e && e.returnValue === false) |
| 27801 |
return this.curOp = null; |
| 27802 |
this._signal("beforeEndOperation"); |
| 27803 |
var command = this.curOp.command; |
| 27804 |
if (command.name && this.$blockScrolling > 0) |
| 27805 |
this.$blockScrolling--; |
| 27806 |
var scrollIntoView = command && command.scrollIntoView; |
| 27807 |
if (scrollIntoView) { |
| 27808 |
switch (scrollIntoView) { |
| 27809 |
case "center-animate": |
| 27810 |
scrollIntoView = "animate"; |
| 27811 |
case "center": |
| 27812 |
this.renderer.scrollCursorIntoView(null, 0.5); |
| 27813 |
break; |
| 27814 |
case "animate": |
| 27815 |
case "cursor": |
| 27816 |
this.renderer.scrollCursorIntoView(); |
| 27817 |
break; |
| 27818 |
case "selectionPart": |
| 27819 |
var range = this.selection.getRange(); |
| 27820 |
var config = this.renderer.layerConfig; |
| 27821 |
if (range.start.row >= config.lastRow || range.end.row <= config.firstRow) { |
| 27822 |
this.renderer.scrollSelectionIntoView(this.selection.anchor, this.selection.lead); |
| 27823 |
} |
| 27824 |
break; |
| 27825 |
default: |
| 27826 |
break; |
| 27827 |
} |
| 27828 |
if (scrollIntoView == "animate") |
| 27829 |
this.renderer.animateScrolling(this.curOp.scrollTop); |
| 27830 |
} |
| 27831 |
|
| 27832 |
this.prevOp = this.curOp; |
| 27833 |
this.curOp = null; |
| 27834 |
} |
| 27835 |
}; |
| 27836 |
this.$mergeableCommands = ["backspace", "del", "insertstring"]; |
| 27837 |
this.$historyTracker = function(e) { |
| 27838 |
if (!this.$mergeUndoDeltas) |
| 27839 |
return; |
| 27840 |
|
| 27841 |
var prev = this.prevOp; |
| 27842 |
var mergeableCommands = this.$mergeableCommands; |
| 27843 |
var shouldMerge = prev.command && (e.command.name == prev.command.name); |
| 27844 |
if (e.command.name == "insertstring") { |
| 27845 |
var text = e.args; |
| 27846 |
if (this.mergeNextCommand === undefined) |
| 27847 |
this.mergeNextCommand = true; |
| 27848 |
|
| 27849 |
shouldMerge = shouldMerge |
| 27850 |
&& this.mergeNextCommand // previous command allows to coalesce with |
| 27851 |
&& (!/\s/.test(text) || /\s/.test(prev.args)); // previous insertion was of same type |
| 27852 |
|
| 27853 |
this.mergeNextCommand = true; |
| 27854 |
} else { |
| 27855 |
shouldMerge = shouldMerge |
| 27856 |
&& mergeableCommands.indexOf(e.command.name) !== -1; // the command is mergeable |
| 27857 |
} |
| 27858 |
|
| 27859 |
if ( |
| 27860 |
this.$mergeUndoDeltas != "always" |
| 27861 |
&& Date.now() - this.sequenceStartTime > 2000 |
| 27862 |
) { |
| 27863 |
shouldMerge = false; // the sequence is too long |
| 27864 |
} |
| 27865 |
|
| 27866 |
if (shouldMerge) |
| 27867 |
this.session.mergeUndoDeltas = true; |
| 27868 |
else if (mergeableCommands.indexOf(e.command.name) !== -1) |
| 27869 |
this.sequenceStartTime = Date.now(); |
| 27870 |
}; |
| 27871 |
this.setKeyboardHandler = function(keyboardHandler, cb) { |
| 27872 |
if (keyboardHandler && typeof keyboardHandler === "string") { |
| 27873 |
this.$keybindingId = keyboardHandler; |
| 27874 |
var _self = this; |
| 27875 |
config.loadModule(["keybinding", keyboardHandler], function(module) { |
| 27876 |
if (_self.$keybindingId == keyboardHandler) |
| 27877 |
_self.keyBinding.setKeyboardHandler(module && module.handler); |
| 27878 |
cb && cb(); |
| 27879 |
}); |
| 27880 |
} else { |
| 27881 |
this.$keybindingId = null; |
| 27882 |
this.keyBinding.setKeyboardHandler(keyboardHandler); |
| 27883 |
cb && cb(); |
| 27884 |
} |
| 27885 |
}; |
| 27886 |
this.getKeyboardHandler = function() { |
| 27887 |
return this.keyBinding.getKeyboardHandler(); |
| 27888 |
}; |
| 27889 |
this.setSession = function(session) { |
| 27890 |
if (this.session == session) |
| 27891 |
return; |
| 27892 |
if (this.curOp) this.endOperation(); |
| 27893 |
this.curOp = {}; |
| 27894 |
|
| 27895 |
var oldSession = this.session; |
| 27896 |
if (oldSession) { |
| 27897 |
this.session.off("change", this.$onDocumentChange); |
| 27898 |
this.session.off("changeMode", this.$onChangeMode); |
| 27899 |
this.session.off("tokenizerUpdate", this.$onTokenizerUpdate); |
| 27900 |
this.session.off("changeTabSize", this.$onChangeTabSize); |
| 27901 |
this.session.off("changeWrapLimit", this.$onChangeWrapLimit); |
| 27902 |
this.session.off("changeWrapMode", this.$onChangeWrapMode); |
| 27903 |
this.session.off("changeFold", this.$onChangeFold); |
| 27904 |
this.session.off("changeFrontMarker", this.$onChangeFrontMarker); |
| 27905 |
this.session.off("changeBackMarker", this.$onChangeBackMarker); |
| 27906 |
this.session.off("changeBreakpoint", this.$onChangeBreakpoint); |
| 27907 |
this.session.off("changeAnnotation", this.$onChangeAnnotation); |
| 27908 |
this.session.off("changeOverwrite", this.$onCursorChange); |
| 27909 |
this.session.off("changeScrollTop", this.$onScrollTopChange); |
| 27910 |
this.session.off("changeScrollLeft", this.$onScrollLeftChange); |
| 27911 |
|
| 27912 |
var selection = this.session.getSelection(); |
| 27913 |
selection.off("changeCursor", this.$onCursorChange); |
| 27914 |
selection.off("changeSelection", this.$onSelectionChange); |
| 27915 |
} |
| 27916 |
|
| 27917 |
this.session = session; |
| 27918 |
if (session) { |
| 27919 |
this.$onDocumentChange = this.onDocumentChange.bind(this); |
| 27920 |
session.on("change", this.$onDocumentChange); |
| 27921 |
this.renderer.setSession(session); |
| 27922 |
|
| 27923 |
this.$onChangeMode = this.onChangeMode.bind(this); |
| 27924 |
session.on("changeMode", this.$onChangeMode); |
| 27925 |
|
| 27926 |
this.$onTokenizerUpdate = this.onTokenizerUpdate.bind(this); |
| 27927 |
session.on("tokenizerUpdate", this.$onTokenizerUpdate); |
| 27928 |
|
| 27929 |
this.$onChangeTabSize = this.renderer.onChangeTabSize.bind(this.renderer); |
| 27930 |
session.on("changeTabSize", this.$onChangeTabSize); |
| 27931 |
|
| 27932 |
this.$onChangeWrapLimit = this.onChangeWrapLimit.bind(this); |
| 27933 |
session.on("changeWrapLimit", this.$onChangeWrapLimit); |
| 27934 |
|
| 27935 |
this.$onChangeWrapMode = this.onChangeWrapMode.bind(this); |
| 27936 |
session.on("changeWrapMode", this.$onChangeWrapMode); |
| 27937 |
|
| 27938 |
this.$onChangeFold = this.onChangeFold.bind(this); |
| 27939 |
session.on("changeFold", this.$onChangeFold); |
| 27940 |
|
| 27941 |
this.$onChangeFrontMarker = this.onChangeFrontMarker.bind(this); |
| 27942 |
this.session.on("changeFrontMarker", this.$onChangeFrontMarker); |
| 27943 |
|
| 27944 |
this.$onChangeBackMarker = this.onChangeBackMarker.bind(this); |
| 27945 |
this.session.on("changeBackMarker", this.$onChangeBackMarker); |
| 27946 |
|
| 27947 |
this.$onChangeBreakpoint = this.onChangeBreakpoint.bind(this); |
| 27948 |
this.session.on("changeBreakpoint", this.$onChangeBreakpoint); |
| 27949 |
|
| 27950 |
this.$onChangeAnnotation = this.onChangeAnnotation.bind(this); |
| 27951 |
this.session.on("changeAnnotation", this.$onChangeAnnotation); |
| 27952 |
|
| 27953 |
this.$onCursorChange = this.onCursorChange.bind(this); |
| 27954 |
this.session.on("changeOverwrite", this.$onCursorChange); |
| 27955 |
|
| 27956 |
this.$onScrollTopChange = this.onScrollTopChange.bind(this); |
| 27957 |
this.session.on("changeScrollTop", this.$onScrollTopChange); |
| 27958 |
|
| 27959 |
this.$onScrollLeftChange = this.onScrollLeftChange.bind(this); |
| 27960 |
this.session.on("changeScrollLeft", this.$onScrollLeftChange); |
| 27961 |
|
| 27962 |
this.selection = session.getSelection(); |
| 27963 |
this.selection.on("changeCursor", this.$onCursorChange); |
| 27964 |
|
| 27965 |
this.$onSelectionChange = this.onSelectionChange.bind(this); |
| 27966 |
this.selection.on("changeSelection", this.$onSelectionChange); |
| 27967 |
|
| 27968 |
this.onChangeMode(); |
| 27969 |
|
| 27970 |
this.$blockScrolling += 1; |
| 27971 |
this.onCursorChange(); |
| 27972 |
this.$blockScrolling -= 1; |
| 27973 |
|
| 27974 |
this.onScrollTopChange(); |
| 27975 |
this.onScrollLeftChange(); |
| 27976 |
this.onSelectionChange(); |
| 27977 |
this.onChangeFrontMarker(); |
| 27978 |
this.onChangeBackMarker(); |
| 27979 |
this.onChangeBreakpoint(); |
| 27980 |
this.onChangeAnnotation(); |
| 27981 |
this.session.getUseWrapMode() && this.renderer.adjustWrapLimit(); |
| 27982 |
this.renderer.updateFull(); |
| 27983 |
} else { |
| 27984 |
this.selection = null; |
| 27985 |
this.renderer.setSession(session); |
| 27986 |
} |
| 27987 |
|
| 27988 |
this._signal("changeSession", { |
| 27989 |
session: session, |
| 27990 |
oldSession: oldSession |
| 27991 |
}); |
| 27992 |
|
| 27993 |
this.curOp = null; |
| 27994 |
|
| 27995 |
oldSession && oldSession._signal("changeEditor", {oldEditor: this}); |
| 27996 |
session && session._signal("changeEditor", {editor: this}); |
| 27997 |
}; |
| 27998 |
this.getSession = function() { |
| 27999 |
return this.session; |
| 28000 |
}; |
| 28001 |
this.setValue = function(val, cursorPos) { |
| 28002 |
this.session.doc.setValue(val); |
| 28003 |
|
| 28004 |
if (!cursorPos) |
| 28005 |
this.selectAll(); |
| 28006 |
else if (cursorPos == 1) |
| 28007 |
this.navigateFileEnd(); |
| 28008 |
else if (cursorPos == -1) |
| 28009 |
this.navigateFileStart(); |
| 28010 |
|
| 28011 |
return val; |
| 28012 |
}; |
| 28013 |
this.getValue = function() { |
| 28014 |
return this.session.getValue(); |
| 28015 |
}; |
| 28016 |
this.getSelection = function() { |
| 28017 |
return this.selection; |
| 28018 |
}; |
| 28019 |
this.resize = function(force) { |
| 28020 |
this.renderer.onResize(force); |
| 28021 |
}; |
| 28022 |
this.setTheme = function(theme, cb) { |
| 28023 |
this.renderer.setTheme(theme, cb); |
| 28024 |
}; |
| 28025 |
this.getTheme = function() { |
| 28026 |
return this.renderer.getTheme(); |
| 28027 |
}; |
| 28028 |
this.setStyle = function(style) { |
| 28029 |
this.renderer.setStyle(style); |
| 28030 |
}; |
| 28031 |
this.unsetStyle = function(style) { |
| 28032 |
this.renderer.unsetStyle(style); |
| 28033 |
}; |
| 28034 |
this.getFontSize = function () { |
| 28035 |
return this.getOption("fontSize") || |
| 28036 |
dom.computedStyle(this.container, "fontSize"); |
| 28037 |
}; |
| 28038 |
this.setFontSize = function(size) { |
| 28039 |
this.setOption("fontSize", size); |
| 28040 |
}; |
| 28041 |
|
| 28042 |
this.$highlightBrackets = function() { |
| 28043 |
if (this.session.$bracketHighlight) { |
| 28044 |
this.session.removeMarker(this.session.$bracketHighlight); |
| 28045 |
this.session.$bracketHighlight = null; |
| 28046 |
} |
| 28047 |
|
| 28048 |
if (this.$highlightPending) { |
| 28049 |
return; |
| 28050 |
} |
| 28051 |
var self = this; |
| 28052 |
this.$highlightPending = true; |
| 28053 |
setTimeout(function() { |
| 28054 |
self.$highlightPending = false; |
| 28055 |
var session = self.session; |
| 28056 |
if (!session || !session.bgTokenizer) return; |
| 28057 |
var pos = session.findMatchingBracket(self.getCursorPosition()); |
| 28058 |
if (pos) { |
| 28059 |
var range = new Range(pos.row, pos.column, pos.row, pos.column + 1); |
| 28060 |
} else if (session.$mode.getMatching) { |
| 28061 |
var range = session.$mode.getMatching(self.session); |
| 28062 |
} |
| 28063 |
if (range) |
| 28064 |
session.$bracketHighlight = session.addMarker(range, "ace_bracket", "text"); |
| 28065 |
}, 50); |
| 28066 |
}; |
| 28067 |
this.$highlightTags = function() { |
| 28068 |
if (this.$highlightTagPending) |
| 28069 |
return; |
| 28070 |
var self = this; |
| 28071 |
this.$highlightTagPending = true; |
| 28072 |
setTimeout(function() { |
| 28073 |
self.$highlightTagPending = false; |
| 28074 |
|
| 28075 |
var session = self.session; |
| 28076 |
if (!session || !session.bgTokenizer) return; |
| 28077 |
|
| 28078 |
var pos = self.getCursorPosition(); |
| 28079 |
var iterator = new TokenIterator(self.session, pos.row, pos.column); |
| 28080 |
var token = iterator.getCurrentToken(); |
| 28081 |
|
| 28082 |
if (!token || !/\b(?:tag-open|tag-name)/.test(token.type)) { |
| 28083 |
session.removeMarker(session.$tagHighlight); |
| 28084 |
session.$tagHighlight = null; |
| 28085 |
return; |
| 28086 |
} |
| 28087 |
|
| 28088 |
if (token.type.indexOf("tag-open") != -1) { |
| 28089 |
token = iterator.stepForward(); |
| 28090 |
if (!token) |
| 28091 |
return; |
| 28092 |
} |
| 28093 |
|
| 28094 |
var tag = token.value; |
| 28095 |
var depth = 0; |
| 28096 |
var prevToken = iterator.stepBackward(); |
| 28097 |
|
| 28098 |
if (prevToken.value == '<'){ |
| 28099 |
do { |
| 28100 |
prevToken = token; |
| 28101 |
token = iterator.stepForward(); |
| 28102 |
|
| 28103 |
if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) { |
| 28104 |
if (prevToken.value === '<'){ |
| 28105 |
depth++; |
| 28106 |
} else if (prevToken.value === '</'){ |
| 28107 |
depth--; |
| 28108 |
} |
| 28109 |
} |
| 28110 |
|
| 28111 |
} while (token && depth >= 0); |
| 28112 |
} else { |
| 28113 |
do { |
| 28114 |
token = prevToken; |
| 28115 |
prevToken = iterator.stepBackward(); |
| 28116 |
|
| 28117 |
if (token && token.value === tag && token.type.indexOf('tag-name') !== -1) { |
| 28118 |
if (prevToken.value === '<') { |
| 28119 |
depth++; |
| 28120 |
} else if (prevToken.value === '</') { |
| 28121 |
depth--; |
| 28122 |
} |
| 28123 |
} |
| 28124 |
} while (prevToken && depth <= 0); |
| 28125 |
iterator.stepForward(); |
| 28126 |
} |
| 28127 |
|
| 28128 |
if (!token) { |
| 28129 |
session.removeMarker(session.$tagHighlight); |
| 28130 |
session.$tagHighlight = null; |
| 28131 |
return; |
| 28132 |
} |
| 28133 |
|
| 28134 |
var row = iterator.getCurrentTokenRow(); |
| 28135 |
var column = iterator.getCurrentTokenColumn(); |
| 28136 |
var range = new Range(row, column, row, column+token.value.length); |
| 28137 |
if (session.$tagHighlight && range.compareRange(session.$backMarkers[session.$tagHighlight].range)!==0) { |
| 28138 |
session.removeMarker(session.$tagHighlight); |
| 28139 |
session.$tagHighlight = null; |
| 28140 |
} |
| 28141 |
|
| 28142 |
if (range && !session.$tagHighlight) |
| 28143 |
session.$tagHighlight = session.addMarker(range, "ace_bracket", "text"); |
| 28144 |
}, 50); |
| 28145 |
}; |
| 28146 |
this.focus = function() { |
| 28147 |
var _self = this; |
| 28148 |
setTimeout(function() { |
| 28149 |
_self.textInput.focus(); |
| 28150 |
}); |
| 28151 |
this.textInput.focus(); |
| 28152 |
}; |
| 28153 |
this.isFocused = function() { |
| 28154 |
return this.textInput.isFocused(); |
| 28155 |
}; |
| 28156 |
this.blur = function() { |
| 28157 |
this.textInput.blur(); |
| 28158 |
}; |
| 28159 |
this.onFocus = function(e) { |
| 28160 |
if (this.$isFocused) |
| 28161 |
return; |
| 28162 |
this.$isFocused = true; |
| 28163 |
this.renderer.showCursor(); |
| 28164 |
this.renderer.visualizeFocus(); |
| 28165 |
this._emit("focus", e); |
| 28166 |
}; |
| 28167 |
this.onBlur = function(e) { |
| 28168 |
if (!this.$isFocused) |
| 28169 |
return; |
| 28170 |
this.$isFocused = false; |
| 28171 |
this.renderer.hideCursor(); |
| 28172 |
this.renderer.visualizeBlur(); |
| 28173 |
this._emit("blur", e); |
| 28174 |
}; |
| 28175 |
|
| 28176 |
this.$cursorChange = function() { |
| 28177 |
this.renderer.updateCursor(); |
| 28178 |
}; |
| 28179 |
this.onDocumentChange = function(delta) { |
| 28180 |
var wrap = this.session.$useWrapMode; |
| 28181 |
var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity); |
| 28182 |
this.renderer.updateLines(delta.start.row, lastRow, wrap); |
| 28183 |
|
| 28184 |
this._signal("change", delta); |
| 28185 |
this.$cursorChange(); |
| 28186 |
this.$updateHighlightActiveLine(); |
| 28187 |
}; |
| 28188 |
|
| 28189 |
this.onTokenizerUpdate = function(e) { |
| 28190 |
var rows = e.data; |
| 28191 |
this.renderer.updateLines(rows.first, rows.last); |
| 28192 |
}; |
| 28193 |
|
| 28194 |
|
| 28195 |
this.onScrollTopChange = function() { |
| 28196 |
this.renderer.scrollToY(this.session.getScrollTop()); |
| 28197 |
}; |
| 28198 |
|
| 28199 |
this.onScrollLeftChange = function() { |
| 28200 |
this.renderer.scrollToX(this.session.getScrollLeft()); |
| 28201 |
}; |
| 28202 |
this.onCursorChange = function() { |
| 28203 |
this.$cursorChange(); |
| 28204 |
|
| 28205 |
if (!this.$blockScrolling) { |
| 28206 |
config.warn("Automatically scrolling cursor into view after selection change", |
| 28207 |
"this will be disabled in the next version", |
| 28208 |
"set editor.$blockScrolling = Infinity to disable this message" |
| 28209 |
); |
| 28210 |
this.renderer.scrollCursorIntoView(); |
| 28211 |
} |
| 28212 |
|
| 28213 |
this.$highlightBrackets(); |
| 28214 |
this.$highlightTags(); |
| 28215 |
this.$updateHighlightActiveLine(); |
| 28216 |
this._signal("changeSelection"); |
| 28217 |
}; |
| 28218 |
|
| 28219 |
this.$updateHighlightActiveLine = function() { |
| 28220 |
var session = this.getSession(); |
| 28221 |
|
| 28222 |
var highlight; |
| 28223 |
if (this.$highlightActiveLine) { |
| 28224 |
if ((this.$selectionStyle != "line" || !this.selection.isMultiLine())) |
| 28225 |
highlight = this.getCursorPosition(); |
| 28226 |
if (this.renderer.$maxLines && this.session.getLength() === 1 && !(this.renderer.$minLines > 1)) |
| 28227 |
highlight = false; |
| 28228 |
} |
| 28229 |
|
| 28230 |
if (session.$highlightLineMarker && !highlight) { |
| 28231 |
session.removeMarker(session.$highlightLineMarker.id); |
| 28232 |
session.$highlightLineMarker = null; |
| 28233 |
} else if (!session.$highlightLineMarker && highlight) { |
| 28234 |
var range = new Range(highlight.row, highlight.column, highlight.row, Infinity); |
| 28235 |
range.id = session.addMarker(range, "ace_active-line", "screenLine"); |
| 28236 |
session.$highlightLineMarker = range; |
| 28237 |
} else if (highlight) { |
| 28238 |
session.$highlightLineMarker.start.row = highlight.row; |
| 28239 |
session.$highlightLineMarker.end.row = highlight.row; |
| 28240 |
session.$highlightLineMarker.start.column = highlight.column; |
| 28241 |
session._signal("changeBackMarker"); |
| 28242 |
} |
| 28243 |
}; |
| 28244 |
|
| 28245 |
this.onSelectionChange = function(e) { |
| 28246 |
var session = this.session; |
| 28247 |
|
| 28248 |
if (session.$selectionMarker) { |
| 28249 |
session.removeMarker(session.$selectionMarker); |
| 28250 |
} |
| 28251 |
session.$selectionMarker = null; |
| 28252 |
|
| 28253 |
if (!this.selection.isEmpty()) { |
| 28254 |
var range = this.selection.getRange(); |
| 28255 |
var style = this.getSelectionStyle(); |
| 28256 |
session.$selectionMarker = session.addMarker(range, "ace_selection", style); |
| 28257 |
} else { |
| 28258 |
this.$updateHighlightActiveLine(); |
| 28259 |
} |
| 28260 |
|
| 28261 |
var re = this.$highlightSelectedWord && this.$getSelectionHighLightRegexp(); |
| 28262 |
this.session.highlight(re); |
| 28263 |
|
| 28264 |
this._signal("changeSelection"); |
| 28265 |
}; |
| 28266 |
|
| 28267 |
this.$getSelectionHighLightRegexp = function() { |
| 28268 |
var session = this.session; |
| 28269 |
|
| 28270 |
var selection = this.getSelectionRange(); |
| 28271 |
if (selection.isEmpty() || selection.isMultiLine()) |
| 28272 |
return; |
| 28273 |
|
| 28274 |
var startOuter = selection.start.column - 1; |
| 28275 |
var endOuter = selection.end.column + 1; |
| 28276 |
var line = session.getLine(selection.start.row); |
| 28277 |
var lineCols = line.length; |
| 28278 |
var needle = line.substring(Math.max(startOuter, 0), |
| 28279 |
Math.min(endOuter, lineCols)); |
| 28280 |
if ((startOuter >= 0 && /^[\w\d]/.test(needle)) || |
| 28281 |
(endOuter <= lineCols && /[\w\d]$/.test(needle))) |
| 28282 |
return; |
| 28283 |
|
| 28284 |
needle = line.substring(selection.start.column, selection.end.column); |
| 28285 |
if (!/^[\w\d]+$/.test(needle)) |
| 28286 |
return; |
| 28287 |
|
| 28288 |
var re = this.$search.$assembleRegExp({ |
| 28289 |
wholeWord: true, |
| 28290 |
caseSensitive: true, |
| 28291 |
needle: needle |
| 28292 |
}); |
| 28293 |
|
| 28294 |
return re; |
| 28295 |
}; |
| 28296 |
|
| 28297 |
|
| 28298 |
this.onChangeFrontMarker = function() { |
| 28299 |
this.renderer.updateFrontMarkers(); |
| 28300 |
}; |
| 28301 |
|
| 28302 |
this.onChangeBackMarker = function() { |
| 28303 |
this.renderer.updateBackMarkers(); |
| 28304 |
}; |
| 28305 |
|
| 28306 |
|
| 28307 |
this.onChangeBreakpoint = function() { |
| 28308 |
this.renderer.updateBreakpoints(); |
| 28309 |
}; |
| 28310 |
|
| 28311 |
this.onChangeAnnotation = function() { |
| 28312 |
this.renderer.setAnnotations(this.session.getAnnotations()); |
| 28313 |
}; |
| 28314 |
|
| 28315 |
|
| 28316 |
this.onChangeMode = function(e) { |
| 28317 |
this.renderer.updateText(); |
| 28318 |
this._emit("changeMode", e); |
| 28319 |
}; |
| 28320 |
|
| 28321 |
|
| 28322 |
this.onChangeWrapLimit = function() { |
| 28323 |
this.renderer.updateFull(); |
| 28324 |
}; |
| 28325 |
|
| 28326 |
this.onChangeWrapMode = function() { |
| 28327 |
this.renderer.onResize(true); |
| 28328 |
}; |
| 28329 |
|
| 28330 |
|
| 28331 |
this.onChangeFold = function() { |
| 28332 |
this.$updateHighlightActiveLine(); |
| 28333 |
this.renderer.updateFull(); |
| 28334 |
}; |
| 28335 |
this.getSelectedText = function() { |
| 28336 |
return this.session.getTextRange(this.getSelectionRange()); |
| 28337 |
}; |
| 28338 |
this.getCopyText = function() { |
| 28339 |
var text = this.getSelectedText(); |
| 28340 |
this._signal("copy", text); |
| 28341 |
return text; |
| 28342 |
}; |
| 28343 |
this.onCopy = function() { |
| 28344 |
this.commands.exec("copy", this); |
| 28345 |
}; |
| 28346 |
this.onCut = function() { |
| 28347 |
this.commands.exec("cut", this); |
| 28348 |
}; |
| 28349 |
this.onPaste = function(text, event) { |
| 28350 |
var e = {text: text, event: event}; |
| 28351 |
this.commands.exec("paste", this, e); |
| 28352 |
}; |
| 28353 |
|
| 28354 |
this.$handlePaste = function(e) { |
| 28355 |
if (typeof e == "string") |
| 28356 |
e = {text: e}; |
| 28357 |
this._signal("paste", e); |
| 28358 |
var text = e.text; |
| 28359 |
if (!this.inMultiSelectMode || this.inVirtualSelectionMode) { |
| 28360 |
this.insert(text); |
| 28361 |
} else { |
| 28362 |
var lines = text.split(/\r\n|\r|\n/); |
| 28363 |
var ranges = this.selection.rangeList.ranges; |
| 28364 |
|
| 28365 |
if (lines.length > ranges.length || lines.length < 2 || !lines[1]) |
| 28366 |
return this.commands.exec("insertstring", this, text); |
| 28367 |
|
| 28368 |
for (var i = ranges.length; i--;) { |
| 28369 |
var range = ranges[i]; |
| 28370 |
if (!range.isEmpty()) |
| 28371 |
this.session.remove(range); |
| 28372 |
|
| 28373 |
this.session.insert(range.start, lines[i]); |
| 28374 |
} |
| 28375 |
} |
| 28376 |
}; |
| 28377 |
|
| 28378 |
this.execCommand = function(command, args) { |
| 28379 |
return this.commands.exec(command, this, args); |
| 28380 |
}; |
| 28381 |
this.insert = function(text, pasted) { |
| 28382 |
var session = this.session; |
| 28383 |
var mode = session.getMode(); |
| 28384 |
var cursor = this.getCursorPosition(); |
| 28385 |
|
| 28386 |
if (this.getBehavioursEnabled() && !pasted) { |
| 28387 |
var transform = mode.transformAction(session.getState(cursor.row), 'insertion', this, session, text); |
| 28388 |
if (transform) { |
| 28389 |
if (text !== transform.text) { |
| 28390 |
this.session.mergeUndoDeltas = false; |
| 28391 |
this.$mergeNextCommand = false; |
| 28392 |
} |
| 28393 |
text = transform.text; |
| 28394 |
|
| 28395 |
} |
| 28396 |
} |
| 28397 |
|
| 28398 |
if (text == "\t") |
| 28399 |
text = this.session.getTabString(); |
| 28400 |
if (!this.selection.isEmpty()) { |
| 28401 |
var range = this.getSelectionRange(); |
| 28402 |
cursor = this.session.remove(range); |
| 28403 |
this.clearSelection(); |
| 28404 |
} |
| 28405 |
else if (this.session.getOverwrite()) { |
| 28406 |
var range = new Range.fromPoints(cursor, cursor); |
| 28407 |
range.end.column += text.length; |
| 28408 |
this.session.remove(range); |
| 28409 |
} |
| 28410 |
|
| 28411 |
if (text == "\n" || text == "\r\n") { |
| 28412 |
var line = session.getLine(cursor.row); |
| 28413 |
if (cursor.column > line.search(/\S|$/)) { |
| 28414 |
var d = line.substr(cursor.column).search(/\S|$/); |
| 28415 |
session.doc.removeInLine(cursor.row, cursor.column, cursor.column + d); |
| 28416 |
} |
| 28417 |
} |
| 28418 |
this.clearSelection(); |
| 28419 |
|
| 28420 |
var start = cursor.column; |
| 28421 |
var lineState = session.getState(cursor.row); |
| 28422 |
var line = session.getLine(cursor.row); |
| 28423 |
var shouldOutdent = mode.checkOutdent(lineState, line, text); |
| 28424 |
var end = session.insert(cursor, text); |
| 28425 |
|
| 28426 |
if (transform && transform.selection) { |
| 28427 |
if (transform.selection.length == 2) { // Transform relative to the current column |
| 28428 |
this.selection.setSelectionRange( |
| 28429 |
new Range(cursor.row, start + transform.selection[0], |
| 28430 |
cursor.row, start + transform.selection[1])); |
| 28431 |
} else { // Transform relative to the current row. |
| 28432 |
this.selection.setSelectionRange( |
| 28433 |
new Range(cursor.row + transform.selection[0], |
| 28434 |
transform.selection[1], |
| 28435 |
cursor.row + transform.selection[2], |
| 28436 |
transform.selection[3])); |
| 28437 |
} |
| 28438 |
} |
| 28439 |
|
| 28440 |
if (session.getDocument().isNewLine(text)) { |
| 28441 |
var lineIndent = mode.getNextLineIndent(lineState, line.slice(0, cursor.column), session.getTabString()); |
| 28442 |
|
| 28443 |
session.insert({row: cursor.row+1, column: 0}, lineIndent); |
| 28444 |
} |
| 28445 |
if (shouldOutdent) |
| 28446 |
mode.autoOutdent(lineState, session, cursor.row); |
| 28447 |
}; |
| 28448 |
|
| 28449 |
this.onTextInput = function(text) { |
| 28450 |
this.keyBinding.onTextInput(text); |
| 28451 |
}; |
| 28452 |
|
| 28453 |
this.onCommandKey = function(e, hashId, keyCode) { |
| 28454 |
this.keyBinding.onCommandKey(e, hashId, keyCode); |
| 28455 |
}; |
| 28456 |
this.setOverwrite = function(overwrite) { |
| 28457 |
this.session.setOverwrite(overwrite); |
| 28458 |
}; |
| 28459 |
this.getOverwrite = function() { |
| 28460 |
return this.session.getOverwrite(); |
| 28461 |
}; |
| 28462 |
this.toggleOverwrite = function() { |
| 28463 |
this.session.toggleOverwrite(); |
| 28464 |
}; |
| 28465 |
this.setScrollSpeed = function(speed) { |
| 28466 |
this.setOption("scrollSpeed", speed); |
| 28467 |
}; |
| 28468 |
this.getScrollSpeed = function() { |
| 28469 |
return this.getOption("scrollSpeed"); |
| 28470 |
}; |
| 28471 |
this.setDragDelay = function(dragDelay) { |
| 28472 |
this.setOption("dragDelay", dragDelay); |
| 28473 |
}; |
| 28474 |
this.getDragDelay = function() { |
| 28475 |
return this.getOption("dragDelay"); |
| 28476 |
}; |
| 28477 |
this.setSelectionStyle = function(val) { |
| 28478 |
this.setOption("selectionStyle", val); |
| 28479 |
}; |
| 28480 |
this.getSelectionStyle = function() { |
| 28481 |
return this.getOption("selectionStyle"); |
| 28482 |
}; |
| 28483 |
this.setHighlightActiveLine = function(shouldHighlight) { |
| 28484 |
this.setOption("highlightActiveLine", shouldHighlight); |
| 28485 |
}; |
| 28486 |
this.getHighlightActiveLine = function() { |
| 28487 |
return this.getOption("highlightActiveLine"); |
| 28488 |
}; |
| 28489 |
this.setHighlightGutterLine = function(shouldHighlight) { |
| 28490 |
this.setOption("highlightGutterLine", shouldHighlight); |
| 28491 |
}; |
| 28492 |
|
| 28493 |
this.getHighlightGutterLine = function() { |
| 28494 |
return this.getOption("highlightGutterLine"); |
| 28495 |
}; |
| 28496 |
this.setHighlightSelectedWord = function(shouldHighlight) { |
| 28497 |
this.setOption("highlightSelectedWord", shouldHighlight); |
| 28498 |
}; |
| 28499 |
this.getHighlightSelectedWord = function() { |
| 28500 |
return this.$highlightSelectedWord; |
| 28501 |
}; |
| 28502 |
|
| 28503 |
this.setAnimatedScroll = function(shouldAnimate){ |
| 28504 |
this.renderer.setAnimatedScroll(shouldAnimate); |
| 28505 |
}; |
| 28506 |
|
| 28507 |
this.getAnimatedScroll = function(){ |
| 28508 |
return this.renderer.getAnimatedScroll(); |
| 28509 |
}; |
| 28510 |
this.setShowInvisibles = function(showInvisibles) { |
| 28511 |
this.renderer.setShowInvisibles(showInvisibles); |
| 28512 |
}; |
| 28513 |
this.getShowInvisibles = function() { |
| 28514 |
return this.renderer.getShowInvisibles(); |
| 28515 |
}; |
| 28516 |
|
| 28517 |
this.setDisplayIndentGuides = function(display) { |
| 28518 |
this.renderer.setDisplayIndentGuides(display); |
| 28519 |
}; |
| 28520 |
|
| 28521 |
this.getDisplayIndentGuides = function() { |
| 28522 |
return this.renderer.getDisplayIndentGuides(); |
| 28523 |
}; |
| 28524 |
this.setShowPrintMargin = function(showPrintMargin) { |
| 28525 |
this.renderer.setShowPrintMargin(showPrintMargin); |
| 28526 |
}; |
| 28527 |
this.getShowPrintMargin = function() { |
| 28528 |
return this.renderer.getShowPrintMargin(); |
| 28529 |
}; |
| 28530 |
this.setPrintMarginColumn = function(showPrintMargin) { |
| 28531 |
this.renderer.setPrintMarginColumn(showPrintMargin); |
| 28532 |
}; |
| 28533 |
this.getPrintMarginColumn = function() { |
| 28534 |
return this.renderer.getPrintMarginColumn(); |
| 28535 |
}; |
| 28536 |
this.setReadOnly = function(readOnly) { |
| 28537 |
this.setOption("readOnly", readOnly); |
| 28538 |
}; |
| 28539 |
this.getReadOnly = function() { |
| 28540 |
return this.getOption("readOnly"); |
| 28541 |
}; |
| 28542 |
this.setBehavioursEnabled = function (enabled) { |
| 28543 |
this.setOption("behavioursEnabled", enabled); |
| 28544 |
}; |
| 28545 |
this.getBehavioursEnabled = function () { |
| 28546 |
return this.getOption("behavioursEnabled"); |
| 28547 |
}; |
| 28548 |
this.setWrapBehavioursEnabled = function (enabled) { |
| 28549 |
this.setOption("wrapBehavioursEnabled", enabled); |
| 28550 |
}; |
| 28551 |
this.getWrapBehavioursEnabled = function () { |
| 28552 |
return this.getOption("wrapBehavioursEnabled"); |
| 28553 |
}; |
| 28554 |
this.setShowFoldWidgets = function(show) { |
| 28555 |
this.setOption("showFoldWidgets", show); |
| 28556 |
|
| 28557 |
}; |
| 28558 |
this.getShowFoldWidgets = function() { |
| 28559 |
return this.getOption("showFoldWidgets"); |
| 28560 |
}; |
| 28561 |
|
| 28562 |
this.setFadeFoldWidgets = function(fade) { |
| 28563 |
this.setOption("fadeFoldWidgets", fade); |
| 28564 |
}; |
| 28565 |
|
| 28566 |
this.getFadeFoldWidgets = function() { |
| 28567 |
return this.getOption("fadeFoldWidgets"); |
| 28568 |
}; |
| 28569 |
this.remove = function(dir) { |
| 28570 |
if (this.selection.isEmpty()){ |
| 28571 |
if (dir == "left") |
| 28572 |
this.selection.selectLeft(); |
| 28573 |
else |
| 28574 |
this.selection.selectRight(); |
| 28575 |
} |
| 28576 |
|
| 28577 |
var range = this.getSelectionRange(); |
| 28578 |
if (this.getBehavioursEnabled()) { |
| 28579 |
var session = this.session; |
| 28580 |
var state = session.getState(range.start.row); |
| 28581 |
var new_range = session.getMode().transformAction(state, 'deletion', this, session, range); |
| 28582 |
|
| 28583 |
if (range.end.column === 0) { |
| 28584 |
var text = session.getTextRange(range); |
| 28585 |
if (text[text.length - 1] == "\n") { |
| 28586 |
var line = session.getLine(range.end.row); |
| 28587 |
if (/^\s+$/.test(line)) { |
| 28588 |
range.end.column = line.length; |
| 28589 |
} |
| 28590 |
} |
| 28591 |
} |
| 28592 |
if (new_range) |
| 28593 |
range = new_range; |
| 28594 |
} |
| 28595 |
|
| 28596 |
this.session.remove(range); |
| 28597 |
this.clearSelection(); |
| 28598 |
}; |
| 28599 |
this.removeWordRight = function() { |
| 28600 |
if (this.selection.isEmpty()) |
| 28601 |
this.selection.selectWordRight(); |
| 28602 |
|
| 28603 |
this.session.remove(this.getSelectionRange()); |
| 28604 |
this.clearSelection(); |
| 28605 |
}; |
| 28606 |
this.removeWordLeft = function() { |
| 28607 |
if (this.selection.isEmpty()) |
| 28608 |
this.selection.selectWordLeft(); |
| 28609 |
|
| 28610 |
this.session.remove(this.getSelectionRange()); |
| 28611 |
this.clearSelection(); |
| 28612 |
}; |
| 28613 |
this.removeToLineStart = function() { |
| 28614 |
if (this.selection.isEmpty()) |
| 28615 |
this.selection.selectLineStart(); |
| 28616 |
|
| 28617 |
this.session.remove(this.getSelectionRange()); |
| 28618 |
this.clearSelection(); |
| 28619 |
}; |
| 28620 |
this.removeToLineEnd = function() { |
| 28621 |
if (this.selection.isEmpty()) |
| 28622 |
this.selection.selectLineEnd(); |
| 28623 |
|
| 28624 |
var range = this.getSelectionRange(); |
| 28625 |
if (range.start.column == range.end.column && range.start.row == range.end.row) { |
| 28626 |
range.end.column = 0; |
| 28627 |
range.end.row++; |
| 28628 |
} |
| 28629 |
|
| 28630 |
this.session.remove(range); |
| 28631 |
this.clearSelection(); |
| 28632 |
}; |
| 28633 |
this.splitLine = function() { |
| 28634 |
if (!this.selection.isEmpty()) { |
| 28635 |
this.session.remove(this.getSelectionRange()); |
| 28636 |
this.clearSelection(); |
| 28637 |
} |
| 28638 |
|
| 28639 |
var cursor = this.getCursorPosition(); |
| 28640 |
this.insert("\n"); |
| 28641 |
this.moveCursorToPosition(cursor); |
| 28642 |
}; |
| 28643 |
this.transposeLetters = function() { |
| 28644 |
if (!this.selection.isEmpty()) { |
| 28645 |
return; |
| 28646 |
} |
| 28647 |
|
| 28648 |
var cursor = this.getCursorPosition(); |
| 28649 |
var column = cursor.column; |
| 28650 |
if (column === 0) |
| 28651 |
return; |
| 28652 |
|
| 28653 |
var line = this.session.getLine(cursor.row); |
| 28654 |
var swap, range; |
| 28655 |
if (column < line.length) { |
| 28656 |
swap = line.charAt(column) + line.charAt(column-1); |
| 28657 |
range = new Range(cursor.row, column-1, cursor.row, column+1); |
| 28658 |
} |
| 28659 |
else { |
| 28660 |
swap = line.charAt(column-1) + line.charAt(column-2); |
| 28661 |
range = new Range(cursor.row, column-2, cursor.row, column); |
| 28662 |
} |
| 28663 |
this.session.replace(range, swap); |
| 28664 |
}; |
| 28665 |
this.toLowerCase = function() { |
| 28666 |
var originalRange = this.getSelectionRange(); |
| 28667 |
if (this.selection.isEmpty()) { |
| 28668 |
this.selection.selectWord(); |
| 28669 |
} |
| 28670 |
|
| 28671 |
var range = this.getSelectionRange(); |
| 28672 |
var text = this.session.getTextRange(range); |
| 28673 |
this.session.replace(range, text.toLowerCase()); |
| 28674 |
this.selection.setSelectionRange(originalRange); |
| 28675 |
}; |
| 28676 |
this.toUpperCase = function() { |
| 28677 |
var originalRange = this.getSelectionRange(); |
| 28678 |
if (this.selection.isEmpty()) { |
| 28679 |
this.selection.selectWord(); |
| 28680 |
} |
| 28681 |
|
| 28682 |
var range = this.getSelectionRange(); |
| 28683 |
var text = this.session.getTextRange(range); |
| 28684 |
this.session.replace(range, text.toUpperCase()); |
| 28685 |
this.selection.setSelectionRange(originalRange); |
| 28686 |
}; |
| 28687 |
this.indent = function() { |
| 28688 |
var session = this.session; |
| 28689 |
var range = this.getSelectionRange(); |
| 28690 |
|
| 28691 |
if (range.start.row < range.end.row) { |
| 28692 |
var rows = this.$getSelectedRows(); |
| 28693 |
session.indentRows(rows.first, rows.last, "\t"); |
| 28694 |
return; |
| 28695 |
} else if (range.start.column < range.end.column) { |
| 28696 |
var text = session.getTextRange(range); |
| 28697 |
if (!/^\s+$/.test(text)) { |
| 28698 |
var rows = this.$getSelectedRows(); |
| 28699 |
session.indentRows(rows.first, rows.last, "\t"); |
| 28700 |
return; |
| 28701 |
} |
| 28702 |
} |
| 28703 |
|
| 28704 |
var line = session.getLine(range.start.row); |
| 28705 |
var position = range.start; |
| 28706 |
var size = session.getTabSize(); |
| 28707 |
var column = session.documentToScreenColumn(position.row, position.column); |
| 28708 |
|
| 28709 |
if (this.session.getUseSoftTabs()) { |
| 28710 |
var count = (size - column % size); |
| 28711 |
var indentString = lang.stringRepeat(" ", count); |
| 28712 |
} else { |
| 28713 |
var count = column % size; |
| 28714 |
while (line[range.start.column] == " " && count) { |
| 28715 |
range.start.column--; |
| 28716 |
count--; |
| 28717 |
} |
| 28718 |
this.selection.setSelectionRange(range); |
| 28719 |
indentString = "\t"; |
| 28720 |
} |
| 28721 |
return this.insert(indentString); |
| 28722 |
}; |
| 28723 |
this.blockIndent = function() { |
| 28724 |
var rows = this.$getSelectedRows(); |
| 28725 |
this.session.indentRows(rows.first, rows.last, "\t"); |
| 28726 |
}; |
| 28727 |
this.blockOutdent = function() { |
| 28728 |
var selection = this.session.getSelection(); |
| 28729 |
this.session.outdentRows(selection.getRange()); |
| 28730 |
}; |
| 28731 |
this.sortLines = function() { |
| 28732 |
var rows = this.$getSelectedRows(); |
| 28733 |
var session = this.session; |
| 28734 |
|
| 28735 |
var lines = []; |
| 28736 |
for (i = rows.first; i <= rows.last; i++) |
| 28737 |
lines.push(session.getLine(i)); |
| 28738 |
|
| 28739 |
lines.sort(function(a, b) { |
| 28740 |
if (a.toLowerCase() < b.toLowerCase()) return -1; |
| 28741 |
if (a.toLowerCase() > b.toLowerCase()) return 1; |
| 28742 |
return 0; |
| 28743 |
}); |
| 28744 |
|
| 28745 |
var deleteRange = new Range(0, 0, 0, 0); |
| 28746 |
for (var i = rows.first; i <= rows.last; i++) { |
| 28747 |
var line = session.getLine(i); |
| 28748 |
deleteRange.start.row = i; |
| 28749 |
deleteRange.end.row = i; |
| 28750 |
deleteRange.end.column = line.length; |
| 28751 |
session.replace(deleteRange, lines[i-rows.first]); |
| 28752 |
} |
| 28753 |
}; |
| 28754 |
this.toggleCommentLines = function() { |
| 28755 |
var state = this.session.getState(this.getCursorPosition().row); |
| 28756 |
var rows = this.$getSelectedRows(); |
| 28757 |
this.session.getMode().toggleCommentLines(state, this.session, rows.first, rows.last); |
| 28758 |
}; |
| 28759 |
|
| 28760 |
this.toggleBlockComment = function() { |
| 28761 |
var cursor = this.getCursorPosition(); |
| 28762 |
var state = this.session.getState(cursor.row); |
| 28763 |
var range = this.getSelectionRange(); |
| 28764 |
this.session.getMode().toggleBlockComment(state, this.session, range, cursor); |
| 28765 |
}; |
| 28766 |
this.getNumberAt = function(row, column) { |
| 28767 |
var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g; |
| 28768 |
_numberRx.lastIndex = 0; |
| 28769 |
|
| 28770 |
var s = this.session.getLine(row); |
| 28771 |
while (_numberRx.lastIndex < column) { |
| 28772 |
var m = _numberRx.exec(s); |
| 28773 |
if(m.index <= column && m.index+m[0].length >= column){ |
| 28774 |
var number = { |
| 28775 |
value: m[0], |
| 28776 |
start: m.index, |
| 28777 |
end: m.index+m[0].length |
| 28778 |
}; |
| 28779 |
return number; |
| 28780 |
} |
| 28781 |
} |
| 28782 |
return null; |
| 28783 |
}; |
| 28784 |
this.modifyNumber = function(amount) { |
| 28785 |
var row = this.selection.getCursor().row; |
| 28786 |
var column = this.selection.getCursor().column; |
| 28787 |
var charRange = new Range(row, column-1, row, column); |
| 28788 |
|
| 28789 |
var c = this.session.getTextRange(charRange); |
| 28790 |
if (!isNaN(parseFloat(c)) && isFinite(c)) { |
| 28791 |
var nr = this.getNumberAt(row, column); |
| 28792 |
if (nr) { |
| 28793 |
var fp = nr.value.indexOf(".") >= 0 ? nr.start + nr.value.indexOf(".") + 1 : nr.end; |
| 28794 |
var decimals = nr.start + nr.value.length - fp; |
| 28795 |
|
| 28796 |
var t = parseFloat(nr.value); |
| 28797 |
t *= Math.pow(10, decimals); |
| 28798 |
|
| 28799 |
|
| 28800 |
if(fp !== nr.end && column < fp){ |
| 28801 |
amount *= Math.pow(10, nr.end - column - 1); |
| 28802 |
} else { |
| 28803 |
amount *= Math.pow(10, nr.end - column); |
| 28804 |
} |
| 28805 |
|
| 28806 |
t += amount; |
| 28807 |
t /= Math.pow(10, decimals); |
| 28808 |
var nnr = t.toFixed(decimals); |
| 28809 |
var replaceRange = new Range(row, nr.start, row, nr.end); |
| 28810 |
this.session.replace(replaceRange, nnr); |
| 28811 |
this.moveCursorTo(row, Math.max(nr.start +1, column + nnr.length - nr.value.length)); |
| 28812 |
|
| 28813 |
} |
| 28814 |
} |
| 28815 |
}; |
| 28816 |
this.removeLines = function() { |
| 28817 |
var rows = this.$getSelectedRows(); |
| 28818 |
this.session.removeFullLines(rows.first, rows.last); |
| 28819 |
this.clearSelection(); |
| 28820 |
}; |
| 28821 |
|
| 28822 |
this.duplicateSelection = function() { |
| 28823 |
var sel = this.selection; |
| 28824 |
var doc = this.session; |
| 28825 |
var range = sel.getRange(); |
| 28826 |
var reverse = sel.isBackwards(); |
| 28827 |
if (range.isEmpty()) { |
| 28828 |
var row = range.start.row; |
| 28829 |
doc.duplicateLines(row, row); |
| 28830 |
} else { |
| 28831 |
var point = reverse ? range.start : range.end; |
| 28832 |
var endPoint = doc.insert(point, doc.getTextRange(range), false); |
| 28833 |
range.start = point; |
| 28834 |
range.end = endPoint; |
| 28835 |
|
| 28836 |
sel.setSelectionRange(range, reverse); |
| 28837 |
} |
| 28838 |
}; |
| 28839 |
this.moveLinesDown = function() { |
| 28840 |
this.$moveLines(1, false); |
| 28841 |
}; |
| 28842 |
this.moveLinesUp = function() { |
| 28843 |
this.$moveLines(-1, false); |
| 28844 |
}; |
| 28845 |
this.moveText = function(range, toPosition, copy) { |
| 28846 |
return this.session.moveText(range, toPosition, copy); |
| 28847 |
}; |
| 28848 |
this.copyLinesUp = function() { |
| 28849 |
this.$moveLines(-1, true); |
| 28850 |
}; |
| 28851 |
this.copyLinesDown = function() { |
| 28852 |
this.$moveLines(1, true); |
| 28853 |
}; |
| 28854 |
this.$moveLines = function(dir, copy) { |
| 28855 |
var rows, moved; |
| 28856 |
var selection = this.selection; |
| 28857 |
if (!selection.inMultiSelectMode || this.inVirtualSelectionMode) { |
| 28858 |
var range = selection.toOrientedRange(); |
| 28859 |
rows = this.$getSelectedRows(range); |
| 28860 |
moved = this.session.$moveLines(rows.first, rows.last, copy ? 0 : dir); |
| 28861 |
if (copy && dir == -1) moved = 0; |
| 28862 |
range.moveBy(moved, 0); |
| 28863 |
selection.fromOrientedRange(range); |
| 28864 |
} else { |
| 28865 |
var ranges = selection.rangeList.ranges; |
| 28866 |
selection.rangeList.detach(this.session); |
| 28867 |
this.inVirtualSelectionMode = true; |
| 28868 |
|
| 28869 |
var diff = 0; |
| 28870 |
var totalDiff = 0; |
| 28871 |
var l = ranges.length; |
| 28872 |
for (var i = 0; i < l; i++) { |
| 28873 |
var rangeIndex = i; |
| 28874 |
ranges[i].moveBy(diff, 0); |
| 28875 |
rows = this.$getSelectedRows(ranges[i]); |
| 28876 |
var first = rows.first; |
| 28877 |
var last = rows.last; |
| 28878 |
while (++i < l) { |
| 28879 |
if (totalDiff) ranges[i].moveBy(totalDiff, 0); |
| 28880 |
var subRows = this.$getSelectedRows(ranges[i]); |
| 28881 |
if (copy && subRows.first != last) |
| 28882 |
break; |
| 28883 |
else if (!copy && subRows.first > last + 1) |
| 28884 |
break; |
| 28885 |
last = subRows.last; |
| 28886 |
} |
| 28887 |
i--; |
| 28888 |
diff = this.session.$moveLines(first, last, copy ? 0 : dir); |
| 28889 |
if (copy && dir == -1) rangeIndex = i + 1; |
| 28890 |
while (rangeIndex <= i) { |
| 28891 |
ranges[rangeIndex].moveBy(diff, 0); |
| 28892 |
rangeIndex++; |
| 28893 |
} |
| 28894 |
if (!copy) diff = 0; |
| 28895 |
totalDiff += diff; |
| 28896 |
} |
| 28897 |
|
| 28898 |
selection.fromOrientedRange(selection.ranges[0]); |
| 28899 |
selection.rangeList.attach(this.session); |
| 28900 |
this.inVirtualSelectionMode = false; |
| 28901 |
} |
| 28902 |
}; |
| 28903 |
this.$getSelectedRows = function(range) { |
| 28904 |
range = (range || this.getSelectionRange()).collapseRows(); |
| 28905 |
|
| 28906 |
return { |
| 28907 |
first: this.session.getRowFoldStart(range.start.row), |
| 28908 |
last: this.session.getRowFoldEnd(range.end.row) |
| 28909 |
}; |
| 28910 |
}; |
| 28911 |
|
| 28912 |
this.onCompositionStart = function(text) { |
| 28913 |
this.renderer.showComposition(this.getCursorPosition()); |
| 28914 |
}; |
| 28915 |
|
| 28916 |
this.onCompositionUpdate = function(text) { |
| 28917 |
this.renderer.setCompositionText(text); |
| 28918 |
}; |
| 28919 |
|
| 28920 |
this.onCompositionEnd = function() { |
| 28921 |
this.renderer.hideComposition(); |
| 28922 |
}; |
| 28923 |
this.getFirstVisibleRow = function() { |
| 28924 |
return this.renderer.getFirstVisibleRow(); |
| 28925 |
}; |
| 28926 |
this.getLastVisibleRow = function() { |
| 28927 |
return this.renderer.getLastVisibleRow(); |
| 28928 |
}; |
| 28929 |
this.isRowVisible = function(row) { |
| 28930 |
return (row >= this.getFirstVisibleRow() && row <= this.getLastVisibleRow()); |
| 28931 |
}; |
| 28932 |
this.isRowFullyVisible = function(row) { |
| 28933 |
return (row >= this.renderer.getFirstFullyVisibleRow() && row <= this.renderer.getLastFullyVisibleRow()); |
| 28934 |
}; |
| 28935 |
this.$getVisibleRowCount = function() { |
| 28936 |
return this.renderer.getScrollBottomRow() - this.renderer.getScrollTopRow() + 1; |
| 28937 |
}; |
| 28938 |
|
| 28939 |
this.$moveByPage = function(dir, select) { |
| 28940 |
var renderer = this.renderer; |
| 28941 |
var config = this.renderer.layerConfig; |
| 28942 |
var rows = dir * Math.floor(config.height / config.lineHeight); |
| 28943 |
|
| 28944 |
this.$blockScrolling++; |
| 28945 |
if (select === true) { |
| 28946 |
this.selection.$moveSelection(function(){ |
| 28947 |
this.moveCursorBy(rows, 0); |
| 28948 |
}); |
| 28949 |
} else if (select === false) { |
| 28950 |
this.selection.moveCursorBy(rows, 0); |
| 28951 |
this.selection.clearSelection(); |
| 28952 |
} |
| 28953 |
this.$blockScrolling--; |
| 28954 |
|
| 28955 |
var scrollTop = renderer.scrollTop; |
| 28956 |
|
| 28957 |
renderer.scrollBy(0, rows * config.lineHeight); |
| 28958 |
if (select != null) |
| 28959 |
renderer.scrollCursorIntoView(null, 0.5); |
| 28960 |
|
| 28961 |
renderer.animateScrolling(scrollTop); |
| 28962 |
}; |
| 28963 |
this.selectPageDown = function() { |
| 28964 |
this.$moveByPage(1, true); |
| 28965 |
}; |
| 28966 |
this.selectPageUp = function() { |
| 28967 |
this.$moveByPage(-1, true); |
| 28968 |
}; |
| 28969 |
this.gotoPageDown = function() { |
| 28970 |
this.$moveByPage(1, false); |
| 28971 |
}; |
| 28972 |
this.gotoPageUp = function() { |
| 28973 |
this.$moveByPage(-1, false); |
| 28974 |
}; |
| 28975 |
this.scrollPageDown = function() { |
| 28976 |
this.$moveByPage(1); |
| 28977 |
}; |
| 28978 |
this.scrollPageUp = function() { |
| 28979 |
this.$moveByPage(-1); |
| 28980 |
}; |
| 28981 |
this.scrollToRow = function(row) { |
| 28982 |
this.renderer.scrollToRow(row); |
| 28983 |
}; |
| 28984 |
this.scrollToLine = function(line, center, animate, callback) { |
| 28985 |
this.renderer.scrollToLine(line, center, animate, callback); |
| 28986 |
}; |
| 28987 |
this.centerSelection = function() { |
| 28988 |
var range = this.getSelectionRange(); |
| 28989 |
var pos = { |
| 28990 |
row: Math.floor(range.start.row + (range.end.row - range.start.row) / 2), |
| 28991 |
column: Math.floor(range.start.column + (range.end.column - range.start.column) / 2) |
| 28992 |
}; |
| 28993 |
this.renderer.alignCursor(pos, 0.5); |
| 28994 |
}; |
| 28995 |
this.getCursorPosition = function() { |
| 28996 |
return this.selection.getCursor(); |
| 28997 |
}; |
| 28998 |
this.getCursorPositionScreen = function() { |
| 28999 |
return this.session.documentToScreenPosition(this.getCursorPosition()); |
| 29000 |
}; |
| 29001 |
this.getSelectionRange = function() { |
| 29002 |
return this.selection.getRange(); |
| 29003 |
}; |
| 29004 |
this.selectAll = function() { |
| 29005 |
this.$blockScrolling += 1; |
| 29006 |
this.selection.selectAll(); |
| 29007 |
this.$blockScrolling -= 1; |
| 29008 |
}; |
| 29009 |
this.clearSelection = function() { |
| 29010 |
this.selection.clearSelection(); |
| 29011 |
}; |
| 29012 |
this.moveCursorTo = function(row, column) { |
| 29013 |
this.selection.moveCursorTo(row, column); |
| 29014 |
}; |
| 29015 |
this.moveCursorToPosition = function(pos) { |
| 29016 |
this.selection.moveCursorToPosition(pos); |
| 29017 |
}; |
| 29018 |
this.jumpToMatching = function(select, expand) { |
| 29019 |
var cursor = this.getCursorPosition(); |
| 29020 |
var iterator = new TokenIterator(this.session, cursor.row, cursor.column); |
| 29021 |
var prevToken = iterator.getCurrentToken(); |
| 29022 |
var token = prevToken || iterator.stepForward(); |
| 29023 |
|
| 29024 |
if (!token) return; |
| 29025 |
var matchType; |
| 29026 |
var found = false; |
| 29027 |
var depth = {}; |
| 29028 |
var i = cursor.column - token.start; |
| 29029 |
var bracketType; |
| 29030 |
var brackets = { |
| 29031 |
")": "(", |
| 29032 |
"(": "(", |
| 29033 |
"]": "[", |
| 29034 |
"[": "[", |
| 29035 |
"{": "{", |
| 29036 |
"}": "{" |
| 29037 |
}; |
| 29038 |
|
| 29039 |
do { |
| 29040 |
if (token.value.match(/[{}()\[\]]/g)) { |
| 29041 |
for (; i < token.value.length && !found; i++) { |
| 29042 |
if (!brackets[token.value[i]]) { |
| 29043 |
continue; |
| 29044 |
} |
| 29045 |
|
| 29046 |
bracketType = brackets[token.value[i]] + '.' + token.type.replace("rparen", "lparen"); |
| 29047 |
|
| 29048 |
if (isNaN(depth[bracketType])) { |
| 29049 |
depth[bracketType] = 0; |
| 29050 |
} |
| 29051 |
|
| 29052 |
switch (token.value[i]) { |
| 29053 |
case '(': |
| 29054 |
case '[': |
| 29055 |
case '{': |
| 29056 |
depth[bracketType]++; |
| 29057 |
break; |
| 29058 |
case ')': |
| 29059 |
case ']': |
| 29060 |
case '}': |
| 29061 |
depth[bracketType]--; |
| 29062 |
|
| 29063 |
if (depth[bracketType] === -1) { |
| 29064 |
matchType = 'bracket'; |
| 29065 |
found = true; |
| 29066 |
} |
| 29067 |
break; |
| 29068 |
} |
| 29069 |
} |
| 29070 |
} |
| 29071 |
else if (token && token.type.indexOf('tag-name') !== -1) { |
| 29072 |
if (isNaN(depth[token.value])) { |
| 29073 |
depth[token.value] = 0; |
| 29074 |
} |
| 29075 |
|
| 29076 |
if (prevToken.value === '<') { |
| 29077 |
depth[token.value]++; |
| 29078 |
} |
| 29079 |
else if (prevToken.value === '</') { |
| 29080 |
depth[token.value]--; |
| 29081 |
} |
| 29082 |
|
| 29083 |
if (depth[token.value] === -1) { |
| 29084 |
matchType = 'tag'; |
| 29085 |
found = true; |
| 29086 |
} |
| 29087 |
} |
| 29088 |
|
| 29089 |
if (!found) { |
| 29090 |
prevToken = token; |
| 29091 |
token = iterator.stepForward(); |
| 29092 |
i = 0; |
| 29093 |
} |
| 29094 |
} while (token && !found); |
| 29095 |
if (!matchType) |
| 29096 |
return; |
| 29097 |
|
| 29098 |
var range, pos; |
| 29099 |
if (matchType === 'bracket') { |
| 29100 |
range = this.session.getBracketRange(cursor); |
| 29101 |
if (!range) { |
| 29102 |
range = new Range( |
| 29103 |
iterator.getCurrentTokenRow(), |
| 29104 |
iterator.getCurrentTokenColumn() + i - 1, |
| 29105 |
iterator.getCurrentTokenRow(), |
| 29106 |
iterator.getCurrentTokenColumn() + i - 1 |
| 29107 |
); |
| 29108 |
pos = range.start; |
| 29109 |
if (expand || pos.row === cursor.row && Math.abs(pos.column - cursor.column) < 2) |
| 29110 |
range = this.session.getBracketRange(pos); |
| 29111 |
} |
| 29112 |
} |
| 29113 |
else if (matchType === 'tag') { |
| 29114 |
if (token && token.type.indexOf('tag-name') !== -1) |
| 29115 |
var tag = token.value; |
| 29116 |
else |
| 29117 |
return; |
| 29118 |
|
| 29119 |
range = new Range( |
| 29120 |
iterator.getCurrentTokenRow(), |
| 29121 |
iterator.getCurrentTokenColumn() - 2, |
| 29122 |
iterator.getCurrentTokenRow(), |
| 29123 |
iterator.getCurrentTokenColumn() - 2 |
| 29124 |
); |
| 29125 |
if (range.compare(cursor.row, cursor.column) === 0) { |
| 29126 |
found = false; |
| 29127 |
do { |
| 29128 |
token = prevToken; |
| 29129 |
prevToken = iterator.stepBackward(); |
| 29130 |
|
| 29131 |
if (prevToken) { |
| 29132 |
if (prevToken.type.indexOf('tag-close') !== -1) { |
| 29133 |
range.setEnd(iterator.getCurrentTokenRow(), iterator.getCurrentTokenColumn() + 1); |
| 29134 |
} |
| 29135 |
|
| 29136 |
if (token.value === tag && token.type.indexOf('tag-name') !== -1) { |
| 29137 |
if (prevToken.value === '<') { |
| 29138 |
depth[tag]++; |
| 29139 |
} |
| 29140 |
else if (prevToken.value === '</') { |
| 29141 |
depth[tag]--; |
| 29142 |
} |
| 29143 |
|
| 29144 |
if (depth[tag] === 0) |
| 29145 |
found = true; |
| 29146 |
} |
| 29147 |
} |
| 29148 |
} while (prevToken && !found); |
| 29149 |
} |
| 29150 |
if (token && token.type.indexOf('tag-name')) { |
| 29151 |
pos = range.start; |
| 29152 |
if (pos.row == cursor.row && Math.abs(pos.column - cursor.column) < 2) |
| 29153 |
pos = range.end; |
| 29154 |
} |
| 29155 |
} |
| 29156 |
|
| 29157 |
pos = range && range.cursor || pos; |
| 29158 |
if (pos) { |
| 29159 |
if (select) { |
| 29160 |
if (range && expand) { |
| 29161 |
this.selection.setRange(range); |
| 29162 |
} else if (range && range.isEqual(this.getSelectionRange())) { |
| 29163 |
this.clearSelection(); |
| 29164 |
} else { |
| 29165 |
this.selection.selectTo(pos.row, pos.column); |
| 29166 |
} |
| 29167 |
} else { |
| 29168 |
this.selection.moveTo(pos.row, pos.column); |
| 29169 |
} |
| 29170 |
} |
| 29171 |
}; |
| 29172 |
this.gotoLine = function(lineNumber, column, animate) { |
| 29173 |
this.selection.clearSelection(); |
| 29174 |
this.session.unfold({row: lineNumber - 1, column: column || 0}); |
| 29175 |
|
| 29176 |
this.$blockScrolling += 1; |
| 29177 |
this.exitMultiSelectMode && this.exitMultiSelectMode(); |
| 29178 |
this.moveCursorTo(lineNumber - 1, column || 0); |
| 29179 |
this.$blockScrolling -= 1; |
| 29180 |
|
| 29181 |
if (!this.isRowFullyVisible(lineNumber - 1)) |
| 29182 |
this.scrollToLine(lineNumber - 1, true, animate); |
| 29183 |
}; |
| 29184 |
this.navigateTo = function(row, column) { |
| 29185 |
this.selection.moveTo(row, column); |
| 29186 |
}; |
| 29187 |
this.navigateUp = function(times) { |
| 29188 |
if (this.selection.isMultiLine() && !this.selection.isBackwards()) { |
| 29189 |
var selectionStart = this.selection.anchor.getPosition(); |
| 29190 |
return this.moveCursorToPosition(selectionStart); |
| 29191 |
} |
| 29192 |
this.selection.clearSelection(); |
| 29193 |
this.selection.moveCursorBy(-times || -1, 0); |
| 29194 |
}; |
| 29195 |
this.navigateDown = function(times) { |
| 29196 |
if (this.selection.isMultiLine() && this.selection.isBackwards()) { |
| 29197 |
var selectionEnd = this.selection.anchor.getPosition(); |
| 29198 |
return this.moveCursorToPosition(selectionEnd); |
| 29199 |
} |
| 29200 |
this.selection.clearSelection(); |
| 29201 |
this.selection.moveCursorBy(times || 1, 0); |
| 29202 |
}; |
| 29203 |
this.navigateLeft = function(times) { |
| 29204 |
if (!this.selection.isEmpty()) { |
| 29205 |
var selectionStart = this.getSelectionRange().start; |
| 29206 |
this.moveCursorToPosition(selectionStart); |
| 29207 |
} |
| 29208 |
else { |
| 29209 |
times = times || 1; |
| 29210 |
while (times--) { |
| 29211 |
this.selection.moveCursorLeft(); |
| 29212 |
} |
| 29213 |
} |
| 29214 |
this.clearSelection(); |
| 29215 |
}; |
| 29216 |
this.navigateRight = function(times) { |
| 29217 |
if (!this.selection.isEmpty()) { |
| 29218 |
var selectionEnd = this.getSelectionRange().end; |
| 29219 |
this.moveCursorToPosition(selectionEnd); |
| 29220 |
} |
| 29221 |
else { |
| 29222 |
times = times || 1; |
| 29223 |
while (times--) { |
| 29224 |
this.selection.moveCursorRight(); |
| 29225 |
} |
| 29226 |
} |
| 29227 |
this.clearSelection(); |
| 29228 |
}; |
| 29229 |
this.navigateLineStart = function() { |
| 29230 |
this.selection.moveCursorLineStart(); |
| 29231 |
this.clearSelection(); |
| 29232 |
}; |
| 29233 |
this.navigateLineEnd = function() { |
| 29234 |
this.selection.moveCursorLineEnd(); |
| 29235 |
this.clearSelection(); |
| 29236 |
}; |
| 29237 |
this.navigateFileEnd = function() { |
| 29238 |
this.selection.moveCursorFileEnd(); |
| 29239 |
this.clearSelection(); |
| 29240 |
}; |
| 29241 |
this.navigateFileStart = function() { |
| 29242 |
this.selection.moveCursorFileStart(); |
| 29243 |
this.clearSelection(); |
| 29244 |
}; |
| 29245 |
this.navigateWordRight = function() { |
| 29246 |
this.selection.moveCursorWordRight(); |
| 29247 |
this.clearSelection(); |
| 29248 |
}; |
| 29249 |
this.navigateWordLeft = function() { |
| 29250 |
this.selection.moveCursorWordLeft(); |
| 29251 |
this.clearSelection(); |
| 29252 |
}; |
| 29253 |
this.replace = function(replacement, options) { |
| 29254 |
if (options) |
| 29255 |
this.$search.set(options); |
| 29256 |
|
| 29257 |
var range = this.$search.find(this.session); |
| 29258 |
var replaced = 0; |
| 29259 |
if (!range) |
| 29260 |
return replaced; |
| 29261 |
|
| 29262 |
if (this.$tryReplace(range, replacement)) { |
| 29263 |
replaced = 1; |
| 29264 |
} |
| 29265 |
if (range !== null) { |
| 29266 |
this.selection.setSelectionRange(range); |
| 29267 |
this.renderer.scrollSelectionIntoView(range.start, range.end); |
| 29268 |
} |
| 29269 |
|
| 29270 |
return replaced; |
| 29271 |
}; |
| 29272 |
this.replaceAll = function(replacement, options) { |
| 29273 |
if (options) { |
| 29274 |
this.$search.set(options); |
| 29275 |
} |
| 29276 |
|
| 29277 |
var ranges = this.$search.findAll(this.session); |
| 29278 |
var replaced = 0; |
| 29279 |
if (!ranges.length) |
| 29280 |
return replaced; |
| 29281 |
|
| 29282 |
this.$blockScrolling += 1; |
| 29283 |
|
| 29284 |
var selection = this.getSelectionRange(); |
| 29285 |
this.selection.moveTo(0, 0); |
| 29286 |
|
| 29287 |
for (var i = ranges.length - 1; i >= 0; --i) { |
| 29288 |
if(this.$tryReplace(ranges[i], replacement)) { |
| 29289 |
replaced++; |
| 29290 |
} |
| 29291 |
} |
| 29292 |
|
| 29293 |
this.selection.setSelectionRange(selection); |
| 29294 |
this.$blockScrolling -= 1; |
| 29295 |
|
| 29296 |
return replaced; |
| 29297 |
}; |
| 29298 |
|
| 29299 |
this.$tryReplace = function(range, replacement) { |
| 29300 |
var input = this.session.getTextRange(range); |
| 29301 |
replacement = this.$search.replace(input, replacement); |
| 29302 |
if (replacement !== null) { |
| 29303 |
range.end = this.session.replace(range, replacement); |
| 29304 |
return range; |
| 29305 |
} else { |
| 29306 |
return null; |
| 29307 |
} |
| 29308 |
}; |
| 29309 |
this.getLastSearchOptions = function() { |
| 29310 |
return this.$search.getOptions(); |
| 29311 |
}; |
| 29312 |
this.find = function(needle, options, animate) { |
| 29313 |
if (!options) |
| 29314 |
options = {}; |
| 29315 |
|
| 29316 |
if (typeof needle == "string" || needle instanceof RegExp) |
| 29317 |
options.needle = needle; |
| 29318 |
else if (typeof needle == "object") |
| 29319 |
oop.mixin(options, needle); |
| 29320 |
|
| 29321 |
var range = this.selection.getRange(); |
| 29322 |
if (options.needle == null) { |
| 29323 |
needle = this.session.getTextRange(range) |
| 29324 |
|| this.$search.$options.needle; |
| 29325 |
if (!needle) { |
| 29326 |
range = this.session.getWordRange(range.start.row, range.start.column); |
| 29327 |
needle = this.session.getTextRange(range); |
| 29328 |
} |
| 29329 |
this.$search.set({needle: needle}); |
| 29330 |
} |
| 29331 |
|
| 29332 |
this.$search.set(options); |
| 29333 |
if (!options.start) |
| 29334 |
this.$search.set({start: range}); |
| 29335 |
|
| 29336 |
var newRange = this.$search.find(this.session); |
| 29337 |
if (options.preventScroll) |
| 29338 |
return newRange; |
| 29339 |
if (newRange) { |
| 29340 |
this.revealRange(newRange, animate); |
| 29341 |
return newRange; |
| 29342 |
} |
| 29343 |
if (options.backwards) |
| 29344 |
range.start = range.end; |
| 29345 |
else |
| 29346 |
range.end = range.start; |
| 29347 |
this.selection.setRange(range); |
| 29348 |
}; |
| 29349 |
this.findNext = function(options, animate) { |
| 29350 |
this.find({skipCurrent: true, backwards: false}, options, animate); |
| 29351 |
}; |
| 29352 |
this.findPrevious = function(options, animate) { |
| 29353 |
this.find(options, {skipCurrent: true, backwards: true}, animate); |
| 29354 |
}; |
| 29355 |
|
| 29356 |
this.revealRange = function(range, animate) { |
| 29357 |
this.$blockScrolling += 1; |
| 29358 |
this.session.unfold(range); |
| 29359 |
this.selection.setSelectionRange(range); |
| 29360 |
this.$blockScrolling -= 1; |
| 29361 |
|
| 29362 |
var scrollTop = this.renderer.scrollTop; |
| 29363 |
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5); |
| 29364 |
if (animate !== false) |
| 29365 |
this.renderer.animateScrolling(scrollTop); |
| 29366 |
}; |
| 29367 |
this.undo = function() { |
| 29368 |
this.$blockScrolling++; |
| 29369 |
this.session.getUndoManager().undo(); |
| 29370 |
this.$blockScrolling--; |
| 29371 |
this.renderer.scrollCursorIntoView(null, 0.5); |
| 29372 |
}; |
| 29373 |
this.redo = function() { |
| 29374 |
this.$blockScrolling++; |
| 29375 |
this.session.getUndoManager().redo(); |
| 29376 |
this.$blockScrolling--; |
| 29377 |
this.renderer.scrollCursorIntoView(null, 0.5); |
| 29378 |
}; |
| 29379 |
this.destroy = function() { |
| 29380 |
this.renderer.destroy(); |
| 29381 |
this._signal("destroy", this); |
| 29382 |
if (this.session) { |
| 29383 |
this.session.destroy(); |
| 29384 |
} |
| 29385 |
}; |
| 29386 |
this.setAutoScrollEditorIntoView = function(enable) { |
| 29387 |
if (!enable) |
| 29388 |
return; |
| 29389 |
var rect; |
| 29390 |
var self = this; |
| 29391 |
var shouldScroll = false; |
| 29392 |
if (!this.$scrollAnchor) |
| 29393 |
this.$scrollAnchor = document.createElement("div"); |
| 29394 |
var scrollAnchor = this.$scrollAnchor; |
| 29395 |
scrollAnchor.style.cssText = "position:absolute"; |
| 29396 |
this.container.insertBefore(scrollAnchor, this.container.firstChild); |
| 29397 |
var onChangeSelection = this.on("changeSelection", function() { |
| 29398 |
shouldScroll = true; |
| 29399 |
}); |
| 29400 |
var onBeforeRender = this.renderer.on("beforeRender", function() { |
| 29401 |
if (shouldScroll) |
| 29402 |
rect = self.renderer.container.getBoundingClientRect(); |
| 29403 |
}); |
| 29404 |
var onAfterRender = this.renderer.on("afterRender", function() { |
| 29405 |
if (shouldScroll && rect && (self.isFocused() |
| 29406 |
|| self.searchBox && self.searchBox.isFocused()) |
| 29407 |
) { |
| 29408 |
var renderer = self.renderer; |
| 29409 |
var pos = renderer.$cursorLayer.$pixelPos; |
| 29410 |
var config = renderer.layerConfig; |
| 29411 |
var top = pos.top - config.offset; |
| 29412 |
if (pos.top >= 0 && top + rect.top < 0) { |
| 29413 |
shouldScroll = true; |
| 29414 |
} else if (pos.top < config.height && |
| 29415 |
pos.top + rect.top + config.lineHeight > window.innerHeight) { |
| 29416 |
shouldScroll = false; |
| 29417 |
} else { |
| 29418 |
shouldScroll = null; |
| 29419 |
} |
| 29420 |
if (shouldScroll != null) { |
| 29421 |
scrollAnchor.style.top = top + "px"; |
| 29422 |
scrollAnchor.style.left = pos.left + "px"; |
| 29423 |
scrollAnchor.style.height = config.lineHeight + "px"; |
| 29424 |
scrollAnchor.scrollIntoView(shouldScroll); |
| 29425 |
} |
| 29426 |
shouldScroll = rect = null; |
| 29427 |
} |
| 29428 |
}); |
| 29429 |
this.setAutoScrollEditorIntoView = function(enable) { |
| 29430 |
if (enable) |
| 29431 |
return; |
| 29432 |
delete this.setAutoScrollEditorIntoView; |
| 29433 |
this.off("changeSelection", onChangeSelection); |
| 29434 |
this.renderer.off("afterRender", onAfterRender); |
| 29435 |
this.renderer.off("beforeRender", onBeforeRender); |
| 29436 |
}; |
| 29437 |
}; |
| 29438 |
|
| 29439 |
|
| 29440 |
this.$resetCursorStyle = function() { |
| 29441 |
var style = this.$cursorStyle || "ace"; |
| 29442 |
var cursorLayer = this.renderer.$cursorLayer; |
| 29443 |
if (!cursorLayer) |
| 29444 |
return; |
| 29445 |
cursorLayer.setSmoothBlinking(/smooth/.test(style)); |
| 29446 |
cursorLayer.isBlinking = !this.$readOnly && style != "wide"; |
| 29447 |
dom.setCssClass(cursorLayer.element, "ace_slim-cursors", /slim/.test(style)); |
| 29448 |
}; |
| 29449 |
|
| 29450 |
}).call(Editor.prototype); |
| 29451 |
|
| 29452 |
|
| 29453 |
|
| 29454 |
config.defineOptions(Editor.prototype, "editor", { |
| 29455 |
selectionStyle: { |
| 29456 |
set: function(style) { |
| 29457 |
this.onSelectionChange(); |
| 29458 |
this._signal("changeSelectionStyle", {data: style}); |
| 29459 |
}, |
| 29460 |
initialValue: "line" |
| 29461 |
}, |
| 29462 |
highlightActiveLine: { |
| 29463 |
set: function() {this.$updateHighlightActiveLine();}, |
| 29464 |
initialValue: true |
| 29465 |
}, |
| 29466 |
highlightSelectedWord: { |
| 29467 |
set: function(shouldHighlight) {this.$onSelectionChange();}, |
| 29468 |
initialValue: true |
| 29469 |
}, |
| 29470 |
readOnly: { |
| 29471 |
set: function(readOnly) { |
| 29472 |
this.$resetCursorStyle(); |
| 29473 |
}, |
| 29474 |
initialValue: false |
| 29475 |
}, |
| 29476 |
cursorStyle: { |
| 29477 |
set: function(val) { this.$resetCursorStyle(); }, |
| 29478 |
values: ["ace", "slim", "smooth", "wide"], |
| 29479 |
initialValue: "ace" |
| 29480 |
}, |
| 29481 |
mergeUndoDeltas: { |
| 29482 |
values: [false, true, "always"], |
| 29483 |
initialValue: true |
| 29484 |
}, |
| 29485 |
behavioursEnabled: {initialValue: true}, |
| 29486 |
wrapBehavioursEnabled: {initialValue: true}, |
| 29487 |
autoScrollEditorIntoView: { |
| 29488 |
set: function(val) {this.setAutoScrollEditorIntoView(val)} |
| 29489 |
}, |
| 29490 |
keyboardHandler: { |
| 29491 |
set: function(val) { this.setKeyboardHandler(val); }, |
| 29492 |
get: function() { return this.keybindingId; }, |
| 29493 |
handlesSet: true |
| 29494 |
}, |
| 29495 |
|
| 29496 |
hScrollBarAlwaysVisible: "renderer", |
| 29497 |
vScrollBarAlwaysVisible: "renderer", |
| 29498 |
highlightGutterLine: "renderer", |
| 29499 |
animatedScroll: "renderer", |
| 29500 |
showInvisibles: "renderer", |
| 29501 |
showPrintMargin: "renderer", |
| 29502 |
printMarginColumn: "renderer", |
| 29503 |
printMargin: "renderer", |
| 29504 |
fadeFoldWidgets: "renderer", |
| 29505 |
showFoldWidgets: "renderer", |
| 29506 |
showLineNumbers: "renderer", |
| 29507 |
showGutter: "renderer", |
| 29508 |
displayIndentGuides: "renderer", |
| 29509 |
fontSize: "renderer", |
| 29510 |
fontFamily: "renderer", |
| 29511 |
maxLines: "renderer", |
| 29512 |
minLines: "renderer", |
| 29513 |
scrollPastEnd: "renderer", |
| 29514 |
fixedWidthGutter: "renderer", |
| 29515 |
theme: "renderer", |
| 29516 |
|
| 29517 |
scrollSpeed: "$mouseHandler", |
| 29518 |
dragDelay: "$mouseHandler", |
| 29519 |
dragEnabled: "$mouseHandler", |
| 29520 |
focusTimout: "$mouseHandler", |
| 29521 |
tooltipFollowsMouse: "$mouseHandler", |
| 29522 |
|
| 29523 |
firstLineNumber: "session", |
| 29524 |
overwrite: "session", |
| 29525 |
newLineMode: "session", |
| 29526 |
useWorker: "session", |
| 29527 |
useSoftTabs: "session", |
| 29528 |
tabSize: "session", |
| 29529 |
wrap: "session", |
| 29530 |
indentedSoftWrap: "session", |
| 29531 |
foldStyle: "session", |
| 29532 |
mode: "session" |
| 29533 |
}); |
| 29534 |
|
| 29535 |
exports.Editor = Editor; |
| 29536 |
}); |
| 29537 |
|
| 29538 |
ace.define("ace/undomanager",["require","exports","module"], function(acequire, exports, module) { |
| 29539 |
"use strict"; |
| 29540 |
var UndoManager = function() { |
| 29541 |
this.reset(); |
| 29542 |
}; |
| 29543 |
|
| 29544 |
(function() { |
| 29545 |
this.execute = function(options) { |
| 29546 |
var deltaSets = options.args[0]; |
| 29547 |
this.$doc = options.args[1]; |
| 29548 |
if (options.merge && this.hasUndo()){ |
| 29549 |
this.dirtyCounter--; |
| 29550 |
deltaSets = this.$undoStack.pop().concat(deltaSets); |
| 29551 |
} |
| 29552 |
this.$undoStack.push(deltaSets); |
| 29553 |
this.$redoStack = []; |
| 29554 |
if (this.dirtyCounter < 0) { |
| 29555 |
this.dirtyCounter = NaN; |
| 29556 |
} |
| 29557 |
this.dirtyCounter++; |
| 29558 |
}; |
| 29559 |
this.undo = function(dontSelect) { |
| 29560 |
var deltaSets = this.$undoStack.pop(); |
| 29561 |
var undoSelectionRange = null; |
| 29562 |
if (deltaSets) { |
| 29563 |
undoSelectionRange = this.$doc.undoChanges(deltaSets, dontSelect); |
| 29564 |
this.$redoStack.push(deltaSets); |
| 29565 |
this.dirtyCounter--; |
| 29566 |
} |
| 29567 |
|
| 29568 |
return undoSelectionRange; |
| 29569 |
}; |
| 29570 |
this.redo = function(dontSelect) { |
| 29571 |
var deltaSets = this.$redoStack.pop(); |
| 29572 |
var redoSelectionRange = null; |
| 29573 |
if (deltaSets) { |
| 29574 |
redoSelectionRange = |
| 29575 |
this.$doc.redoChanges(this.$deserializeDeltas(deltaSets), dontSelect); |
| 29576 |
this.$undoStack.push(deltaSets); |
| 29577 |
this.dirtyCounter++; |
| 29578 |
} |
| 29579 |
return redoSelectionRange; |
| 29580 |
}; |
| 29581 |
this.reset = function() { |
| 29582 |
this.$undoStack = []; |
| 29583 |
this.$redoStack = []; |
| 29584 |
this.dirtyCounter = 0; |
| 29585 |
}; |
| 29586 |
this.hasUndo = function() { |
| 29587 |
return this.$undoStack.length > 0; |
| 29588 |
}; |
| 29589 |
this.hasRedo = function() { |
| 29590 |
return this.$redoStack.length > 0; |
| 29591 |
}; |
| 29592 |
this.markClean = function() { |
| 29593 |
this.dirtyCounter = 0; |
| 29594 |
}; |
| 29595 |
this.isClean = function() { |
| 29596 |
return this.dirtyCounter === 0; |
| 29597 |
}; |
| 29598 |
this.$serializeDeltas = function(deltaSets) { |
| 29599 |
return cloneDeltaSetsObj(deltaSets, $serializeDelta); |
| 29600 |
}; |
| 29601 |
this.$deserializeDeltas = function(deltaSets) { |
| 29602 |
return cloneDeltaSetsObj(deltaSets, $deserializeDelta); |
| 29603 |
}; |
| 29604 |
|
| 29605 |
function $serializeDelta(delta){ |
| 29606 |
return { |
| 29607 |
action: delta.action, |
| 29608 |
start: delta.start, |
| 29609 |
end: delta.end, |
| 29610 |
lines: delta.lines.length == 1 ? null : delta.lines, |
| 29611 |
text: delta.lines.length == 1 ? delta.lines[0] : null |
| 29612 |
}; |
| 29613 |
} |
| 29614 |
|
| 29615 |
function $deserializeDelta(delta) { |
| 29616 |
return { |
| 29617 |
action: delta.action, |
| 29618 |
start: delta.start, |
| 29619 |
end: delta.end, |
| 29620 |
lines: delta.lines || [delta.text] |
| 29621 |
}; |
| 29622 |
} |
| 29623 |
|
| 29624 |
function cloneDeltaSetsObj(deltaSets_old, fnGetModifiedDelta) { |
| 29625 |
var deltaSets_new = new Array(deltaSets_old.length); |
| 29626 |
for (var i = 0; i < deltaSets_old.length; i++) { |
| 29627 |
var deltaSet_old = deltaSets_old[i]; |
| 29628 |
var deltaSet_new = { group: deltaSet_old.group, deltas: new Array(deltaSet_old.length)}; |
| 29629 |
|
| 29630 |
for (var j = 0; j < deltaSet_old.deltas.length; j++) { |
| 29631 |
var delta_old = deltaSet_old.deltas[j]; |
| 29632 |
deltaSet_new.deltas[j] = fnGetModifiedDelta(delta_old); |
| 29633 |
} |
| 29634 |
|
| 29635 |
deltaSets_new[i] = deltaSet_new; |
| 29636 |
} |
| 29637 |
return deltaSets_new; |
| 29638 |
} |
| 29639 |
|
| 29640 |
}).call(UndoManager.prototype); |
| 29641 |
|
| 29642 |
exports.UndoManager = UndoManager; |
| 29643 |
}); |
| 29644 |
|
| 29645 |
ace.define("ace/layer/gutter",["require","exports","module","ace/lib/dom","ace/lib/oop","ace/lib/lang","ace/lib/event_emitter"], function(acequire, exports, module) { |
| 29646 |
"use strict"; |
| 29647 |
|
| 29648 |
var dom = acequire("../lib/dom"); |
| 29649 |
var oop = acequire("../lib/oop"); |
| 29650 |
var lang = acequire("../lib/lang"); |
| 29651 |
var EventEmitter = acequire("../lib/event_emitter").EventEmitter; |
| 29652 |
|
| 29653 |
var Gutter = function(parentEl) { |
| 29654 |
this.element = dom.createElement("div"); |
| 29655 |
this.element.className = "ace_layer ace_gutter-layer"; |
| 29656 |
parentEl.appendChild(this.element); |
| 29657 |
this.setShowFoldWidgets(this.$showFoldWidgets); |
| 29658 |
|
| 29659 |
this.gutterWidth = 0; |
| 29660 |
|
| 29661 |
this.$annotations = []; |
| 29662 |
this.$updateAnnotations = this.$updateAnnotations.bind(this); |
| 29663 |
|
| 29664 |
this.$cells = []; |
| 29665 |
}; |
| 29666 |
|
| 29667 |
(function() { |
| 29668 |
|
| 29669 |
oop.implement(this, EventEmitter); |
| 29670 |
|
| 29671 |
this.setSession = function(session) { |
| 29672 |
if (this.session) |
| 29673 |
this.session.removeEventListener("change", this.$updateAnnotations); |
| 29674 |
this.session = session; |
| 29675 |
if (session) |
| 29676 |
session.on("change", this.$updateAnnotations); |
| 29677 |
}; |
| 29678 |
|
| 29679 |
this.addGutterDecoration = function(row, className){ |
| 29680 |
if (window.console) |
| 29681 |
console.warn && console.warn("deprecated use session.addGutterDecoration"); |
| 29682 |
this.session.addGutterDecoration(row, className); |
| 29683 |
}; |
| 29684 |
|
| 29685 |
this.removeGutterDecoration = function(row, className){ |
| 29686 |
if (window.console) |
| 29687 |
console.warn && console.warn("deprecated use session.removeGutterDecoration"); |
| 29688 |
this.session.removeGutterDecoration(row, className); |
| 29689 |
}; |
| 29690 |
|
| 29691 |
this.setAnnotations = function(annotations) { |
| 29692 |
this.$annotations = []; |
| 29693 |
for (var i = 0; i < annotations.length; i++) { |
| 29694 |
var annotation = annotations[i]; |
| 29695 |
var row = annotation.row; |
| 29696 |
var rowInfo = this.$annotations[row]; |
| 29697 |
if (!rowInfo) |
| 29698 |
rowInfo = this.$annotations[row] = {text: []}; |
| 29699 |
|
| 29700 |
var annoText = annotation.text; |
| 29701 |
annoText = annoText ? lang.escapeHTML(annoText) : annotation.html || ""; |
| 29702 |
|
| 29703 |
if (rowInfo.text.indexOf(annoText) === -1) |
| 29704 |
rowInfo.text.push(annoText); |
| 29705 |
|
| 29706 |
var type = annotation.type; |
| 29707 |
if (type == "error") |
| 29708 |
rowInfo.className = " ace_error"; |
| 29709 |
else if (type == "warning" && rowInfo.className != " ace_error") |
| 29710 |
rowInfo.className = " ace_warning"; |
| 29711 |
else if (type == "info" && (!rowInfo.className)) |
| 29712 |
rowInfo.className = " ace_info"; |
| 29713 |
} |
| 29714 |
}; |
| 29715 |
|
| 29716 |
this.$updateAnnotations = function (delta) { |
| 29717 |
if (!this.$annotations.length) |
| 29718 |
return; |
| 29719 |
var firstRow = delta.start.row; |
| 29720 |
var len = delta.end.row - firstRow; |
| 29721 |
if (len === 0) { |
| 29722 |
} else if (delta.action == 'remove') { |
| 29723 |
this.$annotations.splice(firstRow, len + 1, null); |
| 29724 |
} else { |
| 29725 |
var args = new Array(len + 1); |
| 29726 |
args.unshift(firstRow, 1); |
| 29727 |
this.$annotations.splice.apply(this.$annotations, args); |
| 29728 |
} |
| 29729 |
}; |
| 29730 |
|
| 29731 |
this.update = function(config) { |
| 29732 |
var session = this.session; |
| 29733 |
var firstRow = config.firstRow; |
| 29734 |
var lastRow = Math.min(config.lastRow + config.gutterOffset, // needed to compensate for hor scollbar |
| 29735 |
session.getLength() - 1); |
| 29736 |
var fold = session.getNextFoldLine(firstRow); |
| 29737 |
var foldStart = fold ? fold.start.row : Infinity; |
| 29738 |
var foldWidgets = this.$showFoldWidgets && session.foldWidgets; |
| 29739 |
var breakpoints = session.$breakpoints; |
| 29740 |
var decorations = session.$decorations; |
| 29741 |
var firstLineNumber = session.$firstLineNumber; |
| 29742 |
var lastLineNumber = 0; |
| 29743 |
|
| 29744 |
var gutterRenderer = session.gutterRenderer || this.$renderer; |
| 29745 |
|
| 29746 |
var cell = null; |
| 29747 |
var index = -1; |
| 29748 |
var row = firstRow; |
| 29749 |
while (true) { |
| 29750 |
if (row > foldStart) { |
| 29751 |
row = fold.end.row + 1; |
| 29752 |
fold = session.getNextFoldLine(row, fold); |
| 29753 |
foldStart = fold ? fold.start.row : Infinity; |
| 29754 |
} |
| 29755 |
if (row > lastRow) { |
| 29756 |
while (this.$cells.length > index + 1) { |
| 29757 |
cell = this.$cells.pop(); |
| 29758 |
this.element.removeChild(cell.element); |
| 29759 |
} |
| 29760 |
break; |
| 29761 |
} |
| 29762 |
|
| 29763 |
cell = this.$cells[++index]; |
| 29764 |
if (!cell) { |
| 29765 |
cell = {element: null, textNode: null, foldWidget: null}; |
| 29766 |
cell.element = dom.createElement("div"); |
| 29767 |
cell.textNode = document.createTextNode(''); |
| 29768 |
cell.element.appendChild(cell.textNode); |
| 29769 |
this.element.appendChild(cell.element); |
| 29770 |
this.$cells[index] = cell; |
| 29771 |
} |
| 29772 |
|
| 29773 |
var className = "ace_gutter-cell "; |
| 29774 |
if (breakpoints[row]) |
| 29775 |
className += breakpoints[row]; |
| 29776 |
if (decorations[row]) |
| 29777 |
className += decorations[row]; |
| 29778 |
if (this.$annotations[row]) |
| 29779 |
className += this.$annotations[row].className; |
| 29780 |
if (cell.element.className != className) |
| 29781 |
cell.element.className = className; |
| 29782 |
|
| 29783 |
var height = session.getRowLength(row) * config.lineHeight + "px"; |
| 29784 |
if (height != cell.element.style.height) |
| 29785 |
cell.element.style.height = height; |
| 29786 |
|
| 29787 |
if (foldWidgets) { |
| 29788 |
var c = foldWidgets[row]; |
| 29789 |
if (c == null) |
| 29790 |
c = foldWidgets[row] = session.getFoldWidget(row); |
| 29791 |
} |
| 29792 |
|
| 29793 |
if (c) { |
| 29794 |
if (!cell.foldWidget) { |
| 29795 |
cell.foldWidget = dom.createElement("span"); |
| 29796 |
cell.element.appendChild(cell.foldWidget); |
| 29797 |
} |
| 29798 |
var className = "ace_fold-widget ace_" + c; |
| 29799 |
if (c == "start" && row == foldStart && row < fold.end.row) |
| 29800 |
className += " ace_closed"; |
| 29801 |
else |
| 29802 |
className += " ace_open"; |
| 29803 |
if (cell.foldWidget.className != className) |
| 29804 |
cell.foldWidget.className = className; |
| 29805 |
|
| 29806 |
var height = config.lineHeight + "px"; |
| 29807 |
if (cell.foldWidget.style.height != height) |
| 29808 |
cell.foldWidget.style.height = height; |
| 29809 |
} else { |
| 29810 |
if (cell.foldWidget) { |
| 29811 |
cell.element.removeChild(cell.foldWidget); |
| 29812 |
cell.foldWidget = null; |
| 29813 |
} |
| 29814 |
} |
| 29815 |
|
| 29816 |
var text = lastLineNumber = gutterRenderer |
| 29817 |
? gutterRenderer.getText(session, row) |
| 29818 |
: row + firstLineNumber; |
| 29819 |
if (text != cell.textNode.data) |
| 29820 |
cell.textNode.data = text; |
| 29821 |
|
| 29822 |
row++; |
| 29823 |
} |
| 29824 |
|
| 29825 |
this.element.style.height = config.minHeight + "px"; |
| 29826 |
|
| 29827 |
if (this.$fixedWidth || session.$useWrapMode) |
| 29828 |
lastLineNumber = session.getLength() + firstLineNumber; |
| 29829 |
|
| 29830 |
var gutterWidth = gutterRenderer |
| 29831 |
? gutterRenderer.getWidth(session, lastLineNumber, config) |
| 29832 |
: lastLineNumber.toString().length * config.characterWidth; |
| 29833 |
|
| 29834 |
var padding = this.$padding || this.$computePadding(); |
| 29835 |
gutterWidth += padding.left + padding.right; |
| 29836 |
if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) { |
| 29837 |
this.gutterWidth = gutterWidth; |
| 29838 |
this.element.style.width = Math.ceil(this.gutterWidth) + "px"; |
| 29839 |
this._emit("changeGutterWidth", gutterWidth); |
| 29840 |
} |
| 29841 |
}; |
| 29842 |
|
| 29843 |
this.$fixedWidth = false; |
| 29844 |
|
| 29845 |
this.$showLineNumbers = true; |
| 29846 |
this.$renderer = ""; |
| 29847 |
this.setShowLineNumbers = function(show) { |
| 29848 |
this.$renderer = !show && { |
| 29849 |
getWidth: function() {return ""}, |
| 29850 |
getText: function() {return ""} |
| 29851 |
}; |
| 29852 |
}; |
| 29853 |
|
| 29854 |
this.getShowLineNumbers = function() { |
| 29855 |
return this.$showLineNumbers; |
| 29856 |
}; |
| 29857 |
|
| 29858 |
this.$showFoldWidgets = true; |
| 29859 |
this.setShowFoldWidgets = function(show) { |
| 29860 |
if (show) |
| 29861 |
dom.addCssClass(this.element, "ace_folding-enabled"); |
| 29862 |
else |
| 29863 |
dom.removeCssClass(this.element, "ace_folding-enabled"); |
| 29864 |
|
| 29865 |
this.$showFoldWidgets = show; |
| 29866 |
this.$padding = null; |
| 29867 |
}; |
| 29868 |
|
| 29869 |
this.getShowFoldWidgets = function() { |
| 29870 |
return this.$showFoldWidgets; |
| 29871 |
}; |
| 29872 |
|
| 29873 |
this.$computePadding = function() { |
| 29874 |
if (!this.element.firstChild) |
| 29875 |
return {left: 0, right: 0}; |
| 29876 |
var style = dom.computedStyle(this.element.firstChild); |
| 29877 |
this.$padding = {}; |
| 29878 |
this.$padding.left = parseInt(style.paddingLeft) + 1 || 0; |
| 29879 |
this.$padding.right = parseInt(style.paddingRight) || 0; |
| 29880 |
return this.$padding; |
| 29881 |
}; |
| 29882 |
|
| 29883 |
this.getRegion = function(point) { |
| 29884 |
var padding = this.$padding || this.$computePadding(); |
| 29885 |
var rect = this.element.getBoundingClientRect(); |
| 29886 |
if (point.x < padding.left + rect.left) |
| 29887 |
return "markers"; |
| 29888 |
if (this.$showFoldWidgets && point.x > rect.right - padding.right) |
| 29889 |
return "foldWidgets"; |
| 29890 |
}; |
| 29891 |
|
| 29892 |
}).call(Gutter.prototype); |
| 29893 |
|
| 29894 |
exports.Gutter = Gutter; |
| 29895 |
|
| 29896 |
}); |
| 29897 |
|
| 29898 |
ace.define("ace/layer/marker",["require","exports","module","ace/range","ace/lib/dom"], function(acequire, exports, module) { |
| 29899 |
"use strict"; |
| 29900 |
|
| 29901 |
var Range = acequire("../range").Range; |
| 29902 |
var dom = acequire("../lib/dom"); |
| 29903 |
|
| 29904 |
var Marker = function(parentEl) { |
| 29905 |
this.element = dom.createElement("div"); |
| 29906 |
this.element.className = "ace_layer ace_marker-layer"; |
| 29907 |
parentEl.appendChild(this.element); |
| 29908 |
}; |
| 29909 |
|
| 29910 |
(function() { |
| 29911 |
|
| 29912 |
this.$padding = 0; |
| 29913 |
|
| 29914 |
this.setPadding = function(padding) { |
| 29915 |
this.$padding = padding; |
| 29916 |
}; |
| 29917 |
this.setSession = function(session) { |
| 29918 |
this.session = session; |
| 29919 |
}; |
| 29920 |
|
| 29921 |
this.setMarkers = function(markers) { |
| 29922 |
this.markers = markers; |
| 29923 |
}; |
| 29924 |
|
| 29925 |
this.update = function(config) { |
| 29926 |
var config = config || this.config; |
| 29927 |
if (!config) |
| 29928 |
return; |
| 29929 |
|
| 29930 |
this.config = config; |
| 29931 |
|
| 29932 |
|
| 29933 |
var html = []; |
| 29934 |
for (var key in this.markers) { |
| 29935 |
var marker = this.markers[key]; |
| 29936 |
|
| 29937 |
if (!marker.range) { |
| 29938 |
marker.update(html, this, this.session, config); |
| 29939 |
continue; |
| 29940 |
} |
| 29941 |
|
| 29942 |
var range = marker.range.clipRows(config.firstRow, config.lastRow); |
| 29943 |
if (range.isEmpty()) continue; |
| 29944 |
|
| 29945 |
range = range.toScreenRange(this.session); |
| 29946 |
if (marker.renderer) { |
| 29947 |
var top = this.$getTop(range.start.row, config); |
| 29948 |
var left = this.$padding + range.start.column * config.characterWidth; |
| 29949 |
marker.renderer(html, range, left, top, config); |
| 29950 |
} else if (marker.type == "fullLine") { |
| 29951 |
this.drawFullLineMarker(html, range, marker.clazz, config); |
| 29952 |
} else if (marker.type == "screenLine") { |
| 29953 |
this.drawScreenLineMarker(html, range, marker.clazz, config); |
| 29954 |
} else if (range.isMultiLine()) { |
| 29955 |
if (marker.type == "text") |
| 29956 |
this.drawTextMarker(html, range, marker.clazz, config); |
| 29957 |
else |
| 29958 |
this.drawMultiLineMarker(html, range, marker.clazz, config); |
| 29959 |
} else { |
| 29960 |
this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config); |
| 29961 |
} |
| 29962 |
} |
| 29963 |
this.element.innerHTML = html.join(""); |
| 29964 |
}; |
| 29965 |
|
| 29966 |
this.$getTop = function(row, layerConfig) { |
| 29967 |
return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight; |
| 29968 |
}; |
| 29969 |
|
| 29970 |
function getBorderClass(tl, tr, br, bl) { |
| 29971 |
return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0); |
| 29972 |
} |
| 29973 |
this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) { |
| 29974 |
var session = this.session; |
| 29975 |
var start = range.start.row; |
| 29976 |
var end = range.end.row; |
| 29977 |
var row = start; |
| 29978 |
var prev = 0; |
| 29979 |
var curr = 0; |
| 29980 |
var next = session.getScreenLastRowColumn(row); |
| 29981 |
var lineRange = new Range(row, range.start.column, row, curr); |
| 29982 |
for (; row <= end; row++) { |
| 29983 |
lineRange.start.row = lineRange.end.row = row; |
| 29984 |
lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row); |
| 29985 |
lineRange.end.column = next; |
| 29986 |
prev = curr; |
| 29987 |
curr = next; |
| 29988 |
next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column; |
| 29989 |
this.drawSingleLineMarker(stringBuilder, lineRange, |
| 29990 |
clazz + (row == start ? " ace_start" : "") + " ace_br" |
| 29991 |
+ getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end), |
| 29992 |
layerConfig, row == end ? 0 : 1, extraStyle); |
| 29993 |
} |
| 29994 |
}; |
| 29995 |
this.drawMultiLineMarker = function(stringBuilder, range, clazz, config, extraStyle) { |
| 29996 |
var padding = this.$padding; |
| 29997 |
var height = config.lineHeight; |
| 29998 |
var top = this.$getTop(range.start.row, config); |
| 29999 |
var left = padding + range.start.column * config.characterWidth; |
| 30000 |
extraStyle = extraStyle || ""; |
| 30001 |
|
| 30002 |
stringBuilder.push( |
| 30003 |
"<div class='", clazz, " ace_br1 ace_start' style='", |
| 30004 |
"height:", height, "px;", |
| 30005 |
"right:0;", |
| 30006 |
"top:", top, "px;", |
| 30007 |
"left:", left, "px;", extraStyle, "'></div>" |
| 30008 |
); |
| 30009 |
top = this.$getTop(range.end.row, config); |
| 30010 |
var width = range.end.column * config.characterWidth; |
| 30011 |
|
| 30012 |
stringBuilder.push( |
| 30013 |
"<div class='", clazz, " ace_br12' style='", |
| 30014 |
"height:", height, "px;", |
| 30015 |
"width:", width, "px;", |
| 30016 |
"top:", top, "px;", |
| 30017 |
"left:", padding, "px;", extraStyle, "'></div>" |
| 30018 |
); |
| 30019 |
height = (range.end.row - range.start.row - 1) * config.lineHeight; |
| 30020 |
if (height <= 0) |
| 30021 |
return; |
| 30022 |
top = this.$getTop(range.start.row + 1, config); |
| 30023 |
|
| 30024 |
var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8); |
| 30025 |
|
| 30026 |
stringBuilder.push( |
| 30027 |
"<div class='", clazz, (radiusClass ? " ace_br" + radiusClass : ""), "' style='", |
| 30028 |
"height:", height, "px;", |
| 30029 |
"right:0;", |
| 30030 |
"top:", top, "px;", |
| 30031 |
"left:", padding, "px;", extraStyle, "'></div>" |
| 30032 |
); |
| 30033 |
}; |
| 30034 |
this.drawSingleLineMarker = function(stringBuilder, range, clazz, config, extraLength, extraStyle) { |
| 30035 |
var height = config.lineHeight; |
| 30036 |
var width = (range.end.column + (extraLength || 0) - range.start.column) * config.characterWidth; |
| 30037 |
|
| 30038 |
var top = this.$getTop(range.start.row, config); |
| 30039 |
var left = this.$padding + range.start.column * config.characterWidth; |
| 30040 |
|
| 30041 |
stringBuilder.push( |
| 30042 |
"<div class='", clazz, "' style='", |
| 30043 |
"height:", height, "px;", |
| 30044 |
"width:", width, "px;", |
| 30045 |
"top:", top, "px;", |
| 30046 |
"left:", left, "px;", extraStyle || "", "'></div>" |
| 30047 |
); |
| 30048 |
}; |
| 30049 |
|
| 30050 |
this.drawFullLineMarker = function(stringBuilder, range, clazz, config, extraStyle) { |
| 30051 |
var top = this.$getTop(range.start.row, config); |
| 30052 |
var height = config.lineHeight; |
| 30053 |
if (range.start.row != range.end.row) |
| 30054 |
height += this.$getTop(range.end.row, config) - top; |
| 30055 |
|
| 30056 |
stringBuilder.push( |
| 30057 |
"<div class='", clazz, "' style='", |
| 30058 |
"height:", height, "px;", |
| 30059 |
"top:", top, "px;", |
| 30060 |
"left:0;right:0;", extraStyle || "", "'></div>" |
| 30061 |
); |
| 30062 |
}; |
| 30063 |
|
| 30064 |
this.drawScreenLineMarker = function(stringBuilder, range, clazz, config, extraStyle) { |
| 30065 |
var top = this.$getTop(range.start.row, config); |
| 30066 |
var height = config.lineHeight; |
| 30067 |
|
| 30068 |
stringBuilder.push( |
| 30069 |
"<div class='", clazz, "' style='", |
| 30070 |
"height:", height, "px;", |
| 30071 |
"top:", top, "px;", |
| 30072 |
"left:0;right:0;", extraStyle || "", "'></div>" |
| 30073 |
); |
| 30074 |
}; |
| 30075 |
|
| 30076 |
}).call(Marker.prototype); |
| 30077 |
|
| 30078 |
exports.Marker = Marker; |
| 30079 |
|
| 30080 |
}); |
| 30081 |
|
| 30082 |
ace.define("ace/layer/text",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/lib/event_emitter"], function(acequire, exports, module) { |
| 30083 |
"use strict"; |
| 30084 |
|
| 30085 |
var oop = acequire("../lib/oop"); |
| 30086 |
var dom = acequire("../lib/dom"); |
| 30087 |
var lang = acequire("../lib/lang"); |
| 30088 |
var useragent = acequire("../lib/useragent"); |
| 30089 |
var EventEmitter = acequire("../lib/event_emitter").EventEmitter; |
| 30090 |
|
| 30091 |
var Text = function(parentEl) { |
| 30092 |
this.element = dom.createElement("div"); |
| 30093 |
this.element.className = "ace_layer ace_text-layer"; |
| 30094 |
parentEl.appendChild(this.element); |
| 30095 |
this.$updateEolChar = this.$updateEolChar.bind(this); |
| 30096 |
}; |
| 30097 |
|
| 30098 |
(function() { |
| 30099 |
|
| 30100 |
oop.implement(this, EventEmitter); |
| 30101 |
|
| 30102 |
this.EOF_CHAR = "\xB6"; |
| 30103 |
this.EOL_CHAR_LF = "\xAC"; |
| 30104 |
this.EOL_CHAR_CRLF = "\xa4"; |
| 30105 |
this.EOL_CHAR = this.EOL_CHAR_LF; |
| 30106 |
this.TAB_CHAR = "\u2014"; //"\u21E5"; |
| 30107 |
this.SPACE_CHAR = "\xB7"; |
| 30108 |
this.$padding = 0; |
| 30109 |
|
| 30110 |
this.$updateEolChar = function() { |
| 30111 |
var EOL_CHAR = this.session.doc.getNewLineCharacter() == "\n" |
| 30112 |
? this.EOL_CHAR_LF |
| 30113 |
: this.EOL_CHAR_CRLF; |
| 30114 |
if (this.EOL_CHAR != EOL_CHAR) { |
| 30115 |
this.EOL_CHAR = EOL_CHAR; |
| 30116 |
return true; |
| 30117 |
} |
| 30118 |
} |
| 30119 |
|
| 30120 |
this.setPadding = function(padding) { |
| 30121 |
this.$padding = padding; |
| 30122 |
this.element.style.padding = "0 " + padding + "px"; |
| 30123 |
}; |
| 30124 |
|
| 30125 |
this.getLineHeight = function() { |
| 30126 |
return this.$fontMetrics.$characterSize.height || 0; |
| 30127 |
}; |
| 30128 |
|
| 30129 |
this.getCharacterWidth = function() { |
| 30130 |
return this.$fontMetrics.$characterSize.width || 0; |
| 30131 |
}; |
| 30132 |
|
| 30133 |
this.$setFontMetrics = function(measure) { |
| 30134 |
this.$fontMetrics = measure; |
| 30135 |
this.$fontMetrics.on("changeCharacterSize", function(e) { |
| 30136 |
this._signal("changeCharacterSize", e); |
| 30137 |
}.bind(this)); |
| 30138 |
this.$pollSizeChanges(); |
| 30139 |
} |
| 30140 |
|
| 30141 |
this.checkForSizeChanges = function() { |
| 30142 |
this.$fontMetrics.checkForSizeChanges(); |
| 30143 |
}; |
| 30144 |
this.$pollSizeChanges = function() { |
| 30145 |
return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges(); |
| 30146 |
}; |
| 30147 |
this.setSession = function(session) { |
| 30148 |
this.session = session; |
| 30149 |
if (session) |
| 30150 |
this.$computeTabString(); |
| 30151 |
}; |
| 30152 |
|
| 30153 |
this.showInvisibles = false; |
| 30154 |
this.setShowInvisibles = function(showInvisibles) { |
| 30155 |
if (this.showInvisibles == showInvisibles) |
| 30156 |
return false; |
| 30157 |
|
| 30158 |
this.showInvisibles = showInvisibles; |
| 30159 |
this.$computeTabString(); |
| 30160 |
return true; |
| 30161 |
}; |
| 30162 |
|
| 30163 |
this.displayIndentGuides = true; |
| 30164 |
this.setDisplayIndentGuides = function(display) { |
| 30165 |
if (this.displayIndentGuides == display) |
| 30166 |
return false; |
| 30167 |
|
| 30168 |
this.displayIndentGuides = display; |
| 30169 |
this.$computeTabString(); |
| 30170 |
return true; |
| 30171 |
}; |
| 30172 |
|
| 30173 |
this.$tabStrings = []; |
| 30174 |
this.onChangeTabSize = |
| 30175 |
this.$computeTabString = function() { |
| 30176 |
var tabSize = this.session.getTabSize(); |
| 30177 |
this.tabSize = tabSize; |
| 30178 |
var tabStr = this.$tabStrings = [0]; |
| 30179 |
for (var i = 1; i < tabSize + 1; i++) { |
| 30180 |
if (this.showInvisibles) { |
| 30181 |
tabStr.push("<span class='ace_invisible ace_invisible_tab'>" |
| 30182 |
+ lang.stringRepeat(this.TAB_CHAR, i) |
| 30183 |
+ "</span>"); |
| 30184 |
} else { |
| 30185 |
tabStr.push(lang.stringRepeat(" ", i)); |
| 30186 |
} |
| 30187 |
} |
| 30188 |
if (this.displayIndentGuides) { |
| 30189 |
this.$indentGuideRe = /\s\S| \t|\t |\s$/; |
| 30190 |
var className = "ace_indent-guide"; |
| 30191 |
var spaceClass = ""; |
| 30192 |
var tabClass = ""; |
| 30193 |
if (this.showInvisibles) { |
| 30194 |
className += " ace_invisible"; |
| 30195 |
spaceClass = " ace_invisible_space"; |
| 30196 |
tabClass = " ace_invisible_tab"; |
| 30197 |
var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize); |
| 30198 |
var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize); |
| 30199 |
} else{ |
| 30200 |
var spaceContent = lang.stringRepeat(" ", this.tabSize); |
| 30201 |
var tabContent = spaceContent; |
| 30202 |
} |
| 30203 |
|
| 30204 |
this.$tabStrings[" "] = "<span class='" + className + spaceClass + "'>" + spaceContent + "</span>"; |
| 30205 |
this.$tabStrings["\t"] = "<span class='" + className + tabClass + "'>" + tabContent + "</span>"; |
| 30206 |
} |
| 30207 |
}; |
| 30208 |
|
| 30209 |
this.updateLines = function(config, firstRow, lastRow) { |
| 30210 |
if (this.config.lastRow != config.lastRow || |
| 30211 |
this.config.firstRow != config.firstRow) { |
| 30212 |
this.scrollLines(config); |
| 30213 |
} |
| 30214 |
this.config = config; |
| 30215 |
|
| 30216 |
var first = Math.max(firstRow, config.firstRow); |
| 30217 |
var last = Math.min(lastRow, config.lastRow); |
| 30218 |
|
| 30219 |
var lineElements = this.element.childNodes; |
| 30220 |
var lineElementsIdx = 0; |
| 30221 |
|
| 30222 |
for (var row = config.firstRow; row < first; row++) { |
| 30223 |
var foldLine = this.session.getFoldLine(row); |
| 30224 |
if (foldLine) { |
| 30225 |
if (foldLine.containsRow(first)) { |
| 30226 |
first = foldLine.start.row; |
| 30227 |
break; |
| 30228 |
} else { |
| 30229 |
row = foldLine.end.row; |
| 30230 |
} |
| 30231 |
} |
| 30232 |
lineElementsIdx ++; |
| 30233 |
} |
| 30234 |
|
| 30235 |
var row = first; |
| 30236 |
var foldLine = this.session.getNextFoldLine(row); |
| 30237 |
var foldStart = foldLine ? foldLine.start.row : Infinity; |
| 30238 |
|
| 30239 |
while (true) { |
| 30240 |
if (row > foldStart) { |
| 30241 |
row = foldLine.end.row+1; |
| 30242 |
foldLine = this.session.getNextFoldLine(row, foldLine); |
| 30243 |
foldStart = foldLine ? foldLine.start.row :Infinity; |
| 30244 |
} |
| 30245 |
if (row > last) |
| 30246 |
break; |
| 30247 |
|
| 30248 |
var lineElement = lineElements[lineElementsIdx++]; |
| 30249 |
if (lineElement) { |
| 30250 |
var html = []; |
| 30251 |
this.$renderLine( |
| 30252 |
html, row, !this.$useLineGroups(), row == foldStart ? foldLine : false |
| 30253 |
); |
| 30254 |
lineElement.style.height = config.lineHeight * this.session.getRowLength(row) + "px"; |
| 30255 |
lineElement.innerHTML = html.join(""); |
| 30256 |
} |
| 30257 |
row++; |
| 30258 |
} |
| 30259 |
}; |
| 30260 |
|
| 30261 |
this.scrollLines = function(config) { |
| 30262 |
var oldConfig = this.config; |
| 30263 |
this.config = config; |
| 30264 |
|
| 30265 |
if (!oldConfig || oldConfig.lastRow < config.firstRow) |
| 30266 |
return this.update(config); |
| 30267 |
|
| 30268 |
if (config.lastRow < oldConfig.firstRow) |
| 30269 |
return this.update(config); |
| 30270 |
|
| 30271 |
var el = this.element; |
| 30272 |
if (oldConfig.firstRow < config.firstRow) |
| 30273 |
for (var row=this.session.getFoldedRowCount(oldConfig.firstRow, config.firstRow - 1); row>0; row--) |
| 30274 |
el.removeChild(el.firstChild); |
| 30275 |
|
| 30276 |
if (oldConfig.lastRow > config.lastRow) |
| 30277 |
for (var row=this.session.getFoldedRowCount(config.lastRow + 1, oldConfig.lastRow); row>0; row--) |
| 30278 |
el.removeChild(el.lastChild); |
| 30279 |
|
| 30280 |
if (config.firstRow < oldConfig.firstRow) { |
| 30281 |
var fragment = this.$renderLinesFragment(config, config.firstRow, oldConfig.firstRow - 1); |
| 30282 |
if (el.firstChild) |
| 30283 |
el.insertBefore(fragment, el.firstChild); |
| 30284 |
else |
| 30285 |
el.appendChild(fragment); |
| 30286 |
} |
| 30287 |
|
| 30288 |
if (config.lastRow > oldConfig.lastRow) { |
| 30289 |
var fragment = this.$renderLinesFragment(config, oldConfig.lastRow + 1, config.lastRow); |
| 30290 |
el.appendChild(fragment); |
| 30291 |
} |
| 30292 |
}; |
| 30293 |
|
| 30294 |
this.$renderLinesFragment = function(config, firstRow, lastRow) { |
| 30295 |
var fragment = this.element.ownerDocument.createDocumentFragment(); |
| 30296 |
var row = firstRow; |
| 30297 |
var foldLine = this.session.getNextFoldLine(row); |
| 30298 |
var foldStart = foldLine ? foldLine.start.row : Infinity; |
| 30299 |
|
| 30300 |
while (true) { |
| 30301 |
if (row > foldStart) { |
| 30302 |
row = foldLine.end.row+1; |
| 30303 |
foldLine = this.session.getNextFoldLine(row, foldLine); |
| 30304 |
foldStart = foldLine ? foldLine.start.row : Infinity; |
| 30305 |
} |
| 30306 |
if (row > lastRow) |
| 30307 |
break; |
| 30308 |
|
| 30309 |
var container = dom.createElement("div"); |
| 30310 |
|
| 30311 |
var html = []; |
| 30312 |
this.$renderLine(html, row, false, row == foldStart ? foldLine : false); |
| 30313 |
container.innerHTML = html.join(""); |
| 30314 |
if (this.$useLineGroups()) { |
| 30315 |
container.className = 'ace_line_group'; |
| 30316 |
fragment.appendChild(container); |
| 30317 |
container.style.height = config.lineHeight * this.session.getRowLength(row) + "px"; |
| 30318 |
|
| 30319 |
} else { |
| 30320 |
while(container.firstChild) |
| 30321 |
fragment.appendChild(container.firstChild); |
| 30322 |
} |
| 30323 |
|
| 30324 |
row++; |
| 30325 |
} |
| 30326 |
return fragment; |
| 30327 |
}; |
| 30328 |
|
| 30329 |
this.update = function(config) { |
| 30330 |
this.config = config; |
| 30331 |
|
| 30332 |
var html = []; |
| 30333 |
var firstRow = config.firstRow, lastRow = config.lastRow; |
| 30334 |
|
| 30335 |
var row = firstRow; |
| 30336 |
var foldLine = this.session.getNextFoldLine(row); |
| 30337 |
var foldStart = foldLine ? foldLine.start.row : Infinity; |
| 30338 |
|
| 30339 |
while (true) { |
| 30340 |
if (row > foldStart) { |
| 30341 |
row = foldLine.end.row+1; |
| 30342 |
foldLine = this.session.getNextFoldLine(row, foldLine); |
| 30343 |
foldStart = foldLine ? foldLine.start.row :Infinity; |
| 30344 |
} |
| 30345 |
if (row > lastRow) |
| 30346 |
break; |
| 30347 |
|
| 30348 |
if (this.$useLineGroups()) |
| 30349 |
html.push("<div class='ace_line_group' style='height:", config.lineHeight*this.session.getRowLength(row), "px'>") |
| 30350 |
|
| 30351 |
this.$renderLine(html, row, false, row == foldStart ? foldLine : false); |
| 30352 |
|
| 30353 |
if (this.$useLineGroups()) |
| 30354 |
html.push("</div>"); // end the line group |
| 30355 |
|
| 30356 |
row++; |
| 30357 |
} |
| 30358 |
this.element.innerHTML = html.join(""); |
| 30359 |
}; |
| 30360 |
|
| 30361 |
this.$textToken = { |
| 30362 |
"text": true, |
| 30363 |
"rparen": true, |
| 30364 |
"lparen": true |
| 30365 |
}; |
| 30366 |
|
| 30367 |
this.$renderToken = function(stringBuilder, screenColumn, token, value) { |
| 30368 |
var self = this; |
| 30369 |
var replaceReg = /\t|&|<|>|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\u3000\uFEFF\uFFF9-\uFFFC])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g; |
| 30370 |
var replaceFunc = function(c, a, b, tabIdx, idx4) { |
| 30371 |
if (a) { |
| 30372 |
return self.showInvisibles |
| 30373 |
? "<span class='ace_invisible ace_invisible_space'>" + lang.stringRepeat(self.SPACE_CHAR, c.length) + "</span>" |
| 30374 |
: c; |
| 30375 |
} else if (c == "&") { |
| 30376 |
return "&"; |
| 30377 |
} else if (c == "<") { |
| 30378 |
return "<"; |
| 30379 |
} else if (c == ">") { |
| 30380 |
return ">"; |
| 30381 |
} else if (c == "\t") { |
| 30382 |
var tabSize = self.session.getScreenTabSize(screenColumn + tabIdx); |
| 30383 |
screenColumn += tabSize - 1; |
| 30384 |
return self.$tabStrings[tabSize]; |
| 30385 |
} else if (c == "\u3000") { |
| 30386 |
var classToUse = self.showInvisibles ? "ace_cjk ace_invisible ace_invisible_space" : "ace_cjk"; |
| 30387 |
var space = self.showInvisibles ? self.SPACE_CHAR : ""; |
| 30388 |
screenColumn += 1; |
| 30389 |
return "<span class='" + classToUse + "' style='width:" + |
| 30390 |
(self.config.characterWidth * 2) + |
| 30391 |
"px'>" + space + "</span>"; |
| 30392 |
} else if (b) { |
| 30393 |
return "<span class='ace_invisible ace_invisible_space ace_invalid'>" + self.SPACE_CHAR + "</span>"; |
| 30394 |
} else { |
| 30395 |
screenColumn += 1; |
| 30396 |
return "<span class='ace_cjk' style='width:" + |
| 30397 |
(self.config.characterWidth * 2) + |
| 30398 |
"px'>" + c + "</span>"; |
| 30399 |
} |
| 30400 |
}; |
| 30401 |
|
| 30402 |
var output = value.replace(replaceReg, replaceFunc); |
| 30403 |
|
| 30404 |
if (!this.$textToken[token.type]) { |
| 30405 |
var classes = "ace_" + token.type.replace(/\./g, " ace_"); |
| 30406 |
var style = ""; |
| 30407 |
if (token.type == "fold") |
| 30408 |
style = " style='width:" + (token.value.length * this.config.characterWidth) + "px;' "; |
| 30409 |
stringBuilder.push("<span class='", classes, "'", style, ">", output, "</span>"); |
| 30410 |
} |
| 30411 |
else { |
| 30412 |
stringBuilder.push(output); |
| 30413 |
} |
| 30414 |
return screenColumn + value.length; |
| 30415 |
}; |
| 30416 |
|
| 30417 |
this.renderIndentGuide = function(stringBuilder, value, max) { |
| 30418 |
var cols = value.search(this.$indentGuideRe); |
| 30419 |
if (cols <= 0 || cols >= max) |
| 30420 |
return value; |
| 30421 |
if (value[0] == " ") { |
| 30422 |
cols -= cols % this.tabSize; |
| 30423 |
stringBuilder.push(lang.stringRepeat(this.$tabStrings[" "], cols/this.tabSize)); |
| 30424 |
return value.substr(cols); |
| 30425 |
} else if (value[0] == "\t") { |
| 30426 |
stringBuilder.push(lang.stringRepeat(this.$tabStrings["\t"], cols)); |
| 30427 |
return value.substr(cols); |
| 30428 |
} |
| 30429 |
return value; |
| 30430 |
}; |
| 30431 |
|
| 30432 |
this.$renderWrappedLine = function(stringBuilder, tokens, splits, onlyContents) { |
| 30433 |
var chars = 0; |
| 30434 |
var split = 0; |
| 30435 |
var splitChars = splits[0]; |
| 30436 |
var screenColumn = 0; |
| 30437 |
|
| 30438 |
for (var i = 0; i < tokens.length; i++) { |
| 30439 |
var token = tokens[i]; |
| 30440 |
var value = token.value; |
| 30441 |
if (i == 0 && this.displayIndentGuides) { |
| 30442 |
chars = value.length; |
| 30443 |
value = this.renderIndentGuide(stringBuilder, value, splitChars); |
| 30444 |
if (!value) |
| 30445 |
continue; |
| 30446 |
chars -= value.length; |
| 30447 |
} |
| 30448 |
|
| 30449 |
if (chars + value.length < splitChars) { |
| 30450 |
screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value); |
| 30451 |
chars += value.length; |
| 30452 |
} else { |
| 30453 |
while (chars + value.length >= splitChars) { |
| 30454 |
screenColumn = this.$renderToken( |
| 30455 |
stringBuilder, screenColumn, |
| 30456 |
token, value.substring(0, splitChars - chars) |
| 30457 |
); |
| 30458 |
value = value.substring(splitChars - chars); |
| 30459 |
chars = splitChars; |
| 30460 |
|
| 30461 |
if (!onlyContents) { |
| 30462 |
stringBuilder.push("</div>", |
| 30463 |
"<div class='ace_line' style='height:", |
| 30464 |
this.config.lineHeight, "px'>" |
| 30465 |
); |
| 30466 |
} |
| 30467 |
|
| 30468 |
stringBuilder.push(lang.stringRepeat("\xa0", splits.indent)); |
| 30469 |
|
| 30470 |
split ++; |
| 30471 |
screenColumn = 0; |
| 30472 |
splitChars = splits[split] || Number.MAX_VALUE; |
| 30473 |
} |
| 30474 |
if (value.length != 0) { |
| 30475 |
chars += value.length; |
| 30476 |
screenColumn = this.$renderToken( |
| 30477 |
stringBuilder, screenColumn, token, value |
| 30478 |
); |
| 30479 |
} |
| 30480 |
} |
| 30481 |
} |
| 30482 |
}; |
| 30483 |
|
| 30484 |
this.$renderSimpleLine = function(stringBuilder, tokens) { |
| 30485 |
var screenColumn = 0; |
| 30486 |
var token = tokens[0]; |
| 30487 |
var value = token.value; |
| 30488 |
if (this.displayIndentGuides) |
| 30489 |
value = this.renderIndentGuide(stringBuilder, value); |
| 30490 |
if (value) |
| 30491 |
screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value); |
| 30492 |
for (var i = 1; i < tokens.length; i++) { |
| 30493 |
token = tokens[i]; |
| 30494 |
value = token.value; |
| 30495 |
screenColumn = this.$renderToken(stringBuilder, screenColumn, token, value); |
| 30496 |
} |
| 30497 |
}; |
| 30498 |
this.$renderLine = function(stringBuilder, row, onlyContents, foldLine) { |
| 30499 |
if (!foldLine && foldLine != false) |
| 30500 |
foldLine = this.session.getFoldLine(row); |
| 30501 |
|
| 30502 |
if (foldLine) |
| 30503 |
var tokens = this.$getFoldLineTokens(row, foldLine); |
| 30504 |
else |
| 30505 |
var tokens = this.session.getTokens(row); |
| 30506 |
|
| 30507 |
|
| 30508 |
if (!onlyContents) { |
| 30509 |
stringBuilder.push( |
| 30510 |
"<div class='ace_line' style='height:", |
| 30511 |
this.config.lineHeight * ( |
| 30512 |
this.$useLineGroups() ? 1 :this.session.getRowLength(row) |
| 30513 |
), "px'>" |
| 30514 |
); |
| 30515 |
} |
| 30516 |
|
| 30517 |
if (tokens.length) { |
| 30518 |
var splits = this.session.getRowSplitData(row); |
| 30519 |
if (splits && splits.length) |
| 30520 |
this.$renderWrappedLine(stringBuilder, tokens, splits, onlyContents); |
| 30521 |
else |
| 30522 |
this.$renderSimpleLine(stringBuilder, tokens); |
| 30523 |
} |
| 30524 |
|
| 30525 |
if (this.showInvisibles) { |
| 30526 |
if (foldLine) |
| 30527 |
row = foldLine.end.row |
| 30528 |
|
| 30529 |
stringBuilder.push( |
| 30530 |
"<span class='ace_invisible ace_invisible_eol'>", |
| 30531 |
row == this.session.getLength() - 1 ? this.EOF_CHAR : this.EOL_CHAR, |
| 30532 |
"</span>" |
| 30533 |
); |
| 30534 |
} |
| 30535 |
if (!onlyContents) |
| 30536 |
stringBuilder.push("</div>"); |
| 30537 |
}; |
| 30538 |
|
| 30539 |
this.$getFoldLineTokens = function(row, foldLine) { |
| 30540 |
var session = this.session; |
| 30541 |
var renderTokens = []; |
| 30542 |
|
| 30543 |
function addTokens(tokens, from, to) { |
| 30544 |
var idx = 0, col = 0; |
| 30545 |
while ((col + tokens[idx].value.length) < from) { |
| 30546 |
col += tokens[idx].value.length; |
| 30547 |
idx++; |
| 30548 |
|
| 30549 |
if (idx == tokens.length) |
| 30550 |
return; |
| 30551 |
} |
| 30552 |
if (col != from) { |
| 30553 |
var value = tokens[idx].value.substring(from - col); |
| 30554 |
if (value.length > (to - from)) |
| 30555 |
value = value.substring(0, to - from); |
| 30556 |
|
| 30557 |
renderTokens.push({ |
| 30558 |
type: tokens[idx].type, |
| 30559 |
value: value |
| 30560 |
}); |
| 30561 |
|
| 30562 |
col = from + value.length; |
| 30563 |
idx += 1; |
| 30564 |
} |
| 30565 |
|
| 30566 |
while (col < to && idx < tokens.length) { |
| 30567 |
var value = tokens[idx].value; |
| 30568 |
if (value.length + col > to) { |
| 30569 |
renderTokens.push({ |
| 30570 |
type: tokens[idx].type, |
| 30571 |
value: value.substring(0, to - col) |
| 30572 |
}); |
| 30573 |
} else |
| 30574 |
renderTokens.push(tokens[idx]); |
| 30575 |
col += value.length; |
| 30576 |
idx += 1; |
| 30577 |
} |
| 30578 |
} |
| 30579 |
|
| 30580 |
var tokens = session.getTokens(row); |
| 30581 |
foldLine.walk(function(placeholder, row, column, lastColumn, isNewRow) { |
| 30582 |
if (placeholder != null) { |
| 30583 |
renderTokens.push({ |
| 30584 |
type: "fold", |
| 30585 |
value: placeholder |
| 30586 |
}); |
| 30587 |
} else { |
| 30588 |
if (isNewRow) |
| 30589 |
tokens = session.getTokens(row); |
| 30590 |
|
| 30591 |
if (tokens.length) |
| 30592 |
addTokens(tokens, lastColumn, column); |
| 30593 |
} |
| 30594 |
}, foldLine.end.row, this.session.getLine(foldLine.end.row).length); |
| 30595 |
|
| 30596 |
return renderTokens; |
| 30597 |
}; |
| 30598 |
|
| 30599 |
this.$useLineGroups = function() { |
| 30600 |
return this.session.getUseWrapMode(); |
| 30601 |
}; |
| 30602 |
|
| 30603 |
this.destroy = function() { |
| 30604 |
clearInterval(this.$pollSizeChangesTimer); |
| 30605 |
if (this.$measureNode) |
| 30606 |
this.$measureNode.parentNode.removeChild(this.$measureNode); |
| 30607 |
delete this.$measureNode; |
| 30608 |
}; |
| 30609 |
|
| 30610 |
}).call(Text.prototype); |
| 30611 |
|
| 30612 |
exports.Text = Text; |
| 30613 |
|
| 30614 |
}); |
| 30615 |
|
| 30616 |
ace.define("ace/layer/cursor",["require","exports","module","ace/lib/dom"], function(acequire, exports, module) { |
| 30617 |
"use strict"; |
| 30618 |
|
| 30619 |
var dom = acequire("../lib/dom"); |
| 30620 |
var isIE8; |
| 30621 |
|
| 30622 |
var Cursor = function(parentEl) { |
| 30623 |
this.element = dom.createElement("div"); |
| 30624 |
this.element.className = "ace_layer ace_cursor-layer"; |
| 30625 |
parentEl.appendChild(this.element); |
| 30626 |
|
| 30627 |
if (isIE8 === undefined) |
| 30628 |
isIE8 = !("opacity" in this.element.style); |
| 30629 |
|
| 30630 |
this.isVisible = false; |
| 30631 |
this.isBlinking = true; |
| 30632 |
this.blinkInterval = 1000; |
| 30633 |
this.smoothBlinking = false; |
| 30634 |
|
| 30635 |
this.cursors = []; |
| 30636 |
this.cursor = this.addCursor(); |
| 30637 |
dom.addCssClass(this.element, "ace_hidden-cursors"); |
| 30638 |
this.$updateCursors = (isIE8 |
| 30639 |
? this.$updateVisibility |
| 30640 |
: this.$updateOpacity).bind(this); |
| 30641 |
}; |
| 30642 |
|
| 30643 |
(function() { |
| 30644 |
|
| 30645 |
this.$updateVisibility = function(val) { |
| 30646 |
var cursors = this.cursors; |
| 30647 |
for (var i = cursors.length; i--; ) |
| 30648 |
cursors[i].style.visibility = val ? "" : "hidden"; |
| 30649 |
}; |
| 30650 |
this.$updateOpacity = function(val) { |
| 30651 |
var cursors = this.cursors; |
| 30652 |
for (var i = cursors.length; i--; ) |
| 30653 |
cursors[i].style.opacity = val ? "" : "0"; |
| 30654 |
}; |
| 30655 |
|
| 30656 |
|
| 30657 |
this.$padding = 0; |
| 30658 |
this.setPadding = function(padding) { |
| 30659 |
this.$padding = padding; |
| 30660 |
}; |
| 30661 |
|
| 30662 |
this.setSession = function(session) { |
| 30663 |
this.session = session; |
| 30664 |
}; |
| 30665 |
|
| 30666 |
this.setBlinking = function(blinking) { |
| 30667 |
if (blinking != this.isBlinking){ |
| 30668 |
this.isBlinking = blinking; |
| 30669 |
this.restartTimer(); |
| 30670 |
} |
| 30671 |
}; |
| 30672 |
|
| 30673 |
this.setBlinkInterval = function(blinkInterval) { |
| 30674 |
if (blinkInterval != this.blinkInterval){ |
| 30675 |
this.blinkInterval = blinkInterval; |
| 30676 |
this.restartTimer(); |
| 30677 |
} |
| 30678 |
}; |
| 30679 |
|
| 30680 |
this.setSmoothBlinking = function(smoothBlinking) { |
| 30681 |
if (smoothBlinking != this.smoothBlinking && !isIE8) { |
| 30682 |
this.smoothBlinking = smoothBlinking; |
| 30683 |
dom.setCssClass(this.element, "ace_smooth-blinking", smoothBlinking); |
| 30684 |
this.$updateCursors(true); |
| 30685 |
this.$updateCursors = (this.$updateOpacity).bind(this); |
| 30686 |
this.restartTimer(); |
| 30687 |
} |
| 30688 |
}; |
| 30689 |
|
| 30690 |
this.addCursor = function() { |
| 30691 |
var el = dom.createElement("div"); |
| 30692 |
el.className = "ace_cursor"; |
| 30693 |
this.element.appendChild(el); |
| 30694 |
this.cursors.push(el); |
| 30695 |
return el; |
| 30696 |
}; |
| 30697 |
|
| 30698 |
this.removeCursor = function() { |
| 30699 |
if (this.cursors.length > 1) { |
| 30700 |
var el = this.cursors.pop(); |
| 30701 |
el.parentNode.removeChild(el); |
| 30702 |
return el; |
| 30703 |
} |
| 30704 |
}; |
| 30705 |
|
| 30706 |
this.hideCursor = function() { |
| 30707 |
this.isVisible = false; |
| 30708 |
dom.addCssClass(this.element, "ace_hidden-cursors"); |
| 30709 |
this.restartTimer(); |
| 30710 |
}; |
| 30711 |
|
| 30712 |
this.showCursor = function() { |
| 30713 |
this.isVisible = true; |
| 30714 |
dom.removeCssClass(this.element, "ace_hidden-cursors"); |
| 30715 |
this.restartTimer(); |
| 30716 |
}; |
| 30717 |
|
| 30718 |
this.restartTimer = function() { |
| 30719 |
var update = this.$updateCursors; |
| 30720 |
clearInterval(this.intervalId); |
| 30721 |
clearTimeout(this.timeoutId); |
| 30722 |
if (this.smoothBlinking) { |
| 30723 |
dom.removeCssClass(this.element, "ace_smooth-blinking"); |
| 30724 |
} |
| 30725 |
|
| 30726 |
update(true); |
| 30727 |
|
| 30728 |
if (!this.isBlinking || !this.blinkInterval || !this.isVisible) |
| 30729 |
return; |
| 30730 |
|
| 30731 |
if (this.smoothBlinking) { |
| 30732 |
setTimeout(function(){ |
| 30733 |
dom.addCssClass(this.element, "ace_smooth-blinking"); |
| 30734 |
}.bind(this)); |
| 30735 |
} |
| 30736 |
|
| 30737 |
var blink = function(){ |
| 30738 |
this.timeoutId = setTimeout(function() { |
| 30739 |
update(false); |
| 30740 |
}, 0.6 * this.blinkInterval); |
| 30741 |
}.bind(this); |
| 30742 |
|
| 30743 |
this.intervalId = setInterval(function() { |
| 30744 |
update(true); |
| 30745 |
blink(); |
| 30746 |
}, this.blinkInterval); |
| 30747 |
|
| 30748 |
blink(); |
| 30749 |
}; |
| 30750 |
|
| 30751 |
this.getPixelPosition = function(position, onScreen) { |
| 30752 |
if (!this.config || !this.session) |
| 30753 |
return {left : 0, top : 0}; |
| 30754 |
|
| 30755 |
if (!position) |
| 30756 |
position = this.session.selection.getCursor(); |
| 30757 |
var pos = this.session.documentToScreenPosition(position); |
| 30758 |
var cursorLeft = this.$padding + pos.column * this.config.characterWidth; |
| 30759 |
var cursorTop = (pos.row - (onScreen ? this.config.firstRowScreen : 0)) * |
| 30760 |
this.config.lineHeight; |
| 30761 |
|
| 30762 |
return {left : cursorLeft, top : cursorTop}; |
| 30763 |
}; |
| 30764 |
|
| 30765 |
this.update = function(config) { |
| 30766 |
this.config = config; |
| 30767 |
|
| 30768 |
var selections = this.session.$selectionMarkers; |
| 30769 |
var i = 0, cursorIndex = 0; |
| 30770 |
|
| 30771 |
if (selections === undefined || selections.length === 0){ |
| 30772 |
selections = [{cursor: null}]; |
| 30773 |
} |
| 30774 |
|
| 30775 |
for (var i = 0, n = selections.length; i < n; i++) { |
| 30776 |
var pixelPos = this.getPixelPosition(selections[i].cursor, true); |
| 30777 |
if ((pixelPos.top > config.height + config.offset || |
| 30778 |
pixelPos.top < 0) && i > 1) { |
| 30779 |
continue; |
| 30780 |
} |
| 30781 |
|
| 30782 |
var style = (this.cursors[cursorIndex++] || this.addCursor()).style; |
| 30783 |
|
| 30784 |
if (!this.drawCursor) { |
| 30785 |
style.left = pixelPos.left + "px"; |
| 30786 |
style.top = pixelPos.top + "px"; |
| 30787 |
style.width = config.characterWidth + "px"; |
| 30788 |
style.height = config.lineHeight + "px"; |
| 30789 |
} else { |
| 30790 |
this.drawCursor(style, pixelPos, config, selections[i], this.session); |
| 30791 |
} |
| 30792 |
} |
| 30793 |
while (this.cursors.length > cursorIndex) |
| 30794 |
this.removeCursor(); |
| 30795 |
|
| 30796 |
var overwrite = this.session.getOverwrite(); |
| 30797 |
this.$setOverwrite(overwrite); |
| 30798 |
this.$pixelPos = pixelPos; |
| 30799 |
this.restartTimer(); |
| 30800 |
}; |
| 30801 |
|
| 30802 |
this.drawCursor = null; |
| 30803 |
|
| 30804 |
this.$setOverwrite = function(overwrite) { |
| 30805 |
if (overwrite != this.overwrite) { |
| 30806 |
this.overwrite = overwrite; |
| 30807 |
if (overwrite) |
| 30808 |
dom.addCssClass(this.element, "ace_overwrite-cursors"); |
| 30809 |
else |
| 30810 |
dom.removeCssClass(this.element, "ace_overwrite-cursors"); |
| 30811 |
} |
| 30812 |
}; |
| 30813 |
|
| 30814 |
this.destroy = function() { |
| 30815 |
clearInterval(this.intervalId); |
| 30816 |
clearTimeout(this.timeoutId); |
| 30817 |
}; |
| 30818 |
|
| 30819 |
}).call(Cursor.prototype); |
| 30820 |
|
| 30821 |
exports.Cursor = Cursor; |
| 30822 |
|
| 30823 |
}); |
| 30824 |
|
| 30825 |
ace.define("ace/scrollbar",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/event","ace/lib/event_emitter"], function(acequire, exports, module) { |
| 30826 |
"use strict"; |
| 30827 |
|
| 30828 |
var oop = acequire("./lib/oop"); |
| 30829 |
var dom = acequire("./lib/dom"); |
| 30830 |
var event = acequire("./lib/event"); |
| 30831 |
var EventEmitter = acequire("./lib/event_emitter").EventEmitter; |
| 30832 |
var ScrollBar = function(parent) { |
| 30833 |
this.element = dom.createElement("div"); |
| 30834 |
this.element.className = "ace_scrollbar ace_scrollbar" + this.classSuffix; |
| 30835 |
|
| 30836 |
this.inner = dom.createElement("div"); |
| 30837 |
this.inner.className = "ace_scrollbar-inner"; |
| 30838 |
this.element.appendChild(this.inner); |
| 30839 |
|
| 30840 |
parent.appendChild(this.element); |
| 30841 |
|
| 30842 |
this.setVisible(false); |
| 30843 |
this.skipEvent = false; |
| 30844 |
|
| 30845 |
event.addListener(this.element, "scroll", this.onScroll.bind(this)); |
| 30846 |
event.addListener(this.element, "mousedown", event.preventDefault); |
| 30847 |
}; |
| 30848 |
|
| 30849 |
(function() { |
| 30850 |
oop.implement(this, EventEmitter); |
| 30851 |
|
| 30852 |
this.setVisible = function(isVisible) { |
| 30853 |
this.element.style.display = isVisible ? "" : "none"; |
| 30854 |
this.isVisible = isVisible; |
| 30855 |
}; |
| 30856 |
}).call(ScrollBar.prototype); |
| 30857 |
var VScrollBar = function(parent, renderer) { |
| 30858 |
ScrollBar.call(this, parent); |
| 30859 |
this.scrollTop = 0; |
| 30860 |
renderer.$scrollbarWidth = |
| 30861 |
this.width = dom.scrollbarWidth(parent.ownerDocument); |
| 30862 |
this.inner.style.width = |
| 30863 |
this.element.style.width = (this.width || 15) + 5 + "px"; |
| 30864 |
}; |
| 30865 |
|
| 30866 |
oop.inherits(VScrollBar, ScrollBar); |
| 30867 |
|
| 30868 |
(function() { |
| 30869 |
|
| 30870 |
this.classSuffix = '-v'; |
| 30871 |
this.onScroll = function() { |
| 30872 |
if (!this.skipEvent) { |
| 30873 |
this.scrollTop = this.element.scrollTop; |
| 30874 |
this._emit("scroll", {data: this.scrollTop}); |
| 30875 |
} |
| 30876 |
this.skipEvent = false; |
| 30877 |
}; |
| 30878 |
this.getWidth = function() { |
| 30879 |
return this.isVisible ? this.width : 0; |
| 30880 |
}; |
| 30881 |
this.setHeight = function(height) { |
| 30882 |
this.element.style.height = height + "px"; |
| 30883 |
}; |
| 30884 |
this.setInnerHeight = function(height) { |
| 30885 |
this.inner.style.height = height + "px"; |
| 30886 |
}; |
| 30887 |
this.setScrollHeight = function(height) { |
| 30888 |
this.inner.style.height = height + "px"; |
| 30889 |
}; |
| 30890 |
this.setScrollTop = function(scrollTop) { |
| 30891 |
if (this.scrollTop != scrollTop) { |
| 30892 |
this.skipEvent = true; |
| 30893 |
this.scrollTop = this.element.scrollTop = scrollTop; |
| 30894 |
} |
| 30895 |
}; |
| 30896 |
|
| 30897 |
}).call(VScrollBar.prototype); |
| 30898 |
var HScrollBar = function(parent, renderer) { |
| 30899 |
ScrollBar.call(this, parent); |
| 30900 |
this.scrollLeft = 0; |
| 30901 |
this.height = renderer.$scrollbarWidth; |
| 30902 |
this.inner.style.height = |
| 30903 |
this.element.style.height = (this.height || 15) + 5 + "px"; |
| 30904 |
}; |
| 30905 |
|
| 30906 |
oop.inherits(HScrollBar, ScrollBar); |
| 30907 |
|
| 30908 |
(function() { |
| 30909 |
|
| 30910 |
this.classSuffix = '-h'; |
| 30911 |
this.onScroll = function() { |
| 30912 |
if (!this.skipEvent) { |
| 30913 |
this.scrollLeft = this.element.scrollLeft; |
| 30914 |
this._emit("scroll", {data: this.scrollLeft}); |
| 30915 |
} |
| 30916 |
this.skipEvent = false; |
| 30917 |
}; |
| 30918 |
this.getHeight = function() { |
| 30919 |
return this.isVisible ? this.height : 0; |
| 30920 |
}; |
| 30921 |
this.setWidth = function(width) { |
| 30922 |
this.element.style.width = width + "px"; |
| 30923 |
}; |
| 30924 |
this.setInnerWidth = function(width) { |
| 30925 |
this.inner.style.width = width + "px"; |
| 30926 |
}; |
| 30927 |
this.setScrollWidth = function(width) { |
| 30928 |
this.inner.style.width = width + "px"; |
| 30929 |
}; |
| 30930 |
this.setScrollLeft = function(scrollLeft) { |
| 30931 |
if (this.scrollLeft != scrollLeft) { |
| 30932 |
this.skipEvent = true; |
| 30933 |
this.scrollLeft = this.element.scrollLeft = scrollLeft; |
| 30934 |
} |
| 30935 |
}; |
| 30936 |
|
| 30937 |
}).call(HScrollBar.prototype); |
| 30938 |
|
| 30939 |
|
| 30940 |
exports.ScrollBar = VScrollBar; // backward compatibility |
| 30941 |
exports.ScrollBarV = VScrollBar; // backward compatibility |
| 30942 |
exports.ScrollBarH = HScrollBar; // backward compatibility |
| 30943 |
|
| 30944 |
exports.VScrollBar = VScrollBar; |
| 30945 |
exports.HScrollBar = HScrollBar; |
| 30946 |
}); |
| 30947 |
|
| 30948 |
ace.define("ace/renderloop",["require","exports","module","ace/lib/event"], function(acequire, exports, module) { |
| 30949 |
"use strict"; |
| 30950 |
|
| 30951 |
var event = acequire("./lib/event"); |
| 30952 |
|
| 30953 |
|
| 30954 |
var RenderLoop = function(onRender, win) { |
| 30955 |
this.onRender = onRender; |
| 30956 |
this.pending = false; |
| 30957 |
this.changes = 0; |
| 30958 |
this.window = win || window; |
| 30959 |
}; |
| 30960 |
|
| 30961 |
(function() { |
| 30962 |
|
| 30963 |
|
| 30964 |
this.schedule = function(change) { |
| 30965 |
this.changes = this.changes | change; |
| 30966 |
if (!this.pending && this.changes) { |
| 30967 |
this.pending = true; |
| 30968 |
var _self = this; |
| 30969 |
event.nextFrame(function() { |
| 30970 |
_self.pending = false; |
| 30971 |
var changes; |
| 30972 |
while (changes = _self.changes) { |
| 30973 |
_self.changes = 0; |
| 30974 |
_self.onRender(changes); |
| 30975 |
} |
| 30976 |
}, this.window); |
| 30977 |
} |
| 30978 |
}; |
| 30979 |
|
| 30980 |
}).call(RenderLoop.prototype); |
| 30981 |
|
| 30982 |
exports.RenderLoop = RenderLoop; |
| 30983 |
}); |
| 30984 |
|
| 30985 |
ace.define("ace/layer/font_metrics",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/lib/lang","ace/lib/useragent","ace/lib/event_emitter"], function(acequire, exports, module) { |
| 30986 |
|
| 30987 |
var oop = acequire("../lib/oop"); |
| 30988 |
var dom = acequire("../lib/dom"); |
| 30989 |
var lang = acequire("../lib/lang"); |
| 30990 |
var useragent = acequire("../lib/useragent"); |
| 30991 |
var EventEmitter = acequire("../lib/event_emitter").EventEmitter; |
| 30992 |
|
| 30993 |
var CHAR_COUNT = 0; |
| 30994 |
|
| 30995 |
var FontMetrics = exports.FontMetrics = function(parentEl) { |
| 30996 |
this.el = dom.createElement("div"); |
| 30997 |
this.$setMeasureNodeStyles(this.el.style, true); |
| 30998 |
|
| 30999 |
this.$main = dom.createElement("div"); |
| 31000 |
this.$setMeasureNodeStyles(this.$main.style); |
| 31001 |
|
| 31002 |
this.$measureNode = dom.createElement("div"); |
| 31003 |
this.$setMeasureNodeStyles(this.$measureNode.style); |
| 31004 |
|
| 31005 |
|
| 31006 |
this.el.appendChild(this.$main); |
| 31007 |
this.el.appendChild(this.$measureNode); |
| 31008 |
parentEl.appendChild(this.el); |
| 31009 |
|
| 31010 |
if (!CHAR_COUNT) |
| 31011 |
this.$testFractionalRect(); |
| 31012 |
this.$measureNode.innerHTML = lang.stringRepeat("X", CHAR_COUNT); |
| 31013 |
|
| 31014 |
this.$characterSize = {width: 0, height: 0}; |
| 31015 |
this.checkForSizeChanges(); |
| 31016 |
}; |
| 31017 |
|
| 31018 |
(function() { |
| 31019 |
|
| 31020 |
oop.implement(this, EventEmitter); |
| 31021 |
|
| 31022 |
this.$characterSize = {width: 0, height: 0}; |
| 31023 |
|
| 31024 |
this.$testFractionalRect = function() { |
| 31025 |
var el = dom.createElement("div"); |
| 31026 |
this.$setMeasureNodeStyles(el.style); |
| 31027 |
el.style.width = "0.2px"; |
| 31028 |
document.documentElement.appendChild(el); |
| 31029 |
var w = el.getBoundingClientRect().width; |
| 31030 |
if (w > 0 && w < 1) |
| 31031 |
CHAR_COUNT = 50; |
| 31032 |
else |
| 31033 |
CHAR_COUNT = 100; |
| 31034 |
el.parentNode.removeChild(el); |
| 31035 |
}; |
| 31036 |
|
| 31037 |
this.$setMeasureNodeStyles = function(style, isRoot) { |
| 31038 |
style.width = style.height = "auto"; |
| 31039 |
style.left = style.top = "0px"; |
| 31040 |
style.visibility = "hidden"; |
| 31041 |
style.position = "absolute"; |
| 31042 |
style.whiteSpace = "pre"; |
| 31043 |
|
| 31044 |
if (useragent.isIE < 8) { |
| 31045 |
style["font-family"] = "inherit"; |
| 31046 |
} else { |
| 31047 |
style.font = "inherit"; |
| 31048 |
} |
| 31049 |
style.overflow = isRoot ? "hidden" : "visible"; |
| 31050 |
}; |
| 31051 |
|
| 31052 |
this.checkForSizeChanges = function() { |
| 31053 |
var size = this.$measureSizes(); |
| 31054 |
if (size && (this.$characterSize.width !== size.width || this.$characterSize.height !== size.height)) { |
| 31055 |
this.$measureNode.style.fontWeight = "bold"; |
| 31056 |
var boldSize = this.$measureSizes(); |
| 31057 |
this.$measureNode.style.fontWeight = ""; |
| 31058 |
this.$characterSize = size; |
| 31059 |
this.charSizes = Object.create(null); |
| 31060 |
this.allowBoldFonts = boldSize && boldSize.width === size.width && boldSize.height === size.height; |
| 31061 |
this._emit("changeCharacterSize", {data: size}); |
| 31062 |
} |
| 31063 |
}; |
| 31064 |
|
| 31065 |
this.$pollSizeChanges = function() { |
| 31066 |
if (this.$pollSizeChangesTimer) |
| 31067 |
return this.$pollSizeChangesTimer; |
| 31068 |
var self = this; |
| 31069 |
return this.$pollSizeChangesTimer = setInterval(function() { |
| 31070 |
self.checkForSizeChanges(); |
| 31071 |
}, 500); |
| 31072 |
}; |
| 31073 |
|
| 31074 |
this.setPolling = function(val) { |
| 31075 |
if (val) { |
| 31076 |
this.$pollSizeChanges(); |
| 31077 |
} else if (this.$pollSizeChangesTimer) { |
| 31078 |
clearInterval(this.$pollSizeChangesTimer); |
| 31079 |
this.$pollSizeChangesTimer = 0; |
| 31080 |
} |
| 31081 |
}; |
| 31082 |
|
| 31083 |
this.$measureSizes = function() { |
| 31084 |
if (CHAR_COUNT === 50) { |
| 31085 |
var rect = null; |
| 31086 |
try { |
| 31087 |
rect = this.$measureNode.getBoundingClientRect(); |
| 31088 |
} catch(e) { |
| 31089 |
rect = {width: 0, height:0 }; |
| 31090 |
} |
| 31091 |
var size = { |
| 31092 |
height: rect.height, |
| 31093 |
width: rect.width / CHAR_COUNT |
| 31094 |
}; |
| 31095 |
} else { |
| 31096 |
var size = { |
| 31097 |
height: this.$measureNode.clientHeight, |
| 31098 |
width: this.$measureNode.clientWidth / CHAR_COUNT |
| 31099 |
}; |
| 31100 |
} |
| 31101 |
if (size.width === 0 || size.height === 0) |
| 31102 |
return null; |
| 31103 |
return size; |
| 31104 |
}; |
| 31105 |
|
| 31106 |
this.$measureCharWidth = function(ch) { |
| 31107 |
this.$main.innerHTML = lang.stringRepeat(ch, CHAR_COUNT); |
| 31108 |
var rect = this.$main.getBoundingClientRect(); |
| 31109 |
return rect.width / CHAR_COUNT; |
| 31110 |
}; |
| 31111 |
|
| 31112 |
this.getCharacterWidth = function(ch) { |
| 31113 |
var w = this.charSizes[ch]; |
| 31114 |
if (w === undefined) { |
| 31115 |
w = this.charSizes[ch] = this.$measureCharWidth(ch) / this.$characterSize.width; |
| 31116 |
} |
| 31117 |
return w; |
| 31118 |
}; |
| 31119 |
|
| 31120 |
this.destroy = function() { |
| 31121 |
clearInterval(this.$pollSizeChangesTimer); |
| 31122 |
if (this.el && this.el.parentNode) |
| 31123 |
this.el.parentNode.removeChild(this.el); |
| 31124 |
}; |
| 31125 |
|
| 31126 |
}).call(FontMetrics.prototype); |
| 31127 |
|
| 31128 |
}); |
| 31129 |
|
| 31130 |
ace.define("ace/virtual_renderer",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/config","ace/lib/useragent","ace/layer/gutter","ace/layer/marker","ace/layer/text","ace/layer/cursor","ace/scrollbar","ace/scrollbar","ace/renderloop","ace/layer/font_metrics","ace/lib/event_emitter"], function(acequire, exports, module) { |
| 31131 |
"use strict"; |
| 31132 |
|
| 31133 |
var oop = acequire("./lib/oop"); |
| 31134 |
var dom = acequire("./lib/dom"); |
| 31135 |
var config = acequire("./config"); |
| 31136 |
var useragent = acequire("./lib/useragent"); |
| 31137 |
var GutterLayer = acequire("./layer/gutter").Gutter; |
| 31138 |
var MarkerLayer = acequire("./layer/marker").Marker; |
| 31139 |
var TextLayer = acequire("./layer/text").Text; |
| 31140 |
var CursorLayer = acequire("./layer/cursor").Cursor; |
| 31141 |
var HScrollBar = acequire("./scrollbar").HScrollBar; |
| 31142 |
var VScrollBar = acequire("./scrollbar").VScrollBar; |
| 31143 |
var RenderLoop = acequire("./renderloop").RenderLoop; |
| 31144 |
var FontMetrics = acequire("./layer/font_metrics").FontMetrics; |
| 31145 |
var EventEmitter = acequire("./lib/event_emitter").EventEmitter; |
| 31146 |
var editorCss = ".ace_editor {\ |
| 31147 |
position: relative;\ |
| 31148 |
overflow: hidden;\ |
| 31149 |
font: 12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;\ |
| 31150 |
direction: ltr;\ |
| 31151 |
}\ |
| 31152 |
.ace_scroller {\ |
| 31153 |
position: absolute;\ |
| 31154 |
overflow: hidden;\ |
| 31155 |
top: 0;\ |
| 31156 |
bottom: 0;\ |
| 31157 |
background-color: inherit;\ |
| 31158 |
-ms-user-select: none;\ |
| 31159 |
-moz-user-select: none;\ |
| 31160 |
-webkit-user-select: none;\ |
| 31161 |
user-select: none;\ |
| 31162 |
cursor: text;\ |
| 31163 |
}\ |
| 31164 |
.ace_content {\ |
| 31165 |
position: absolute;\ |
| 31166 |
-moz-box-sizing: border-box;\ |
| 31167 |
-webkit-box-sizing: border-box;\ |
| 31168 |
box-sizing: border-box;\ |
| 31169 |
min-width: 100%;\ |
| 31170 |
}\ |
| 31171 |
.ace_dragging .ace_scroller:before{\ |
| 31172 |
position: absolute;\ |
| 31173 |
top: 0;\ |
| 31174 |
left: 0;\ |
| 31175 |
right: 0;\ |
| 31176 |
bottom: 0;\ |
| 31177 |
content: '';\ |
| 31178 |
background: rgba(250, 250, 250, 0.01);\ |
| 31179 |
z-index: 1000;\ |
| 31180 |
}\ |
| 31181 |
.ace_dragging.ace_dark .ace_scroller:before{\ |
| 31182 |
background: rgba(0, 0, 0, 0.01);\ |
| 31183 |
}\ |
| 31184 |
.ace_selecting, .ace_selecting * {\ |
| 31185 |
cursor: text !important;\ |
| 31186 |
}\ |
| 31187 |
.ace_gutter {\ |
| 31188 |
position: absolute;\ |
| 31189 |
overflow : hidden;\ |
| 31190 |
width: auto;\ |
| 31191 |
top: 0;\ |
| 31192 |
bottom: 0;\ |
| 31193 |
left: 0;\ |
| 31194 |
cursor: default;\ |
| 31195 |
z-index: 4;\ |
| 31196 |
-ms-user-select: none;\ |
| 31197 |
-moz-user-select: none;\ |
| 31198 |
-webkit-user-select: none;\ |
| 31199 |
user-select: none;\ |
| 31200 |
}\ |
| 31201 |
.ace_gutter-active-line {\ |
| 31202 |
position: absolute;\ |
| 31203 |
left: 0;\ |
| 31204 |
right: 0;\ |
| 31205 |
}\ |
| 31206 |
.ace_scroller.ace_scroll-left {\ |
| 31207 |
box-shadow: 17px 0 16px -16px rgba(0, 0, 0, 0.4) inset;\ |
| 31208 |
}\ |
| 31209 |
.ace_gutter-cell {\ |
| 31210 |
padding-left: 19px;\ |
| 31211 |
padding-right: 6px;\ |
| 31212 |
background-repeat: no-repeat;\ |
| 31213 |
}\ |
| 31214 |
.ace_gutter-cell.ace_error {\ |
| 31215 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAABOFBMVEX/////////QRswFAb/Ui4wFAYwFAYwFAaWGAfDRymzOSH/PxswFAb/SiUwFAYwFAbUPRvjQiDllog5HhHdRybsTi3/Tyv9Tir+Syj/UC3////XurebMBIwFAb/RSHbPx/gUzfdwL3kzMivKBAwFAbbvbnhPx66NhowFAYwFAaZJg8wFAaxKBDZurf/RB6mMxb/SCMwFAYwFAbxQB3+RB4wFAb/Qhy4Oh+4QifbNRcwFAYwFAYwFAb/QRzdNhgwFAYwFAbav7v/Uy7oaE68MBK5LxLewr/r2NXewLswFAaxJw4wFAbkPRy2PyYwFAaxKhLm1tMwFAazPiQwFAaUGAb/QBrfOx3bvrv/VC/maE4wFAbRPBq6MRO8Qynew8Dp2tjfwb0wFAbx6eju5+by6uns4uH9/f36+vr/GkHjAAAAYnRSTlMAGt+64rnWu/bo8eAA4InH3+DwoN7j4eLi4xP99Nfg4+b+/u9B/eDs1MD1mO7+4PHg2MXa347g7vDizMLN4eG+Pv7i5evs/v79yu7S3/DV7/498Yv24eH+4ufQ3Ozu/v7+y13sRqwAAADLSURBVHjaZc/XDsFgGIBhtDrshlitmk2IrbHFqL2pvXf/+78DPokj7+Fz9qpU/9UXJIlhmPaTaQ6QPaz0mm+5gwkgovcV6GZzd5JtCQwgsxoHOvJO15kleRLAnMgHFIESUEPmawB9ngmelTtipwwfASilxOLyiV5UVUyVAfbG0cCPHig+GBkzAENHS0AstVF6bacZIOzgLmxsHbt2OecNgJC83JERmePUYq8ARGkJx6XtFsdddBQgZE2nPR6CICZhawjA4Fb/chv+399kfR+MMMDGOQAAAABJRU5ErkJggg==\");\ |
| 31216 |
background-repeat: no-repeat;\ |
| 31217 |
background-position: 2px center;\ |
| 31218 |
}\ |
| 31219 |
.ace_gutter-cell.ace_warning {\ |
| 31220 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAmVBMVEX///8AAAD///8AAAAAAABPSzb/5sAAAAB/blH/73z/ulkAAAAAAAD85pkAAAAAAAACAgP/vGz/rkDerGbGrV7/pkQICAf////e0IsAAAD/oED/qTvhrnUAAAD/yHD/njcAAADuv2r/nz//oTj/p064oGf/zHAAAAA9Nir/tFIAAAD/tlTiuWf/tkIAAACynXEAAAAAAAAtIRW7zBpBAAAAM3RSTlMAABR1m7RXO8Ln31Z36zT+neXe5OzooRDfn+TZ4p3h2hTf4t3k3ucyrN1K5+Xaks52Sfs9CXgrAAAAjklEQVR42o3PbQ+CIBQFYEwboPhSYgoYunIqqLn6/z8uYdH8Vmdnu9vz4WwXgN/xTPRD2+sgOcZjsge/whXZgUaYYvT8QnuJaUrjrHUQreGczuEafQCO/SJTufTbroWsPgsllVhq3wJEk2jUSzX3CUEDJC84707djRc5MTAQxoLgupWRwW6UB5fS++NV8AbOZgnsC7BpEAAAAABJRU5ErkJggg==\");\ |
| 31221 |
background-position: 2px center;\ |
| 31222 |
}\ |
| 31223 |
.ace_gutter-cell.ace_info {\ |
| 31224 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAJ0Uk5TAAB2k804AAAAPklEQVQY02NgIB68QuO3tiLznjAwpKTgNyDbMegwisCHZUETUZV0ZqOquBpXj2rtnpSJT1AEnnRmL2OgGgAAIKkRQap2htgAAAAASUVORK5CYII=\");\ |
| 31225 |
background-position: 2px center;\ |
| 31226 |
}\ |
| 31227 |
.ace_dark .ace_gutter-cell.ace_info {\ |
| 31228 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAJFBMVEUAAAChoaGAgIAqKiq+vr6tra1ZWVmUlJSbm5s8PDxubm56enrdgzg3AAAAAXRSTlMAQObYZgAAAClJREFUeNpjYMAPdsMYHegyJZFQBlsUlMFVCWUYKkAZMxZAGdxlDMQBAG+TBP4B6RyJAAAAAElFTkSuQmCC\");\ |
| 31229 |
}\ |
| 31230 |
.ace_scrollbar {\ |
| 31231 |
position: absolute;\ |
| 31232 |
right: 0;\ |
| 31233 |
bottom: 0;\ |
| 31234 |
z-index: 6;\ |
| 31235 |
}\ |
| 31236 |
.ace_scrollbar-inner {\ |
| 31237 |
position: absolute;\ |
| 31238 |
cursor: text;\ |
| 31239 |
left: 0;\ |
| 31240 |
top: 0;\ |
| 31241 |
}\ |
| 31242 |
.ace_scrollbar-v{\ |
| 31243 |
overflow-x: hidden;\ |
| 31244 |
overflow-y: scroll;\ |
| 31245 |
top: 0;\ |
| 31246 |
}\ |
| 31247 |
.ace_scrollbar-h {\ |
| 31248 |
overflow-x: scroll;\ |
| 31249 |
overflow-y: hidden;\ |
| 31250 |
left: 0;\ |
| 31251 |
}\ |
| 31252 |
.ace_print-margin {\ |
| 31253 |
position: absolute;\ |
| 31254 |
height: 100%;\ |
| 31255 |
}\ |
| 31256 |
.ace_text-input {\ |
| 31257 |
position: absolute;\ |
| 31258 |
z-index: 0;\ |
| 31259 |
width: 0.5em;\ |
| 31260 |
height: 1em;\ |
| 31261 |
opacity: 0;\ |
| 31262 |
background: transparent;\ |
| 31263 |
-moz-appearance: none;\ |
| 31264 |
appearance: none;\ |
| 31265 |
border: none;\ |
| 31266 |
resize: none;\ |
| 31267 |
outline: none;\ |
| 31268 |
overflow: hidden;\ |
| 31269 |
font: inherit;\ |
| 31270 |
padding: 0 1px;\ |
| 31271 |
margin: 0 -1px;\ |
| 31272 |
text-indent: -1em;\ |
| 31273 |
-ms-user-select: text;\ |
| 31274 |
-moz-user-select: text;\ |
| 31275 |
-webkit-user-select: text;\ |
| 31276 |
user-select: text;\ |
| 31277 |
white-space: pre!important;\ |
| 31278 |
}\ |
| 31279 |
.ace_text-input.ace_composition {\ |
| 31280 |
background: inherit;\ |
| 31281 |
color: inherit;\ |
| 31282 |
z-index: 1000;\ |
| 31283 |
opacity: 1;\ |
| 31284 |
text-indent: 0;\ |
| 31285 |
}\ |
| 31286 |
.ace_layer {\ |
| 31287 |
z-index: 1;\ |
| 31288 |
position: absolute;\ |
| 31289 |
overflow: hidden;\ |
| 31290 |
word-wrap: normal;\ |
| 31291 |
white-space: pre;\ |
| 31292 |
height: 100%;\ |
| 31293 |
width: 100%;\ |
| 31294 |
-moz-box-sizing: border-box;\ |
| 31295 |
-webkit-box-sizing: border-box;\ |
| 31296 |
box-sizing: border-box;\ |
| 31297 |
pointer-events: none;\ |
| 31298 |
}\ |
| 31299 |
.ace_gutter-layer {\ |
| 31300 |
position: relative;\ |
| 31301 |
width: auto;\ |
| 31302 |
text-align: right;\ |
| 31303 |
pointer-events: auto;\ |
| 31304 |
}\ |
| 31305 |
.ace_text-layer {\ |
| 31306 |
font: inherit !important;\ |
| 31307 |
}\ |
| 31308 |
.ace_cjk {\ |
| 31309 |
display: inline-block;\ |
| 31310 |
text-align: center;\ |
| 31311 |
}\ |
| 31312 |
.ace_cursor-layer {\ |
| 31313 |
z-index: 4;\ |
| 31314 |
}\ |
| 31315 |
.ace_cursor {\ |
| 31316 |
z-index: 4;\ |
| 31317 |
position: absolute;\ |
| 31318 |
-moz-box-sizing: border-box;\ |
| 31319 |
-webkit-box-sizing: border-box;\ |
| 31320 |
box-sizing: border-box;\ |
| 31321 |
border-left: 2px solid;\ |
| 31322 |
transform: translatez(0);\ |
| 31323 |
}\ |
| 31324 |
.ace_slim-cursors .ace_cursor {\ |
| 31325 |
border-left-width: 1px;\ |
| 31326 |
}\ |
| 31327 |
.ace_overwrite-cursors .ace_cursor {\ |
| 31328 |
border-left-width: 0;\ |
| 31329 |
border-bottom: 1px solid;\ |
| 31330 |
}\ |
| 31331 |
.ace_hidden-cursors .ace_cursor {\ |
| 31332 |
opacity: 0.2;\ |
| 31333 |
}\ |
| 31334 |
.ace_smooth-blinking .ace_cursor {\ |
| 31335 |
-webkit-transition: opacity 0.18s;\ |
| 31336 |
transition: opacity 0.18s;\ |
| 31337 |
}\ |
| 31338 |
.ace_editor.ace_multiselect .ace_cursor {\ |
| 31339 |
border-left-width: 1px;\ |
| 31340 |
}\ |
| 31341 |
.ace_marker-layer .ace_step, .ace_marker-layer .ace_stack {\ |
| 31342 |
position: absolute;\ |
| 31343 |
z-index: 3;\ |
| 31344 |
}\ |
| 31345 |
.ace_marker-layer .ace_selection {\ |
| 31346 |
position: absolute;\ |
| 31347 |
z-index: 5;\ |
| 31348 |
}\ |
| 31349 |
.ace_marker-layer .ace_bracket {\ |
| 31350 |
position: absolute;\ |
| 31351 |
z-index: 6;\ |
| 31352 |
}\ |
| 31353 |
.ace_marker-layer .ace_active-line {\ |
| 31354 |
position: absolute;\ |
| 31355 |
z-index: 2;\ |
| 31356 |
}\ |
| 31357 |
.ace_marker-layer .ace_selected-word {\ |
| 31358 |
position: absolute;\ |
| 31359 |
z-index: 4;\ |
| 31360 |
-moz-box-sizing: border-box;\ |
| 31361 |
-webkit-box-sizing: border-box;\ |
| 31362 |
box-sizing: border-box;\ |
| 31363 |
}\ |
| 31364 |
.ace_line .ace_fold {\ |
| 31365 |
-moz-box-sizing: border-box;\ |
| 31366 |
-webkit-box-sizing: border-box;\ |
| 31367 |
box-sizing: border-box;\ |
| 31368 |
display: inline-block;\ |
| 31369 |
height: 11px;\ |
| 31370 |
margin-top: -2px;\ |
| 31371 |
vertical-align: middle;\ |
| 31372 |
background-image:\ |
| 31373 |
url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\ |
| 31374 |
url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACJJREFUeNpi+P//fxgTAwPDBxDxD078RSX+YeEyDFMCIMAAI3INmXiwf2YAAAAASUVORK5CYII=\");\ |
| 31375 |
background-repeat: no-repeat, repeat-x;\ |
| 31376 |
background-position: center center, top left;\ |
| 31377 |
color: transparent;\ |
| 31378 |
border: 1px solid black;\ |
| 31379 |
border-radius: 2px;\ |
| 31380 |
cursor: pointer;\ |
| 31381 |
pointer-events: auto;\ |
| 31382 |
}\ |
| 31383 |
.ace_dark .ace_fold {\ |
| 31384 |
}\ |
| 31385 |
.ace_fold:hover{\ |
| 31386 |
background-image:\ |
| 31387 |
url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAJCAYAAADU6McMAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJpJREFUeNpi/P//PwOlgAXGYGRklAVSokD8GmjwY1wasKljQpYACtpCFeADcHVQfQyMQAwzwAZI3wJKvCLkfKBaMSClBlR7BOQikCFGQEErIH0VqkabiGCAqwUadAzZJRxQr/0gwiXIal8zQQPnNVTgJ1TdawL0T5gBIP1MUJNhBv2HKoQHHjqNrA4WO4zY0glyNKLT2KIfIMAAQsdgGiXvgnYAAAAASUVORK5CYII=\"),\ |
| 31388 |
url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA3CAYAAADNNiA5AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAACBJREFUeNpi+P//fz4TAwPDZxDxD5X4i5fLMEwJgAADAEPVDbjNw87ZAAAAAElFTkSuQmCC\");\ |
| 31389 |
}\ |
| 31390 |
.ace_tooltip {\ |
| 31391 |
background-color: #FFF;\ |
| 31392 |
background-image: -webkit-linear-gradient(top, transparent, rgba(0, 0, 0, 0.1));\ |
| 31393 |
background-image: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.1));\ |
| 31394 |
border: 1px solid gray;\ |
| 31395 |
border-radius: 1px;\ |
| 31396 |
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);\ |
| 31397 |
color: black;\ |
| 31398 |
max-width: 100%;\ |
| 31399 |
padding: 3px 4px;\ |
| 31400 |
position: fixed;\ |
| 31401 |
z-index: 999999;\ |
| 31402 |
-moz-box-sizing: border-box;\ |
| 31403 |
-webkit-box-sizing: border-box;\ |
| 31404 |
box-sizing: border-box;\ |
| 31405 |
cursor: default;\ |
| 31406 |
white-space: pre;\ |
| 31407 |
word-wrap: break-word;\ |
| 31408 |
line-height: normal;\ |
| 31409 |
font-style: normal;\ |
| 31410 |
font-weight: normal;\ |
| 31411 |
letter-spacing: normal;\ |
| 31412 |
pointer-events: none;\ |
| 31413 |
}\ |
| 31414 |
.ace_folding-enabled > .ace_gutter-cell {\ |
| 31415 |
padding-right: 13px;\ |
| 31416 |
}\ |
| 31417 |
.ace_fold-widget {\ |
| 31418 |
-moz-box-sizing: border-box;\ |
| 31419 |
-webkit-box-sizing: border-box;\ |
| 31420 |
box-sizing: border-box;\ |
| 31421 |
margin: 0 -12px 0 1px;\ |
| 31422 |
display: none;\ |
| 31423 |
width: 11px;\ |
| 31424 |
vertical-align: top;\ |
| 31425 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42mWKsQ0AMAzC8ixLlrzQjzmBiEjp0A6WwBCSPgKAXoLkqSot7nN3yMwR7pZ32NzpKkVoDBUxKAAAAABJRU5ErkJggg==\");\ |
| 31426 |
background-repeat: no-repeat;\ |
| 31427 |
background-position: center;\ |
| 31428 |
border-radius: 3px;\ |
| 31429 |
border: 1px solid transparent;\ |
| 31430 |
cursor: pointer;\ |
| 31431 |
}\ |
| 31432 |
.ace_folding-enabled .ace_fold-widget {\ |
| 31433 |
display: inline-block; \ |
| 31434 |
}\ |
| 31435 |
.ace_fold-widget.ace_end {\ |
| 31436 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAANElEQVR42m3HwQkAMAhD0YzsRchFKI7sAikeWkrxwScEB0nh5e7KTPWimZki4tYfVbX+MNl4pyZXejUO1QAAAABJRU5ErkJggg==\");\ |
| 31437 |
}\ |
| 31438 |
.ace_fold-widget.ace_closed {\ |
| 31439 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAGCAYAAAAG5SQMAAAAOUlEQVR42jXKwQkAMAgDwKwqKD4EwQ26sSOkVWjgIIHAzPiCgaqiqnJHZnKICBERHN194O5b9vbLuAVRL+l0YWnZAAAAAElFTkSuQmCCXA==\");\ |
| 31440 |
}\ |
| 31441 |
.ace_fold-widget:hover {\ |
| 31442 |
border: 1px solid rgba(0, 0, 0, 0.3);\ |
| 31443 |
background-color: rgba(255, 255, 255, 0.2);\ |
| 31444 |
box-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);\ |
| 31445 |
}\ |
| 31446 |
.ace_fold-widget:active {\ |
| 31447 |
border: 1px solid rgba(0, 0, 0, 0.4);\ |
| 31448 |
background-color: rgba(0, 0, 0, 0.05);\ |
| 31449 |
box-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);\ |
| 31450 |
}\ |
| 31451 |
.ace_dark .ace_fold-widget {\ |
| 31452 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHklEQVQIW2P4//8/AzoGEQ7oGCaLLAhWiSwB146BAQCSTPYocqT0AAAAAElFTkSuQmCC\");\ |
| 31453 |
}\ |
| 31454 |
.ace_dark .ace_fold-widget.ace_end {\ |
| 31455 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAH0lEQVQIW2P4//8/AxQ7wNjIAjDMgC4AxjCVKBirIAAF0kz2rlhxpAAAAABJRU5ErkJggg==\");\ |
| 31456 |
}\ |
| 31457 |
.ace_dark .ace_fold-widget.ace_closed {\ |
| 31458 |
background-image: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAAFCAYAAACAcVaiAAAAHElEQVQIW2P4//+/AxAzgDADlOOAznHAKgPWAwARji8UIDTfQQAAAABJRU5ErkJggg==\");\ |
| 31459 |
}\ |
| 31460 |
.ace_dark .ace_fold-widget:hover {\ |
| 31461 |
box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\ |
| 31462 |
background-color: rgba(255, 255, 255, 0.1);\ |
| 31463 |
}\ |
| 31464 |
.ace_dark .ace_fold-widget:active {\ |
| 31465 |
box-shadow: 0 1px 1px rgba(255, 255, 255, 0.2);\ |
| 31466 |
}\ |
| 31467 |
.ace_fold-widget.ace_invalid {\ |
| 31468 |
background-color: #FFB4B4;\ |
| 31469 |
border-color: #DE5555;\ |
| 31470 |
}\ |
| 31471 |
.ace_fade-fold-widgets .ace_fold-widget {\ |
| 31472 |
-webkit-transition: opacity 0.4s ease 0.05s;\ |
| 31473 |
transition: opacity 0.4s ease 0.05s;\ |
| 31474 |
opacity: 0;\ |
| 31475 |
}\ |
| 31476 |
.ace_fade-fold-widgets:hover .ace_fold-widget {\ |
| 31477 |
-webkit-transition: opacity 0.05s ease 0.05s;\ |
| 31478 |
transition: opacity 0.05s ease 0.05s;\ |
| 31479 |
opacity:1;\ |
| 31480 |
}\ |
| 31481 |
.ace_underline {\ |
| 31482 |
text-decoration: underline;\ |
| 31483 |
}\ |
| 31484 |
.ace_bold {\ |
| 31485 |
font-weight: bold;\ |
| 31486 |
}\ |
| 31487 |
.ace_nobold .ace_bold {\ |
| 31488 |
font-weight: normal;\ |
| 31489 |
}\ |
| 31490 |
.ace_italic {\ |
| 31491 |
font-style: italic;\ |
| 31492 |
}\ |
| 31493 |
.ace_error-marker {\ |
| 31494 |
background-color: rgba(255, 0, 0,0.2);\ |
| 31495 |
position: absolute;\ |
| 31496 |
z-index: 9;\ |
| 31497 |
}\ |
| 31498 |
.ace_highlight-marker {\ |
| 31499 |
background-color: rgba(255, 255, 0,0.2);\ |
| 31500 |
position: absolute;\ |
| 31501 |
z-index: 8;\ |
| 31502 |
}\ |
| 31503 |
.ace_br1 {border-top-left-radius : 3px;}\ |
| 31504 |
.ace_br2 {border-top-right-radius : 3px;}\ |
| 31505 |
.ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}\ |
| 31506 |
.ace_br4 {border-bottom-right-radius: 3px;}\ |
| 31507 |
.ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}\ |
| 31508 |
.ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}\ |
| 31509 |
.ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}\ |
| 31510 |
.ace_br8 {border-bottom-left-radius : 3px;}\ |
| 31511 |
.ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}\ |
| 31512 |
.ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}\ |
| 31513 |
.ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}\ |
| 31514 |
.ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\ |
| 31515 |
.ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\ |
| 31516 |
.ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\ |
| 31517 |
.ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}\ |
| 31518 |
"; |
| 31519 |
|
| 31520 |
dom.importCssString(editorCss, "ace_editor.css"); |
| 31521 |
|
| 31522 |
var VirtualRenderer = function(container, theme) { |
| 31523 |
var _self = this; |
| 31524 |
|
| 31525 |
this.container = container || dom.createElement("div"); |
| 31526 |
this.$keepTextAreaAtCursor = !useragent.isOldIE; |
| 31527 |
|
| 31528 |
dom.addCssClass(this.container, "ace_editor"); |
| 31529 |
|
| 31530 |
this.setTheme(theme); |
| 31531 |
|
| 31532 |
this.$gutter = dom.createElement("div"); |
| 31533 |
this.$gutter.className = "ace_gutter"; |
| 31534 |
this.container.appendChild(this.$gutter); |
| 31535 |
|
| 31536 |
this.scroller = dom.createElement("div"); |
| 31537 |
this.scroller.className = "ace_scroller"; |
| 31538 |
this.container.appendChild(this.scroller); |
| 31539 |
|
| 31540 |
this.content = dom.createElement("div"); |
| 31541 |
this.content.className = "ace_content"; |
| 31542 |
this.scroller.appendChild(this.content); |
| 31543 |
|
| 31544 |
this.$gutterLayer = new GutterLayer(this.$gutter); |
| 31545 |
this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this)); |
| 31546 |
|
| 31547 |
this.$markerBack = new MarkerLayer(this.content); |
| 31548 |
|
| 31549 |
var textLayer = this.$textLayer = new TextLayer(this.content); |
| 31550 |
this.canvas = textLayer.element; |
| 31551 |
|
| 31552 |
this.$markerFront = new MarkerLayer(this.content); |
| 31553 |
|
| 31554 |
this.$cursorLayer = new CursorLayer(this.content); |
| 31555 |
this.$horizScroll = false; |
| 31556 |
this.$vScroll = false; |
| 31557 |
|
| 31558 |
this.scrollBar = |
| 31559 |
this.scrollBarV = new VScrollBar(this.container, this); |
| 31560 |
this.scrollBarH = new HScrollBar(this.container, this); |
| 31561 |
this.scrollBarV.addEventListener("scroll", function(e) { |
| 31562 |
if (!_self.$scrollAnimation) |
| 31563 |
_self.session.setScrollTop(e.data - _self.scrollMargin.top); |
| 31564 |
}); |
| 31565 |
this.scrollBarH.addEventListener("scroll", function(e) { |
| 31566 |
if (!_self.$scrollAnimation) |
| 31567 |
_self.session.setScrollLeft(e.data - _self.scrollMargin.left); |
| 31568 |
}); |
| 31569 |
|
| 31570 |
this.scrollTop = 0; |
| 31571 |
this.scrollLeft = 0; |
| 31572 |
|
| 31573 |
this.cursorPos = { |
| 31574 |
row : 0, |
| 31575 |
column : 0 |
| 31576 |
}; |
| 31577 |
|
| 31578 |
this.$fontMetrics = new FontMetrics(this.container); |
| 31579 |
this.$textLayer.$setFontMetrics(this.$fontMetrics); |
| 31580 |
this.$textLayer.addEventListener("changeCharacterSize", function(e) { |
| 31581 |
_self.updateCharacterSize(); |
| 31582 |
_self.onResize(true, _self.gutterWidth, _self.$size.width, _self.$size.height); |
| 31583 |
_self._signal("changeCharacterSize", e); |
| 31584 |
}); |
| 31585 |
|
| 31586 |
this.$size = { |
| 31587 |
width: 0, |
| 31588 |
height: 0, |
| 31589 |
scrollerHeight: 0, |
| 31590 |
scrollerWidth: 0, |
| 31591 |
$dirty: true |
| 31592 |
}; |
| 31593 |
|
| 31594 |
this.layerConfig = { |
| 31595 |
width : 1, |
| 31596 |
padding : 0, |
| 31597 |
firstRow : 0, |
| 31598 |
firstRowScreen: 0, |
| 31599 |
lastRow : 0, |
| 31600 |
lineHeight : 0, |
| 31601 |
characterWidth : 0, |
| 31602 |
minHeight : 1, |
| 31603 |
maxHeight : 1, |
| 31604 |
offset : 0, |
| 31605 |
height : 1, |
| 31606 |
gutterOffset: 1 |
| 31607 |
}; |
| 31608 |
|
| 31609 |
this.scrollMargin = { |
| 31610 |
left: 0, |
| 31611 |
right: 0, |
| 31612 |
top: 0, |
| 31613 |
bottom: 0, |
| 31614 |
v: 0, |
| 31615 |
h: 0 |
| 31616 |
}; |
| 31617 |
|
| 31618 |
this.$loop = new RenderLoop( |
| 31619 |
this.$renderChanges.bind(this), |
| 31620 |
this.container.ownerDocument.defaultView |
| 31621 |
); |
| 31622 |
this.$loop.schedule(this.CHANGE_FULL); |
| 31623 |
|
| 31624 |
this.updateCharacterSize(); |
| 31625 |
this.setPadding(4); |
| 31626 |
config.resetOptions(this); |
| 31627 |
config._emit("renderer", this); |
| 31628 |
}; |
| 31629 |
|
| 31630 |
(function() { |
| 31631 |
|
| 31632 |
this.CHANGE_CURSOR = 1; |
| 31633 |
this.CHANGE_MARKER = 2; |
| 31634 |
this.CHANGE_GUTTER = 4; |
| 31635 |
this.CHANGE_SCROLL = 8; |
| 31636 |
this.CHANGE_LINES = 16; |
| 31637 |
this.CHANGE_TEXT = 32; |
| 31638 |
this.CHANGE_SIZE = 64; |
| 31639 |
this.CHANGE_MARKER_BACK = 128; |
| 31640 |
this.CHANGE_MARKER_FRONT = 256; |
| 31641 |
this.CHANGE_FULL = 512; |
| 31642 |
this.CHANGE_H_SCROLL = 1024; |
| 31643 |
|
| 31644 |
oop.implement(this, EventEmitter); |
| 31645 |
|
| 31646 |
this.updateCharacterSize = function() { |
| 31647 |
if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) { |
| 31648 |
this.$allowBoldFonts = this.$textLayer.allowBoldFonts; |
| 31649 |
this.setStyle("ace_nobold", !this.$allowBoldFonts); |
| 31650 |
} |
| 31651 |
|
| 31652 |
this.layerConfig.characterWidth = |
| 31653 |
this.characterWidth = this.$textLayer.getCharacterWidth(); |
| 31654 |
this.layerConfig.lineHeight = |
| 31655 |
this.lineHeight = this.$textLayer.getLineHeight(); |
| 31656 |
this.$updatePrintMargin(); |
| 31657 |
}; |
| 31658 |
this.setSession = function(session) { |
| 31659 |
if (this.session) |
| 31660 |
this.session.doc.off("changeNewLineMode", this.onChangeNewLineMode); |
| 31661 |
|
| 31662 |
this.session = session; |
| 31663 |
if (session && this.scrollMargin.top && session.getScrollTop() <= 0) |
| 31664 |
session.setScrollTop(-this.scrollMargin.top); |
| 31665 |
|
| 31666 |
this.$cursorLayer.setSession(session); |
| 31667 |
this.$markerBack.setSession(session); |
| 31668 |
this.$markerFront.setSession(session); |
| 31669 |
this.$gutterLayer.setSession(session); |
| 31670 |
this.$textLayer.setSession(session); |
| 31671 |
if (!session) |
| 31672 |
return; |
| 31673 |
|
| 31674 |
this.$loop.schedule(this.CHANGE_FULL); |
| 31675 |
this.session.$setFontMetrics(this.$fontMetrics); |
| 31676 |
|
| 31677 |
this.onChangeNewLineMode = this.onChangeNewLineMode.bind(this); |
| 31678 |
this.onChangeNewLineMode() |
| 31679 |
this.session.doc.on("changeNewLineMode", this.onChangeNewLineMode); |
| 31680 |
}; |
| 31681 |
this.updateLines = function(firstRow, lastRow, force) { |
| 31682 |
if (lastRow === undefined) |
| 31683 |
lastRow = Infinity; |
| 31684 |
|
| 31685 |
if (!this.$changedLines) { |
| 31686 |
this.$changedLines = { |
| 31687 |
firstRow: firstRow, |
| 31688 |
lastRow: lastRow |
| 31689 |
}; |
| 31690 |
} |
| 31691 |
else { |
| 31692 |
if (this.$changedLines.firstRow > firstRow) |
| 31693 |
this.$changedLines.firstRow = firstRow; |
| 31694 |
|
| 31695 |
if (this.$changedLines.lastRow < lastRow) |
| 31696 |
this.$changedLines.lastRow = lastRow; |
| 31697 |
} |
| 31698 |
if (this.$changedLines.lastRow < this.layerConfig.firstRow) { |
| 31699 |
if (force) |
| 31700 |
this.$changedLines.lastRow = this.layerConfig.lastRow; |
| 31701 |
else |
| 31702 |
return; |
| 31703 |
} |
| 31704 |
if (this.$changedLines.firstRow > this.layerConfig.lastRow) |
| 31705 |
return; |
| 31706 |
this.$loop.schedule(this.CHANGE_LINES); |
| 31707 |
}; |
| 31708 |
|
| 31709 |
this.onChangeNewLineMode = function() { |
| 31710 |
this.$loop.schedule(this.CHANGE_TEXT); |
| 31711 |
this.$textLayer.$updateEolChar(); |
| 31712 |
}; |
| 31713 |
|
| 31714 |
this.onChangeTabSize = function() { |
| 31715 |
this.$loop.schedule(this.CHANGE_TEXT | this.CHANGE_MARKER); |
| 31716 |
this.$textLayer.onChangeTabSize(); |
| 31717 |
}; |
| 31718 |
this.updateText = function() { |
| 31719 |
this.$loop.schedule(this.CHANGE_TEXT); |
| 31720 |
}; |
| 31721 |
this.updateFull = function(force) { |
| 31722 |
if (force) |
| 31723 |
this.$renderChanges(this.CHANGE_FULL, true); |
| 31724 |
else |
| 31725 |
this.$loop.schedule(this.CHANGE_FULL); |
| 31726 |
}; |
| 31727 |
this.updateFontSize = function() { |
| 31728 |
this.$textLayer.checkForSizeChanges(); |
| 31729 |
}; |
| 31730 |
|
| 31731 |
this.$changes = 0; |
| 31732 |
this.$updateSizeAsync = function() { |
| 31733 |
if (this.$loop.pending) |
| 31734 |
this.$size.$dirty = true; |
| 31735 |
else |
| 31736 |
this.onResize(); |
| 31737 |
}; |
| 31738 |
this.onResize = function(force, gutterWidth, width, height) { |
| 31739 |
if (this.resizing > 2) |
| 31740 |
return; |
| 31741 |
else if (this.resizing > 0) |
| 31742 |
this.resizing++; |
| 31743 |
else |
| 31744 |
this.resizing = force ? 1 : 0; |
| 31745 |
var el = this.container; |
| 31746 |
if (!height) |
| 31747 |
height = el.clientHeight || el.scrollHeight; |
| 31748 |
if (!width) |
| 31749 |
width = el.clientWidth || el.scrollWidth; |
| 31750 |
var changes = this.$updateCachedSize(force, gutterWidth, width, height); |
| 31751 |
|
| 31752 |
|
| 31753 |
if (!this.$size.scrollerHeight || (!width && !height)) |
| 31754 |
return this.resizing = 0; |
| 31755 |
|
| 31756 |
if (force) |
| 31757 |
this.$gutterLayer.$padding = null; |
| 31758 |
|
| 31759 |
if (force) |
| 31760 |
this.$renderChanges(changes | this.$changes, true); |
| 31761 |
else |
| 31762 |
this.$loop.schedule(changes | this.$changes); |
| 31763 |
|
| 31764 |
if (this.resizing) |
| 31765 |
this.resizing = 0; |
| 31766 |
this.scrollBarV.scrollLeft = this.scrollBarV.scrollTop = null; |
| 31767 |
}; |
| 31768 |
|
| 31769 |
this.$updateCachedSize = function(force, gutterWidth, width, height) { |
| 31770 |
height -= (this.$extraHeight || 0); |
| 31771 |
var changes = 0; |
| 31772 |
var size = this.$size; |
| 31773 |
var oldSize = { |
| 31774 |
width: size.width, |
| 31775 |
height: size.height, |
| 31776 |
scrollerHeight: size.scrollerHeight, |
| 31777 |
scrollerWidth: size.scrollerWidth |
| 31778 |
}; |
| 31779 |
if (height && (force || size.height != height)) { |
| 31780 |
size.height = height; |
| 31781 |
changes |= this.CHANGE_SIZE; |
| 31782 |
|
| 31783 |
size.scrollerHeight = size.height; |
| 31784 |
if (this.$horizScroll) |
| 31785 |
size.scrollerHeight -= this.scrollBarH.getHeight(); |
| 31786 |
this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px"; |
| 31787 |
|
| 31788 |
changes = changes | this.CHANGE_SCROLL; |
| 31789 |
} |
| 31790 |
|
| 31791 |
if (width && (force || size.width != width)) { |
| 31792 |
changes |= this.CHANGE_SIZE; |
| 31793 |
size.width = width; |
| 31794 |
|
| 31795 |
if (gutterWidth == null) |
| 31796 |
gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0; |
| 31797 |
|
| 31798 |
this.gutterWidth = gutterWidth; |
| 31799 |
|
| 31800 |
this.scrollBarH.element.style.left = |
| 31801 |
this.scroller.style.left = gutterWidth + "px"; |
| 31802 |
size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth()); |
| 31803 |
|
| 31804 |
this.scrollBarH.element.style.right = |
| 31805 |
this.scroller.style.right = this.scrollBarV.getWidth() + "px"; |
| 31806 |
this.scroller.style.bottom = this.scrollBarH.getHeight() + "px"; |
| 31807 |
|
| 31808 |
if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) |
| 31809 |
changes |= this.CHANGE_FULL; |
| 31810 |
} |
| 31811 |
|
| 31812 |
size.$dirty = !width || !height; |
| 31813 |
|
| 31814 |
if (changes) |
| 31815 |
this._signal("resize", oldSize); |
| 31816 |
|
| 31817 |
return changes; |
| 31818 |
}; |
| 31819 |
|
| 31820 |
this.onGutterResize = function() { |
| 31821 |
var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0; |
| 31822 |
if (gutterWidth != this.gutterWidth) |
| 31823 |
this.$changes |= this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height); |
| 31824 |
|
| 31825 |
if (this.session.getUseWrapMode() && this.adjustWrapLimit()) { |
| 31826 |
this.$loop.schedule(this.CHANGE_FULL); |
| 31827 |
} else if (this.$size.$dirty) { |
| 31828 |
this.$loop.schedule(this.CHANGE_FULL); |
| 31829 |
} else { |
| 31830 |
this.$computeLayerConfig(); |
| 31831 |
this.$loop.schedule(this.CHANGE_MARKER); |
| 31832 |
} |
| 31833 |
}; |
| 31834 |
this.adjustWrapLimit = function() { |
| 31835 |
var availableWidth = this.$size.scrollerWidth - this.$padding * 2; |
| 31836 |
var limit = Math.floor(availableWidth / this.characterWidth); |
| 31837 |
return this.session.adjustWrapLimit(limit, this.$showPrintMargin && this.$printMarginColumn); |
| 31838 |
}; |
| 31839 |
this.setAnimatedScroll = function(shouldAnimate){ |
| 31840 |
this.setOption("animatedScroll", shouldAnimate); |
| 31841 |
}; |
| 31842 |
this.getAnimatedScroll = function() { |
| 31843 |
return this.$animatedScroll; |
| 31844 |
}; |
| 31845 |
this.setShowInvisibles = function(showInvisibles) { |
| 31846 |
this.setOption("showInvisibles", showInvisibles); |
| 31847 |
}; |
| 31848 |
this.getShowInvisibles = function() { |
| 31849 |
return this.getOption("showInvisibles"); |
| 31850 |
}; |
| 31851 |
this.getDisplayIndentGuides = function() { |
| 31852 |
return this.getOption("displayIndentGuides"); |
| 31853 |
}; |
| 31854 |
|
| 31855 |
this.setDisplayIndentGuides = function(display) { |
| 31856 |
this.setOption("displayIndentGuides", display); |
| 31857 |
}; |
| 31858 |
this.setShowPrintMargin = function(showPrintMargin) { |
| 31859 |
this.setOption("showPrintMargin", showPrintMargin); |
| 31860 |
}; |
| 31861 |
this.getShowPrintMargin = function() { |
| 31862 |
return this.getOption("showPrintMargin"); |
| 31863 |
}; |
| 31864 |
this.setPrintMarginColumn = function(showPrintMargin) { |
| 31865 |
this.setOption("printMarginColumn", showPrintMargin); |
| 31866 |
}; |
| 31867 |
this.getPrintMarginColumn = function() { |
| 31868 |
return this.getOption("printMarginColumn"); |
| 31869 |
}; |
| 31870 |
this.getShowGutter = function(){ |
| 31871 |
return this.getOption("showGutter"); |
| 31872 |
}; |
| 31873 |
this.setShowGutter = function(show){ |
| 31874 |
return this.setOption("showGutter", show); |
| 31875 |
}; |
| 31876 |
|
| 31877 |
this.getFadeFoldWidgets = function(){ |
| 31878 |
return this.getOption("fadeFoldWidgets") |
| 31879 |
}; |
| 31880 |
|
| 31881 |
this.setFadeFoldWidgets = function(show) { |
| 31882 |
this.setOption("fadeFoldWidgets", show); |
| 31883 |
}; |
| 31884 |
|
| 31885 |
this.setHighlightGutterLine = function(shouldHighlight) { |
| 31886 |
this.setOption("highlightGutterLine", shouldHighlight); |
| 31887 |
}; |
| 31888 |
|
| 31889 |
this.getHighlightGutterLine = function() { |
| 31890 |
return this.getOption("highlightGutterLine"); |
| 31891 |
}; |
| 31892 |
|
| 31893 |
this.$updateGutterLineHighlight = function() { |
| 31894 |
var pos = this.$cursorLayer.$pixelPos; |
| 31895 |
var height = this.layerConfig.lineHeight; |
| 31896 |
if (this.session.getUseWrapMode()) { |
| 31897 |
var cursor = this.session.selection.getCursor(); |
| 31898 |
cursor.column = 0; |
| 31899 |
pos = this.$cursorLayer.getPixelPosition(cursor, true); |
| 31900 |
height *= this.session.getRowLength(cursor.row); |
| 31901 |
} |
| 31902 |
this.$gutterLineHighlight.style.top = pos.top - this.layerConfig.offset + "px"; |
| 31903 |
this.$gutterLineHighlight.style.height = height + "px"; |
| 31904 |
}; |
| 31905 |
|
| 31906 |
this.$updatePrintMargin = function() { |
| 31907 |
if (!this.$showPrintMargin && !this.$printMarginEl) |
| 31908 |
return; |
| 31909 |
|
| 31910 |
if (!this.$printMarginEl) { |
| 31911 |
var containerEl = dom.createElement("div"); |
| 31912 |
containerEl.className = "ace_layer ace_print-margin-layer"; |
| 31913 |
this.$printMarginEl = dom.createElement("div"); |
| 31914 |
this.$printMarginEl.className = "ace_print-margin"; |
| 31915 |
containerEl.appendChild(this.$printMarginEl); |
| 31916 |
this.content.insertBefore(containerEl, this.content.firstChild); |
| 31917 |
} |
| 31918 |
|
| 31919 |
var style = this.$printMarginEl.style; |
| 31920 |
style.left = ((this.characterWidth * this.$printMarginColumn) + this.$padding) + "px"; |
| 31921 |
style.visibility = this.$showPrintMargin ? "visible" : "hidden"; |
| 31922 |
|
| 31923 |
if (this.session && this.session.$wrap == -1) |
| 31924 |
this.adjustWrapLimit(); |
| 31925 |
}; |
| 31926 |
this.getContainerElement = function() { |
| 31927 |
return this.container; |
| 31928 |
}; |
| 31929 |
this.getMouseEventTarget = function() { |
| 31930 |
return this.scroller; |
| 31931 |
}; |
| 31932 |
this.getTextAreaContainer = function() { |
| 31933 |
return this.container; |
| 31934 |
}; |
| 31935 |
this.$moveTextAreaToCursor = function() { |
| 31936 |
if (!this.$keepTextAreaAtCursor) |
| 31937 |
return; |
| 31938 |
var config = this.layerConfig; |
| 31939 |
var posTop = this.$cursorLayer.$pixelPos.top; |
| 31940 |
var posLeft = this.$cursorLayer.$pixelPos.left; |
| 31941 |
posTop -= config.offset; |
| 31942 |
|
| 31943 |
var style = this.textarea.style; |
| 31944 |
var h = this.lineHeight; |
| 31945 |
if (posTop < 0 || posTop > config.height - h) { |
| 31946 |
style.top = style.left = "0"; |
| 31947 |
return; |
| 31948 |
} |
| 31949 |
|
| 31950 |
var w = this.characterWidth; |
| 31951 |
if (this.$composition) { |
| 31952 |
var val = this.textarea.value.replace(/^\x01+/, ""); |
| 31953 |
w *= (this.session.$getStringScreenWidth(val)[0]+2); |
| 31954 |
h += 2; |
| 31955 |
} |
| 31956 |
posLeft -= this.scrollLeft; |
| 31957 |
if (posLeft > this.$size.scrollerWidth - w) |
| 31958 |
posLeft = this.$size.scrollerWidth - w; |
| 31959 |
|
| 31960 |
posLeft += this.gutterWidth; |
| 31961 |
style.height = h + "px"; |
| 31962 |
style.width = w + "px"; |
| 31963 |
style.left = Math.min(posLeft, this.$size.scrollerWidth - w) + "px"; |
| 31964 |
style.top = Math.min(posTop, this.$size.height - h) + "px"; |
| 31965 |
}; |
| 31966 |
this.getFirstVisibleRow = function() { |
| 31967 |
return this.layerConfig.firstRow; |
| 31968 |
}; |
| 31969 |
this.getFirstFullyVisibleRow = function() { |
| 31970 |
return this.layerConfig.firstRow + (this.layerConfig.offset === 0 ? 0 : 1); |
| 31971 |
}; |
| 31972 |
this.getLastFullyVisibleRow = function() { |
| 31973 |
var config = this.layerConfig; |
| 31974 |
var lastRow = config.lastRow |
| 31975 |
var top = this.session.documentToScreenRow(lastRow, 0) * config.lineHeight; |
| 31976 |
if (top - this.session.getScrollTop() > config.height - config.lineHeight) |
| 31977 |
return lastRow - 1; |
| 31978 |
return lastRow; |
| 31979 |
}; |
| 31980 |
this.getLastVisibleRow = function() { |
| 31981 |
return this.layerConfig.lastRow; |
| 31982 |
}; |
| 31983 |
|
| 31984 |
this.$padding = null; |
| 31985 |
this.setPadding = function(padding) { |
| 31986 |
this.$padding = padding; |
| 31987 |
this.$textLayer.setPadding(padding); |
| 31988 |
this.$cursorLayer.setPadding(padding); |
| 31989 |
this.$markerFront.setPadding(padding); |
| 31990 |
this.$markerBack.setPadding(padding); |
| 31991 |
this.$loop.schedule(this.CHANGE_FULL); |
| 31992 |
this.$updatePrintMargin(); |
| 31993 |
}; |
| 31994 |
|
| 31995 |
this.setScrollMargin = function(top, bottom, left, right) { |
| 31996 |
var sm = this.scrollMargin; |
| 31997 |
sm.top = top|0; |
| 31998 |
sm.bottom = bottom|0; |
| 31999 |
sm.right = right|0; |
| 32000 |
sm.left = left|0; |
| 32001 |
sm.v = sm.top + sm.bottom; |
| 32002 |
sm.h = sm.left + sm.right; |
| 32003 |
if (sm.top && this.scrollTop <= 0 && this.session) |
| 32004 |
this.session.setScrollTop(-sm.top); |
| 32005 |
this.updateFull(); |
| 32006 |
}; |
| 32007 |
this.getHScrollBarAlwaysVisible = function() { |
| 32008 |
return this.$hScrollBarAlwaysVisible; |
| 32009 |
}; |
| 32010 |
this.setHScrollBarAlwaysVisible = function(alwaysVisible) { |
| 32011 |
this.setOption("hScrollBarAlwaysVisible", alwaysVisible); |
| 32012 |
}; |
| 32013 |
this.getVScrollBarAlwaysVisible = function() { |
| 32014 |
return this.$vScrollBarAlwaysVisible; |
| 32015 |
}; |
| 32016 |
this.setVScrollBarAlwaysVisible = function(alwaysVisible) { |
| 32017 |
this.setOption("vScrollBarAlwaysVisible", alwaysVisible); |
| 32018 |
}; |
| 32019 |
|
| 32020 |
this.$updateScrollBarV = function() { |
| 32021 |
var scrollHeight = this.layerConfig.maxHeight; |
| 32022 |
var scrollerHeight = this.$size.scrollerHeight; |
| 32023 |
if (!this.$maxLines && this.$scrollPastEnd) { |
| 32024 |
scrollHeight -= (scrollerHeight - this.lineHeight) * this.$scrollPastEnd; |
| 32025 |
if (this.scrollTop > scrollHeight - scrollerHeight) { |
| 32026 |
scrollHeight = this.scrollTop + scrollerHeight; |
| 32027 |
this.scrollBarV.scrollTop = null; |
| 32028 |
} |
| 32029 |
} |
| 32030 |
this.scrollBarV.setScrollHeight(scrollHeight + this.scrollMargin.v); |
| 32031 |
this.scrollBarV.setScrollTop(this.scrollTop + this.scrollMargin.top); |
| 32032 |
}; |
| 32033 |
this.$updateScrollBarH = function() { |
| 32034 |
this.scrollBarH.setScrollWidth(this.layerConfig.width + 2 * this.$padding + this.scrollMargin.h); |
| 32035 |
this.scrollBarH.setScrollLeft(this.scrollLeft + this.scrollMargin.left); |
| 32036 |
}; |
| 32037 |
|
| 32038 |
this.$frozen = false; |
| 32039 |
this.freeze = function() { |
| 32040 |
this.$frozen = true; |
| 32041 |
}; |
| 32042 |
|
| 32043 |
this.unfreeze = function() { |
| 32044 |
this.$frozen = false; |
| 32045 |
}; |
| 32046 |
|
| 32047 |
this.$renderChanges = function(changes, force) { |
| 32048 |
if (this.$changes) { |
| 32049 |
changes |= this.$changes; |
| 32050 |
this.$changes = 0; |
| 32051 |
} |
| 32052 |
if ((!this.session || !this.container.offsetWidth || this.$frozen) || (!changes && !force)) { |
| 32053 |
this.$changes |= changes; |
| 32054 |
return; |
| 32055 |
} |
| 32056 |
if (this.$size.$dirty) { |
| 32057 |
this.$changes |= changes; |
| 32058 |
return this.onResize(true); |
| 32059 |
} |
| 32060 |
if (!this.lineHeight) { |
| 32061 |
this.$textLayer.checkForSizeChanges(); |
| 32062 |
} |
| 32063 |
|
| 32064 |
this._signal("beforeRender"); |
| 32065 |
var config = this.layerConfig; |
| 32066 |
if (changes & this.CHANGE_FULL || |
| 32067 |
changes & this.CHANGE_SIZE || |
| 32068 |
changes & this.CHANGE_TEXT || |
| 32069 |
changes & this.CHANGE_LINES || |
| 32070 |
changes & this.CHANGE_SCROLL || |
| 32071 |
changes & this.CHANGE_H_SCROLL |
| 32072 |
) { |
| 32073 |
changes |= this.$computeLayerConfig(); |
| 32074 |
if (config.firstRow != this.layerConfig.firstRow && config.firstRowScreen == this.layerConfig.firstRowScreen) { |
| 32075 |
var st = this.scrollTop + (config.firstRow - this.layerConfig.firstRow) * this.lineHeight; |
| 32076 |
if (st > 0) { |
| 32077 |
this.scrollTop = st; |
| 32078 |
changes = changes | this.CHANGE_SCROLL; |
| 32079 |
changes |= this.$computeLayerConfig(); |
| 32080 |
} |
| 32081 |
} |
| 32082 |
config = this.layerConfig; |
| 32083 |
this.$updateScrollBarV(); |
| 32084 |
if (changes & this.CHANGE_H_SCROLL) |
| 32085 |
this.$updateScrollBarH(); |
| 32086 |
this.$gutterLayer.element.style.marginTop = (-config.offset) + "px"; |
| 32087 |
this.content.style.marginTop = (-config.offset) + "px"; |
| 32088 |
this.content.style.width = config.width + 2 * this.$padding + "px"; |
| 32089 |
this.content.style.height = config.minHeight + "px"; |
| 32090 |
} |
| 32091 |
if (changes & this.CHANGE_H_SCROLL) { |
| 32092 |
this.content.style.marginLeft = -this.scrollLeft + "px"; |
| 32093 |
this.scroller.className = this.scrollLeft <= 0 ? "ace_scroller" : "ace_scroller ace_scroll-left"; |
| 32094 |
} |
| 32095 |
if (changes & this.CHANGE_FULL) { |
| 32096 |
this.$textLayer.update(config); |
| 32097 |
if (this.$showGutter) |
| 32098 |
this.$gutterLayer.update(config); |
| 32099 |
this.$markerBack.update(config); |
| 32100 |
this.$markerFront.update(config); |
| 32101 |
this.$cursorLayer.update(config); |
| 32102 |
this.$moveTextAreaToCursor(); |
| 32103 |
this.$highlightGutterLine && this.$updateGutterLineHighlight(); |
| 32104 |
this._signal("afterRender"); |
| 32105 |
return; |
| 32106 |
} |
| 32107 |
if (changes & this.CHANGE_SCROLL) { |
| 32108 |
if (changes & this.CHANGE_TEXT || changes & this.CHANGE_LINES) |
| 32109 |
this.$textLayer.update(config); |
| 32110 |
else |
| 32111 |
this.$textLayer.scrollLines(config); |
| 32112 |
|
| 32113 |
if (this.$showGutter) |
| 32114 |
this.$gutterLayer.update(config); |
| 32115 |
this.$markerBack.update(config); |
| 32116 |
this.$markerFront.update(config); |
| 32117 |
this.$cursorLayer.update(config); |
| 32118 |
this.$highlightGutterLine && this.$updateGutterLineHighlight(); |
| 32119 |
this.$moveTextAreaToCursor(); |
| 32120 |
this._signal("afterRender"); |
| 32121 |
return; |
| 32122 |
} |
| 32123 |
|
| 32124 |
if (changes & this.CHANGE_TEXT) { |
| 32125 |
this.$textLayer.update(config); |
| 32126 |
if (this.$showGutter) |
| 32127 |
this.$gutterLayer.update(config); |
| 32128 |
} |
| 32129 |
else if (changes & this.CHANGE_LINES) { |
| 32130 |
if (this.$updateLines() || (changes & this.CHANGE_GUTTER) && this.$showGutter) |
| 32131 |
this.$gutterLayer.update(config); |
| 32132 |
} |
| 32133 |
else if (changes & this.CHANGE_TEXT || changes & this.CHANGE_GUTTER) { |
| 32134 |
if (this.$showGutter) |
| 32135 |
this.$gutterLayer.update(config); |
| 32136 |
} |
| 32137 |
|
| 32138 |
if (changes & this.CHANGE_CURSOR) { |
| 32139 |
this.$cursorLayer.update(config); |
| 32140 |
this.$moveTextAreaToCursor(); |
| 32141 |
this.$highlightGutterLine && this.$updateGutterLineHighlight(); |
| 32142 |
} |
| 32143 |
|
| 32144 |
if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_FRONT)) { |
| 32145 |
this.$markerFront.update(config); |
| 32146 |
} |
| 32147 |
|
| 32148 |
if (changes & (this.CHANGE_MARKER | this.CHANGE_MARKER_BACK)) { |
| 32149 |
this.$markerBack.update(config); |
| 32150 |
} |
| 32151 |
|
| 32152 |
this._signal("afterRender"); |
| 32153 |
}; |
| 32154 |
|
| 32155 |
|
| 32156 |
this.$autosize = function() { |
| 32157 |
var height = this.session.getScreenLength() * this.lineHeight; |
| 32158 |
var maxHeight = this.$maxLines * this.lineHeight; |
| 32159 |
var desiredHeight = Math.max( |
| 32160 |
(this.$minLines||1) * this.lineHeight, |
| 32161 |
Math.min(maxHeight, height) |
| 32162 |
) + this.scrollMargin.v + (this.$extraHeight || 0); |
| 32163 |
if (this.$horizScroll) |
| 32164 |
desiredHeight += this.scrollBarH.getHeight(); |
| 32165 |
var vScroll = height > maxHeight; |
| 32166 |
|
| 32167 |
if (desiredHeight != this.desiredHeight || |
| 32168 |
this.$size.height != this.desiredHeight || vScroll != this.$vScroll) { |
| 32169 |
if (vScroll != this.$vScroll) { |
| 32170 |
this.$vScroll = vScroll; |
| 32171 |
this.scrollBarV.setVisible(vScroll); |
| 32172 |
} |
| 32173 |
|
| 32174 |
var w = this.container.clientWidth; |
| 32175 |
this.container.style.height = desiredHeight + "px"; |
| 32176 |
this.$updateCachedSize(true, this.$gutterWidth, w, desiredHeight); |
| 32177 |
this.desiredHeight = desiredHeight; |
| 32178 |
|
| 32179 |
this._signal("autosize"); |
| 32180 |
} |
| 32181 |
}; |
| 32182 |
|
| 32183 |
this.$computeLayerConfig = function() { |
| 32184 |
var session = this.session; |
| 32185 |
var size = this.$size; |
| 32186 |
|
| 32187 |
var hideScrollbars = size.height <= 2 * this.lineHeight; |
| 32188 |
var screenLines = this.session.getScreenLength(); |
| 32189 |
var maxHeight = screenLines * this.lineHeight; |
| 32190 |
|
| 32191 |
var longestLine = this.$getLongestLine(); |
| 32192 |
|
| 32193 |
var horizScroll = !hideScrollbars && (this.$hScrollBarAlwaysVisible || |
| 32194 |
size.scrollerWidth - longestLine - 2 * this.$padding < 0); |
| 32195 |
|
| 32196 |
var hScrollChanged = this.$horizScroll !== horizScroll; |
| 32197 |
if (hScrollChanged) { |
| 32198 |
this.$horizScroll = horizScroll; |
| 32199 |
this.scrollBarH.setVisible(horizScroll); |
| 32200 |
} |
| 32201 |
var vScrollBefore = this.$vScroll; // autosize can change vscroll value in which case we need to update longestLine |
| 32202 |
if (this.$maxLines && this.lineHeight > 1) |
| 32203 |
this.$autosize(); |
| 32204 |
|
| 32205 |
var offset = this.scrollTop % this.lineHeight; |
| 32206 |
var minHeight = size.scrollerHeight + this.lineHeight; |
| 32207 |
|
| 32208 |
var scrollPastEnd = !this.$maxLines && this.$scrollPastEnd |
| 32209 |
? (size.scrollerHeight - this.lineHeight) * this.$scrollPastEnd |
| 32210 |
: 0; |
| 32211 |
maxHeight += scrollPastEnd; |
| 32212 |
|
| 32213 |
var sm = this.scrollMargin; |
| 32214 |
this.session.setScrollTop(Math.max(-sm.top, |
| 32215 |
Math.min(this.scrollTop, maxHeight - size.scrollerHeight + sm.bottom))); |
| 32216 |
|
| 32217 |
this.session.setScrollLeft(Math.max(-sm.left, Math.min(this.scrollLeft, |
| 32218 |
longestLine + 2 * this.$padding - size.scrollerWidth + sm.right))); |
| 32219 |
|
| 32220 |
var vScroll = !hideScrollbars && (this.$vScrollBarAlwaysVisible || |
| 32221 |
size.scrollerHeight - maxHeight + scrollPastEnd < 0 || this.scrollTop > sm.top); |
| 32222 |
var vScrollChanged = vScrollBefore !== vScroll; |
| 32223 |
if (vScrollChanged) { |
| 32224 |
this.$vScroll = vScroll; |
| 32225 |
this.scrollBarV.setVisible(vScroll); |
| 32226 |
} |
| 32227 |
|
| 32228 |
var lineCount = Math.ceil(minHeight / this.lineHeight) - 1; |
| 32229 |
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight)); |
| 32230 |
var lastRow = firstRow + lineCount; |
| 32231 |
var firstRowScreen, firstRowHeight; |
| 32232 |
var lineHeight = this.lineHeight; |
| 32233 |
firstRow = session.screenToDocumentRow(firstRow, 0); |
| 32234 |
var foldLine = session.getFoldLine(firstRow); |
| 32235 |
if (foldLine) { |
| 32236 |
firstRow = foldLine.start.row; |
| 32237 |
} |
| 32238 |
|
| 32239 |
firstRowScreen = session.documentToScreenRow(firstRow, 0); |
| 32240 |
firstRowHeight = session.getRowLength(firstRow) * lineHeight; |
| 32241 |
|
| 32242 |
lastRow = Math.min(session.screenToDocumentRow(lastRow, 0), session.getLength() - 1); |
| 32243 |
minHeight = size.scrollerHeight + session.getRowLength(lastRow) * lineHeight + |
| 32244 |
firstRowHeight; |
| 32245 |
|
| 32246 |
offset = this.scrollTop - firstRowScreen * lineHeight; |
| 32247 |
|
| 32248 |
var changes = 0; |
| 32249 |
if (this.layerConfig.width != longestLine) |
| 32250 |
changes = this.CHANGE_H_SCROLL; |
| 32251 |
if (hScrollChanged || vScrollChanged) { |
| 32252 |
changes = this.$updateCachedSize(true, this.gutterWidth, size.width, size.height); |
| 32253 |
this._signal("scrollbarVisibilityChanged"); |
| 32254 |
if (vScrollChanged) |
| 32255 |
longestLine = this.$getLongestLine(); |
| 32256 |
} |
| 32257 |
|
| 32258 |
this.layerConfig = { |
| 32259 |
width : longestLine, |
| 32260 |
padding : this.$padding, |
| 32261 |
firstRow : firstRow, |
| 32262 |
firstRowScreen: firstRowScreen, |
| 32263 |
lastRow : lastRow, |
| 32264 |
lineHeight : lineHeight, |
| 32265 |
characterWidth : this.characterWidth, |
| 32266 |
minHeight : minHeight, |
| 32267 |
maxHeight : maxHeight, |
| 32268 |
offset : offset, |
| 32269 |
gutterOffset : Math.max(0, Math.ceil((offset + size.height - size.scrollerHeight) / lineHeight)), |
| 32270 |
height : this.$size.scrollerHeight |
| 32271 |
}; |
| 32272 |
|
| 32273 |
return changes; |
| 32274 |
}; |
| 32275 |
|
| 32276 |
this.$updateLines = function() { |
| 32277 |
var firstRow = this.$changedLines.firstRow; |
| 32278 |
var lastRow = this.$changedLines.lastRow; |
| 32279 |
this.$changedLines = null; |
| 32280 |
|
| 32281 |
var layerConfig = this.layerConfig; |
| 32282 |
|
| 32283 |
if (firstRow > layerConfig.lastRow + 1) { return; } |
| 32284 |
if (lastRow < layerConfig.firstRow) { return; } |
| 32285 |
if (lastRow === Infinity) { |
| 32286 |
if (this.$showGutter) |
| 32287 |
this.$gutterLayer.update(layerConfig); |
| 32288 |
this.$textLayer.update(layerConfig); |
| 32289 |
return; |
| 32290 |
} |
| 32291 |
this.$textLayer.updateLines(layerConfig, firstRow, lastRow); |
| 32292 |
return true; |
| 32293 |
}; |
| 32294 |
|
| 32295 |
this.$getLongestLine = function() { |
| 32296 |
var charCount = this.session.getScreenWidth(); |
| 32297 |
if (this.showInvisibles && !this.session.$useWrapMode) |
| 32298 |
charCount += 1; |
| 32299 |
|
| 32300 |
return Math.max(this.$size.scrollerWidth - 2 * this.$padding, Math.round(charCount * this.characterWidth)); |
| 32301 |
}; |
| 32302 |
this.updateFrontMarkers = function() { |
| 32303 |
this.$markerFront.setMarkers(this.session.getMarkers(true)); |
| 32304 |
this.$loop.schedule(this.CHANGE_MARKER_FRONT); |
| 32305 |
}; |
| 32306 |
this.updateBackMarkers = function() { |
| 32307 |
this.$markerBack.setMarkers(this.session.getMarkers()); |
| 32308 |
this.$loop.schedule(this.CHANGE_MARKER_BACK); |
| 32309 |
}; |
| 32310 |
this.addGutterDecoration = function(row, className){ |
| 32311 |
this.$gutterLayer.addGutterDecoration(row, className); |
| 32312 |
}; |
| 32313 |
this.removeGutterDecoration = function(row, className){ |
| 32314 |
this.$gutterLayer.removeGutterDecoration(row, className); |
| 32315 |
}; |
| 32316 |
this.updateBreakpoints = function(rows) { |
| 32317 |
this.$loop.schedule(this.CHANGE_GUTTER); |
| 32318 |
}; |
| 32319 |
this.setAnnotations = function(annotations) { |
| 32320 |
this.$gutterLayer.setAnnotations(annotations); |
| 32321 |
this.$loop.schedule(this.CHANGE_GUTTER); |
| 32322 |
}; |
| 32323 |
this.updateCursor = function() { |
| 32324 |
this.$loop.schedule(this.CHANGE_CURSOR); |
| 32325 |
}; |
| 32326 |
this.hideCursor = function() { |
| 32327 |
this.$cursorLayer.hideCursor(); |
| 32328 |
}; |
| 32329 |
this.showCursor = function() { |
| 32330 |
this.$cursorLayer.showCursor(); |
| 32331 |
}; |
| 32332 |
|
| 32333 |
this.scrollSelectionIntoView = function(anchor, lead, offset) { |
| 32334 |
this.scrollCursorIntoView(anchor, offset); |
| 32335 |
this.scrollCursorIntoView(lead, offset); |
| 32336 |
}; |
| 32337 |
this.scrollCursorIntoView = function(cursor, offset, $viewMargin) { |
| 32338 |
if (this.$size.scrollerHeight === 0) |
| 32339 |
return; |
| 32340 |
|
| 32341 |
var pos = this.$cursorLayer.getPixelPosition(cursor); |
| 32342 |
|
| 32343 |
var left = pos.left; |
| 32344 |
var top = pos.top; |
| 32345 |
|
| 32346 |
var topMargin = $viewMargin && $viewMargin.top || 0; |
| 32347 |
var bottomMargin = $viewMargin && $viewMargin.bottom || 0; |
| 32348 |
|
| 32349 |
var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop; |
| 32350 |
|
| 32351 |
if (scrollTop + topMargin > top) { |
| 32352 |
if (offset && scrollTop + topMargin > top + this.lineHeight) |
| 32353 |
top -= offset * this.$size.scrollerHeight; |
| 32354 |
if (top === 0) |
| 32355 |
top = -this.scrollMargin.top; |
| 32356 |
this.session.setScrollTop(top); |
| 32357 |
} else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) { |
| 32358 |
if (offset && scrollTop + this.$size.scrollerHeight - bottomMargin < top - this.lineHeight) |
| 32359 |
top += offset * this.$size.scrollerHeight; |
| 32360 |
this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight); |
| 32361 |
} |
| 32362 |
|
| 32363 |
var scrollLeft = this.scrollLeft; |
| 32364 |
|
| 32365 |
if (scrollLeft > left) { |
| 32366 |
if (left < this.$padding + 2 * this.layerConfig.characterWidth) |
| 32367 |
left = -this.scrollMargin.left; |
| 32368 |
this.session.setScrollLeft(left); |
| 32369 |
} else if (scrollLeft + this.$size.scrollerWidth < left + this.characterWidth) { |
| 32370 |
this.session.setScrollLeft(Math.round(left + this.characterWidth - this.$size.scrollerWidth)); |
| 32371 |
} else if (scrollLeft <= this.$padding && left - scrollLeft < this.characterWidth) { |
| 32372 |
this.session.setScrollLeft(0); |
| 32373 |
} |
| 32374 |
}; |
| 32375 |
this.getScrollTop = function() { |
| 32376 |
return this.session.getScrollTop(); |
| 32377 |
}; |
| 32378 |
this.getScrollLeft = function() { |
| 32379 |
return this.session.getScrollLeft(); |
| 32380 |
}; |
| 32381 |
this.getScrollTopRow = function() { |
| 32382 |
return this.scrollTop / this.lineHeight; |
| 32383 |
}; |
| 32384 |
this.getScrollBottomRow = function() { |
| 32385 |
return Math.max(0, Math.floor((this.scrollTop + this.$size.scrollerHeight) / this.lineHeight) - 1); |
| 32386 |
}; |
| 32387 |
this.scrollToRow = function(row) { |
| 32388 |
this.session.setScrollTop(row * this.lineHeight); |
| 32389 |
}; |
| 32390 |
|
| 32391 |
this.alignCursor = function(cursor, alignment) { |
| 32392 |
if (typeof cursor == "number") |
| 32393 |
cursor = {row: cursor, column: 0}; |
| 32394 |
|
| 32395 |
var pos = this.$cursorLayer.getPixelPosition(cursor); |
| 32396 |
var h = this.$size.scrollerHeight - this.lineHeight; |
| 32397 |
var offset = pos.top - h * (alignment || 0); |
| 32398 |
|
| 32399 |
this.session.setScrollTop(offset); |
| 32400 |
return offset; |
| 32401 |
}; |
| 32402 |
|
| 32403 |
this.STEPS = 8; |
| 32404 |
this.$calcSteps = function(fromValue, toValue){ |
| 32405 |
var i = 0; |
| 32406 |
var l = this.STEPS; |
| 32407 |
var steps = []; |
| 32408 |
|
| 32409 |
var func = function(t, x_min, dx) { |
| 32410 |
return dx * (Math.pow(t - 1, 3) + 1) + x_min; |
| 32411 |
}; |
| 32412 |
|
| 32413 |
for (i = 0; i < l; ++i) |
| 32414 |
steps.push(func(i / this.STEPS, fromValue, toValue - fromValue)); |
| 32415 |
|
| 32416 |
return steps; |
| 32417 |
}; |
| 32418 |
this.scrollToLine = function(line, center, animate, callback) { |
| 32419 |
var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); |
| 32420 |
var offset = pos.top; |
| 32421 |
if (center) |
| 32422 |
offset -= this.$size.scrollerHeight / 2; |
| 32423 |
|
| 32424 |
var initialScroll = this.scrollTop; |
| 32425 |
this.session.setScrollTop(offset); |
| 32426 |
if (animate !== false) |
| 32427 |
this.animateScrolling(initialScroll, callback); |
| 32428 |
}; |
| 32429 |
|
| 32430 |
this.animateScrolling = function(fromValue, callback) { |
| 32431 |
var toValue = this.scrollTop; |
| 32432 |
if (!this.$animatedScroll) |
| 32433 |
return; |
| 32434 |
var _self = this; |
| 32435 |
|
| 32436 |
if (fromValue == toValue) |
| 32437 |
return; |
| 32438 |
|
| 32439 |
if (this.$scrollAnimation) { |
| 32440 |
var oldSteps = this.$scrollAnimation.steps; |
| 32441 |
if (oldSteps.length) { |
| 32442 |
fromValue = oldSteps[0]; |
| 32443 |
if (fromValue == toValue) |
| 32444 |
return; |
| 32445 |
} |
| 32446 |
} |
| 32447 |
|
| 32448 |
var steps = _self.$calcSteps(fromValue, toValue); |
| 32449 |
this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps}; |
| 32450 |
|
| 32451 |
clearInterval(this.$timer); |
| 32452 |
|
| 32453 |
_self.session.setScrollTop(steps.shift()); |
| 32454 |
_self.session.$scrollTop = toValue; |
| 32455 |
this.$timer = setInterval(function() { |
| 32456 |
if (steps.length) { |
| 32457 |
_self.session.setScrollTop(steps.shift()); |
| 32458 |
_self.session.$scrollTop = toValue; |
| 32459 |
} else if (toValue != null) { |
| 32460 |
_self.session.$scrollTop = -1; |
| 32461 |
_self.session.setScrollTop(toValue); |
| 32462 |
toValue = null; |
| 32463 |
} else { |
| 32464 |
_self.$timer = clearInterval(_self.$timer); |
| 32465 |
_self.$scrollAnimation = null; |
| 32466 |
callback && callback(); |
| 32467 |
} |
| 32468 |
}, 10); |
| 32469 |
}; |
| 32470 |
this.scrollToY = function(scrollTop) { |
| 32471 |
if (this.scrollTop !== scrollTop) { |
| 32472 |
this.$loop.schedule(this.CHANGE_SCROLL); |
| 32473 |
this.scrollTop = scrollTop; |
| 32474 |
} |
| 32475 |
}; |
| 32476 |
this.scrollToX = function(scrollLeft) { |
| 32477 |
if (this.scrollLeft !== scrollLeft) |
| 32478 |
this.scrollLeft = scrollLeft; |
| 32479 |
this.$loop.schedule(this.CHANGE_H_SCROLL); |
| 32480 |
}; |
| 32481 |
this.scrollTo = function(x, y) { |
| 32482 |
this.session.setScrollTop(y); |
| 32483 |
this.session.setScrollLeft(y); |
| 32484 |
}; |
| 32485 |
this.scrollBy = function(deltaX, deltaY) { |
| 32486 |
deltaY && this.session.setScrollTop(this.session.getScrollTop() + deltaY); |
| 32487 |
deltaX && this.session.setScrollLeft(this.session.getScrollLeft() + deltaX); |
| 32488 |
}; |
| 32489 |
this.isScrollableBy = function(deltaX, deltaY) { |
| 32490 |
if (deltaY < 0 && this.session.getScrollTop() >= 1 - this.scrollMargin.top) |
| 32491 |
return true; |
| 32492 |
if (deltaY > 0 && this.session.getScrollTop() + this.$size.scrollerHeight |
| 32493 |
- this.layerConfig.maxHeight < -1 + this.scrollMargin.bottom) |
| 32494 |
return true; |
| 32495 |
if (deltaX < 0 && this.session.getScrollLeft() >= 1 - this.scrollMargin.left) |
| 32496 |
return true; |
| 32497 |
if (deltaX > 0 && this.session.getScrollLeft() + this.$size.scrollerWidth |
| 32498 |
- this.layerConfig.width < -1 + this.scrollMargin.right) |
| 32499 |
return true; |
| 32500 |
}; |
| 32501 |
|
| 32502 |
this.pixelToScreenCoordinates = function(x, y) { |
| 32503 |
var canvasPos = this.scroller.getBoundingClientRect(); |
| 32504 |
|
| 32505 |
var offset = (x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth; |
| 32506 |
var row = Math.floor((y + this.scrollTop - canvasPos.top) / this.lineHeight); |
| 32507 |
var col = Math.round(offset); |
| 32508 |
|
| 32509 |
return {row: row, column: col, side: offset - col > 0 ? 1 : -1}; |
| 32510 |
}; |
| 32511 |
|
| 32512 |
this.screenToTextCoordinates = function(x, y) { |
| 32513 |
var canvasPos = this.scroller.getBoundingClientRect(); |
| 32514 |
|
| 32515 |
var col = Math.round( |
| 32516 |
(x + this.scrollLeft - canvasPos.left - this.$padding) / this.characterWidth |
| 32517 |
); |
| 32518 |
|
| 32519 |
var row = (y + this.scrollTop - canvasPos.top) / this.lineHeight; |
| 32520 |
|
| 32521 |
return this.session.screenToDocumentPosition(row, Math.max(col, 0)); |
| 32522 |
}; |
| 32523 |
this.textToScreenCoordinates = function(row, column) { |
| 32524 |
var canvasPos = this.scroller.getBoundingClientRect(); |
| 32525 |
var pos = this.session.documentToScreenPosition(row, column); |
| 32526 |
|
| 32527 |
var x = this.$padding + Math.round(pos.column * this.characterWidth); |
| 32528 |
var y = pos.row * this.lineHeight; |
| 32529 |
|
| 32530 |
return { |
| 32531 |
pageX: canvasPos.left + x - this.scrollLeft, |
| 32532 |
pageY: canvasPos.top + y - this.scrollTop |
| 32533 |
}; |
| 32534 |
}; |
| 32535 |
this.visualizeFocus = function() { |
| 32536 |
dom.addCssClass(this.container, "ace_focus"); |
| 32537 |
}; |
| 32538 |
this.visualizeBlur = function() { |
| 32539 |
dom.removeCssClass(this.container, "ace_focus"); |
| 32540 |
}; |
| 32541 |
this.showComposition = function(position) { |
| 32542 |
if (!this.$composition) |
| 32543 |
this.$composition = { |
| 32544 |
keepTextAreaAtCursor: this.$keepTextAreaAtCursor, |
| 32545 |
cssText: this.textarea.style.cssText |
| 32546 |
}; |
| 32547 |
|
| 32548 |
this.$keepTextAreaAtCursor = true; |
| 32549 |
dom.addCssClass(this.textarea, "ace_composition"); |
| 32550 |
this.textarea.style.cssText = ""; |
| 32551 |
this.$moveTextAreaToCursor(); |
| 32552 |
}; |
| 32553 |
this.setCompositionText = function(text) { |
| 32554 |
this.$moveTextAreaToCursor(); |
| 32555 |
}; |
| 32556 |
this.hideComposition = function() { |
| 32557 |
if (!this.$composition) |
| 32558 |
return; |
| 32559 |
|
| 32560 |
dom.removeCssClass(this.textarea, "ace_composition"); |
| 32561 |
this.$keepTextAreaAtCursor = this.$composition.keepTextAreaAtCursor; |
| 32562 |
this.textarea.style.cssText = this.$composition.cssText; |
| 32563 |
this.$composition = null; |
| 32564 |
}; |
| 32565 |
this.setTheme = function(theme, cb) { |
| 32566 |
var _self = this; |
| 32567 |
this.$themeId = theme; |
| 32568 |
_self._dispatchEvent('themeChange',{theme:theme}); |
| 32569 |
|
| 32570 |
if (!theme || typeof theme == "string") { |
| 32571 |
var moduleName = theme || this.$options.theme.initialValue; |
| 32572 |
config.loadModule(["theme", moduleName], afterLoad); |
| 32573 |
} else { |
| 32574 |
afterLoad(theme); |
| 32575 |
} |
| 32576 |
|
| 32577 |
function afterLoad(module) { |
| 32578 |
if (_self.$themeId != theme) |
| 32579 |
return cb && cb(); |
| 32580 |
if (!module.cssClass) |
| 32581 |
return; |
| 32582 |
dom.importCssString( |
| 32583 |
module.cssText, |
| 32584 |
module.cssClass, |
| 32585 |
_self.container.ownerDocument |
| 32586 |
); |
| 32587 |
|
| 32588 |
if (_self.theme) |
| 32589 |
dom.removeCssClass(_self.container, _self.theme.cssClass); |
| 32590 |
|
| 32591 |
var padding = "padding" in module ? module.padding |
| 32592 |
: "padding" in (_self.theme || {}) ? 4 : _self.$padding; |
| 32593 |
if (_self.$padding && padding != _self.$padding) |
| 32594 |
_self.setPadding(padding); |
| 32595 |
_self.$theme = module.cssClass; |
| 32596 |
|
| 32597 |
_self.theme = module; |
| 32598 |
dom.addCssClass(_self.container, module.cssClass); |
| 32599 |
dom.setCssClass(_self.container, "ace_dark", module.isDark); |
| 32600 |
if (_self.$size) { |
| 32601 |
_self.$size.width = 0; |
| 32602 |
_self.$updateSizeAsync(); |
| 32603 |
} |
| 32604 |
|
| 32605 |
_self._dispatchEvent('themeLoaded', {theme:module}); |
| 32606 |
cb && cb(); |
| 32607 |
} |
| 32608 |
}; |
| 32609 |
this.getTheme = function() { |
| 32610 |
return this.$themeId; |
| 32611 |
}; |
| 32612 |
this.setStyle = function(style, include) { |
| 32613 |
dom.setCssClass(this.container, style, include !== false); |
| 32614 |
}; |
| 32615 |
this.unsetStyle = function(style) { |
| 32616 |
dom.removeCssClass(this.container, style); |
| 32617 |
}; |
| 32618 |
|
| 32619 |
this.setCursorStyle = function(style) { |
| 32620 |
if (this.scroller.style.cursor != style) |
| 32621 |
this.scroller.style.cursor = style; |
| 32622 |
}; |
| 32623 |
this.setMouseCursor = function(cursorStyle) { |
| 32624 |
this.scroller.style.cursor = cursorStyle; |
| 32625 |
}; |
| 32626 |
this.destroy = function() { |
| 32627 |
this.$textLayer.destroy(); |
| 32628 |
this.$cursorLayer.destroy(); |
| 32629 |
}; |
| 32630 |
|
| 32631 |
}).call(VirtualRenderer.prototype); |
| 32632 |
|
| 32633 |
|
| 32634 |
config.defineOptions(VirtualRenderer.prototype, "renderer", { |
| 32635 |
animatedScroll: {initialValue: false}, |
| 32636 |
showInvisibles: { |
| 32637 |
set: function(value) { |
| 32638 |
if (this.$textLayer.setShowInvisibles(value)) |
| 32639 |
this.$loop.schedule(this.CHANGE_TEXT); |
| 32640 |
}, |
| 32641 |
initialValue: false |
| 32642 |
}, |
| 32643 |
showPrintMargin: { |
| 32644 |
set: function() { this.$updatePrintMargin(); }, |
| 32645 |
initialValue: true |
| 32646 |
}, |
| 32647 |
printMarginColumn: { |
| 32648 |
set: function() { this.$updatePrintMargin(); }, |
| 32649 |
initialValue: 80 |
| 32650 |
}, |
| 32651 |
printMargin: { |
| 32652 |
set: function(val) { |
| 32653 |
if (typeof val == "number") |
| 32654 |
this.$printMarginColumn = val; |
| 32655 |
this.$showPrintMargin = !!val; |
| 32656 |
this.$updatePrintMargin(); |
| 32657 |
}, |
| 32658 |
get: function() { |
| 32659 |
return this.$showPrintMargin && this.$printMarginColumn; |
| 32660 |
} |
| 32661 |
}, |
| 32662 |
showGutter: { |
| 32663 |
set: function(show){ |
| 32664 |
this.$gutter.style.display = show ? "block" : "none"; |
| 32665 |
this.$loop.schedule(this.CHANGE_FULL); |
| 32666 |
this.onGutterResize(); |
| 32667 |
}, |
| 32668 |
initialValue: true |
| 32669 |
}, |
| 32670 |
fadeFoldWidgets: { |
| 32671 |
set: function(show) { |
| 32672 |
dom.setCssClass(this.$gutter, "ace_fade-fold-widgets", show); |
| 32673 |
}, |
| 32674 |
initialValue: false |
| 32675 |
}, |
| 32676 |
showFoldWidgets: { |
| 32677 |
set: function(show) {this.$gutterLayer.setShowFoldWidgets(show)}, |
| 32678 |
initialValue: true |
| 32679 |
}, |
| 32680 |
showLineNumbers: { |
| 32681 |
set: function(show) { |
| 32682 |
this.$gutterLayer.setShowLineNumbers(show); |
| 32683 |
this.$loop.schedule(this.CHANGE_GUTTER); |
| 32684 |
}, |
| 32685 |
initialValue: true |
| 32686 |
}, |
| 32687 |
displayIndentGuides: { |
| 32688 |
set: function(show) { |
| 32689 |
if (this.$textLayer.setDisplayIndentGuides(show)) |
| 32690 |
this.$loop.schedule(this.CHANGE_TEXT); |
| 32691 |
}, |
| 32692 |
initialValue: true |
| 32693 |
}, |
| 32694 |
highlightGutterLine: { |
| 32695 |
set: function(shouldHighlight) { |
| 32696 |
if (!this.$gutterLineHighlight) { |
| 32697 |
this.$gutterLineHighlight = dom.createElement("div"); |
| 32698 |
this.$gutterLineHighlight.className = "ace_gutter-active-line"; |
| 32699 |
this.$gutter.appendChild(this.$gutterLineHighlight); |
| 32700 |
return; |
| 32701 |
} |
| 32702 |
|
| 32703 |
this.$gutterLineHighlight.style.display = shouldHighlight ? "" : "none"; |
| 32704 |
if (this.$cursorLayer.$pixelPos) |
| 32705 |
this.$updateGutterLineHighlight(); |
| 32706 |
}, |
| 32707 |
initialValue: false, |
| 32708 |
value: true |
| 32709 |
}, |
| 32710 |
hScrollBarAlwaysVisible: { |
| 32711 |
set: function(val) { |
| 32712 |
if (!this.$hScrollBarAlwaysVisible || !this.$horizScroll) |
| 32713 |
this.$loop.schedule(this.CHANGE_SCROLL); |
| 32714 |
}, |
| 32715 |
initialValue: false |
| 32716 |
}, |
| 32717 |
vScrollBarAlwaysVisible: { |
| 32718 |
set: function(val) { |
| 32719 |
if (!this.$vScrollBarAlwaysVisible || !this.$vScroll) |
| 32720 |
this.$loop.schedule(this.CHANGE_SCROLL); |
| 32721 |
}, |
| 32722 |
initialValue: false |
| 32723 |
}, |
| 32724 |
fontSize: { |
| 32725 |
set: function(size) { |
| 32726 |
if (typeof size == "number") |
| 32727 |
size = size + "px"; |
| 32728 |
this.container.style.fontSize = size; |
| 32729 |
this.updateFontSize(); |
| 32730 |
}, |
| 32731 |
initialValue: 12 |
| 32732 |
}, |
| 32733 |
fontFamily: { |
| 32734 |
set: function(name) { |
| 32735 |
this.container.style.fontFamily = name; |
| 32736 |
this.updateFontSize(); |
| 32737 |
} |
| 32738 |
}, |
| 32739 |
maxLines: { |
| 32740 |
set: function(val) { |
| 32741 |
this.updateFull(); |
| 32742 |
} |
| 32743 |
}, |
| 32744 |
minLines: { |
| 32745 |
set: function(val) { |
| 32746 |
this.updateFull(); |
| 32747 |
} |
| 32748 |
}, |
| 32749 |
scrollPastEnd: { |
| 32750 |
set: function(val) { |
| 32751 |
val = +val || 0; |
| 32752 |
if (this.$scrollPastEnd == val) |
| 32753 |
return; |
| 32754 |
this.$scrollPastEnd = val; |
| 32755 |
this.$loop.schedule(this.CHANGE_SCROLL); |
| 32756 |
}, |
| 32757 |
initialValue: 0, |
| 32758 |
handlesSet: true |
| 32759 |
}, |
| 32760 |
fixedWidthGutter: { |
| 32761 |
set: function(val) { |
| 32762 |
this.$gutterLayer.$fixedWidth = !!val; |
| 32763 |
this.$loop.schedule(this.CHANGE_GUTTER); |
| 32764 |
} |
| 32765 |
}, |
| 32766 |
theme: { |
| 32767 |
set: function(val) { this.setTheme(val) }, |
| 32768 |
get: function() { return this.$themeId || this.theme; }, |
| 32769 |
initialValue: "./theme/textmate", |
| 32770 |
handlesSet: true |
| 32771 |
} |
| 32772 |
}); |
| 32773 |
|
| 32774 |
exports.VirtualRenderer = VirtualRenderer; |
| 32775 |
}); |
| 32776 |
|
| 32777 |
ace.define("ace/worker/worker_client",["require","exports","module","ace/lib/oop","ace/lib/net","ace/lib/event_emitter","ace/config"], function(acequire, exports, module) { |
| 32778 |
"use strict"; |
| 32779 |
|
| 32780 |
var oop = acequire("../lib/oop"); |
| 32781 |
var net = acequire("../lib/net"); |
| 32782 |
var EventEmitter = acequire("../lib/event_emitter").EventEmitter; |
| 32783 |
var config = acequire("../config"); |
| 32784 |
|
| 32785 |
var WorkerClient = function(topLevelNamespaces, mod, classname, workerUrl) { |
| 32786 |
this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this); |
| 32787 |
this.changeListener = this.changeListener.bind(this); |
| 32788 |
this.onMessage = this.onMessage.bind(this); |
| 32789 |
if (acequire.nameToUrl && !acequire.toUrl) |
| 32790 |
acequire.toUrl = acequire.nameToUrl; |
| 32791 |
|
| 32792 |
if (config.get("packaged") || !acequire.toUrl) { |
| 32793 |
workerUrl = workerUrl || config.moduleUrl(mod.id, "worker") |
| 32794 |
} else { |
| 32795 |
var normalizePath = this.$normalizePath; |
| 32796 |
workerUrl = workerUrl || normalizePath(acequire.toUrl("ace/worker/worker.js", null, "_")); |
| 32797 |
|
| 32798 |
var tlns = {}; |
| 32799 |
topLevelNamespaces.forEach(function(ns) { |
| 32800 |
tlns[ns] = normalizePath(acequire.toUrl(ns, null, "_").replace(/(\.js)?(\?.*)?$/, "")); |
| 32801 |
}); |
| 32802 |
} |
| 32803 |
|
| 32804 |
try { |
| 32805 |
var workerSrc = mod.src; |
| 32806 |
var Blob = __webpack_require__(66); |
| 32807 |
var blob = new Blob([ workerSrc ], { type: 'application/javascript' }); |
| 32808 |
var blobUrl = (window.URL || window.webkitURL).createObjectURL(blob); |
| 32809 |
|
| 32810 |
this.$worker = new Worker(blobUrl); |
| 32811 |
|
| 32812 |
} catch(e) { |
| 32813 |
if (e instanceof window.DOMException) { |
| 32814 |
var blob = this.$workerBlob(workerUrl); |
| 32815 |
var URL = window.URL || window.webkitURL; |
| 32816 |
var blobURL = URL.createObjectURL(blob); |
| 32817 |
|
| 32818 |
this.$worker = new Worker(blobURL); |
| 32819 |
URL.revokeObjectURL(blobURL); |
| 32820 |
} else { |
| 32821 |
throw e; |
| 32822 |
} |
| 32823 |
} |
| 32824 |
this.$worker.postMessage({ |
| 32825 |
init : true, |
| 32826 |
tlns : tlns, |
| 32827 |
module : mod.id, |
| 32828 |
classname : classname |
| 32829 |
}); |
| 32830 |
|
| 32831 |
this.callbackId = 1; |
| 32832 |
this.callbacks = {}; |
| 32833 |
|
| 32834 |
this.$worker.onmessage = this.onMessage; |
| 32835 |
}; |
| 32836 |
|
| 32837 |
(function(){ |
| 32838 |
|
| 32839 |
oop.implement(this, EventEmitter); |
| 32840 |
|
| 32841 |
this.onMessage = function(e) { |
| 32842 |
var msg = e.data; |
| 32843 |
switch(msg.type) { |
| 32844 |
case "event": |
| 32845 |
this._signal(msg.name, {data: msg.data}); |
| 32846 |
break; |
| 32847 |
case "call": |
| 32848 |
var callback = this.callbacks[msg.id]; |
| 32849 |
if (callback) { |
| 32850 |
callback(msg.data); |
| 32851 |
delete this.callbacks[msg.id]; |
| 32852 |
} |
| 32853 |
break; |
| 32854 |
case "error": |
| 32855 |
this.reportError(msg.data); |
| 32856 |
break; |
| 32857 |
case "log": |
| 32858 |
window.console && console.log && console.log.apply(console, msg.data); |
| 32859 |
break; |
| 32860 |
} |
| 32861 |
}; |
| 32862 |
|
| 32863 |
this.reportError = function(err) { |
| 32864 |
window.console && console.error && console.error(err); |
| 32865 |
}; |
| 32866 |
|
| 32867 |
this.$normalizePath = function(path) { |
| 32868 |
return net.qualifyURL(path); |
| 32869 |
}; |
| 32870 |
|
| 32871 |
this.terminate = function() { |
| 32872 |
this._signal("terminate", {}); |
| 32873 |
this.deltaQueue = null; |
| 32874 |
this.$worker.terminate(); |
| 32875 |
this.$worker = null; |
| 32876 |
if (this.$doc) |
| 32877 |
this.$doc.off("change", this.changeListener); |
| 32878 |
this.$doc = null; |
| 32879 |
}; |
| 32880 |
|
| 32881 |
this.send = function(cmd, args) { |
| 32882 |
this.$worker.postMessage({command: cmd, args: args}); |
| 32883 |
}; |
| 32884 |
|
| 32885 |
this.call = function(cmd, args, callback) { |
| 32886 |
if (callback) { |
| 32887 |
var id = this.callbackId++; |
| 32888 |
this.callbacks[id] = callback; |
| 32889 |
args.push(id); |
| 32890 |
} |
| 32891 |
this.send(cmd, args); |
| 32892 |
}; |
| 32893 |
|
| 32894 |
this.emit = function(event, data) { |
| 32895 |
try { |
| 32896 |
this.$worker.postMessage({event: event, data: {data: data.data}}); |
| 32897 |
} |
| 32898 |
catch(ex) { |
| 32899 |
console.error(ex.stack); |
| 32900 |
} |
| 32901 |
}; |
| 32902 |
|
| 32903 |
this.attachToDocument = function(doc) { |
| 32904 |
if(this.$doc) |
| 32905 |
this.terminate(); |
| 32906 |
|
| 32907 |
this.$doc = doc; |
| 32908 |
this.call("setValue", [doc.getValue()]); |
| 32909 |
doc.on("change", this.changeListener); |
| 32910 |
}; |
| 32911 |
|
| 32912 |
this.changeListener = function(delta) { |
| 32913 |
if (!this.deltaQueue) { |
| 32914 |
this.deltaQueue = []; |
| 32915 |
setTimeout(this.$sendDeltaQueue, 0); |
| 32916 |
} |
| 32917 |
if (delta.action == "insert") |
| 32918 |
this.deltaQueue.push(delta.start, delta.lines); |
| 32919 |
else |
| 32920 |
this.deltaQueue.push(delta.start, delta.end); |
| 32921 |
}; |
| 32922 |
|
| 32923 |
this.$sendDeltaQueue = function() { |
| 32924 |
var q = this.deltaQueue; |
| 32925 |
if (!q) return; |
| 32926 |
this.deltaQueue = null; |
| 32927 |
if (q.length > 50 && q.length > this.$doc.getLength() >> 1) { |
| 32928 |
this.call("setValue", [this.$doc.getValue()]); |
| 32929 |
} else |
| 32930 |
this.emit("change", {data: q}); |
| 32931 |
}; |
| 32932 |
|
| 32933 |
this.$workerBlob = function(workerUrl) { |
| 32934 |
var script = "importScripts('" + net.qualifyURL(workerUrl) + "');"; |
| 32935 |
try { |
| 32936 |
return new Blob([script], {"type": "application/javascript"}); |
| 32937 |
} catch (e) { // Backwards-compatibility |
| 32938 |
var BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder; |
| 32939 |
var blobBuilder = new BlobBuilder(); |
| 32940 |
blobBuilder.append(script); |
| 32941 |
return blobBuilder.getBlob("application/javascript"); |
| 32942 |
} |
| 32943 |
}; |
| 32944 |
|
| 32945 |
}).call(WorkerClient.prototype); |
| 32946 |
|
| 32947 |
|
| 32948 |
var UIWorkerClient = function(topLevelNamespaces, mod, classname) { |
| 32949 |
this.$sendDeltaQueue = this.$sendDeltaQueue.bind(this); |
| 32950 |
this.changeListener = this.changeListener.bind(this); |
| 32951 |
this.callbackId = 1; |
| 32952 |
this.callbacks = {}; |
| 32953 |
this.messageBuffer = []; |
| 32954 |
|
| 32955 |
var main = null; |
| 32956 |
var emitSync = false; |
| 32957 |
var sender = Object.create(EventEmitter); |
| 32958 |
var _self = this; |
| 32959 |
|
| 32960 |
this.$worker = {}; |
| 32961 |
this.$worker.terminate = function() {}; |
| 32962 |
this.$worker.postMessage = function(e) { |
| 32963 |
_self.messageBuffer.push(e); |
| 32964 |
if (main) { |
| 32965 |
if (emitSync) |
| 32966 |
setTimeout(processNext); |
| 32967 |
else |
| 32968 |
processNext(); |
| 32969 |
} |
| 32970 |
}; |
| 32971 |
this.setEmitSync = function(val) { emitSync = val }; |
| 32972 |
|
| 32973 |
var processNext = function() { |
| 32974 |
var msg = _self.messageBuffer.shift(); |
| 32975 |
if (msg.command) |
| 32976 |
main[msg.command].apply(main, msg.args); |
| 32977 |
else if (msg.event) |
| 32978 |
sender._signal(msg.event, msg.data); |
| 32979 |
}; |
| 32980 |
|
| 32981 |
sender.postMessage = function(msg) { |
| 32982 |
_self.onMessage({data: msg}); |
| 32983 |
}; |
| 32984 |
sender.callback = function(data, callbackId) { |
| 32985 |
this.postMessage({type: "call", id: callbackId, data: data}); |
| 32986 |
}; |
| 32987 |
sender.emit = function(name, data) { |
| 32988 |
this.postMessage({type: "event", name: name, data: data}); |
| 32989 |
}; |
| 32990 |
|
| 32991 |
config.loadModule(["worker", mod], function(Main) { |
| 32992 |
main = new Main[classname](sender); |
| 32993 |
while (_self.messageBuffer.length) |
| 32994 |
processNext(); |
| 32995 |
}); |
| 32996 |
}; |
| 32997 |
|
| 32998 |
UIWorkerClient.prototype = WorkerClient.prototype; |
| 32999 |
|
| 33000 |
exports.UIWorkerClient = UIWorkerClient; |
| 33001 |
exports.WorkerClient = WorkerClient; |
| 33002 |
|
| 33003 |
}); |
| 33004 |
|
| 33005 |
ace.define("ace/placeholder",["require","exports","module","ace/range","ace/lib/event_emitter","ace/lib/oop"], function(acequire, exports, module) { |
| 33006 |
"use strict"; |
| 33007 |
|
| 33008 |
var Range = acequire("./range").Range; |
| 33009 |
var EventEmitter = acequire("./lib/event_emitter").EventEmitter; |
| 33010 |
var oop = acequire("./lib/oop"); |
| 33011 |
|
| 33012 |
var PlaceHolder = function(session, length, pos, others, mainClass, othersClass) { |
| 33013 |
var _self = this; |
| 33014 |
this.length = length; |
| 33015 |
this.session = session; |
| 33016 |
this.doc = session.getDocument(); |
| 33017 |
this.mainClass = mainClass; |
| 33018 |
this.othersClass = othersClass; |
| 33019 |
this.$onUpdate = this.onUpdate.bind(this); |
| 33020 |
this.doc.on("change", this.$onUpdate); |
| 33021 |
this.$others = others; |
| 33022 |
|
| 33023 |
this.$onCursorChange = function() { |
| 33024 |
setTimeout(function() { |
| 33025 |
_self.onCursorChange(); |
| 33026 |
}); |
| 33027 |
}; |
| 33028 |
|
| 33029 |
this.$pos = pos; |
| 33030 |
var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1}; |
| 33031 |
this.$undoStackDepth = undoStack.length; |
| 33032 |
this.setup(); |
| 33033 |
|
| 33034 |
session.selection.on("changeCursor", this.$onCursorChange); |
| 33035 |
}; |
| 33036 |
|
| 33037 |
(function() { |
| 33038 |
|
| 33039 |
oop.implement(this, EventEmitter); |
| 33040 |
this.setup = function() { |
| 33041 |
var _self = this; |
| 33042 |
var doc = this.doc; |
| 33043 |
var session = this.session; |
| 33044 |
|
| 33045 |
this.selectionBefore = session.selection.toJSON(); |
| 33046 |
if (session.selection.inMultiSelectMode) |
| 33047 |
session.selection.toSingleRange(); |
| 33048 |
|
| 33049 |
this.pos = doc.createAnchor(this.$pos.row, this.$pos.column); |
| 33050 |
var pos = this.pos; |
| 33051 |
pos.$insertRight = true; |
| 33052 |
pos.detach(); |
| 33053 |
pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column + this.length), this.mainClass, null, false); |
| 33054 |
this.others = []; |
| 33055 |
this.$others.forEach(function(other) { |
| 33056 |
var anchor = doc.createAnchor(other.row, other.column); |
| 33057 |
anchor.$insertRight = true; |
| 33058 |
anchor.detach(); |
| 33059 |
_self.others.push(anchor); |
| 33060 |
}); |
| 33061 |
session.setUndoSelect(false); |
| 33062 |
}; |
| 33063 |
this.showOtherMarkers = function() { |
| 33064 |
if (this.othersActive) return; |
| 33065 |
var session = this.session; |
| 33066 |
var _self = this; |
| 33067 |
this.othersActive = true; |
| 33068 |
this.others.forEach(function(anchor) { |
| 33069 |
anchor.markerId = session.addMarker(new Range(anchor.row, anchor.column, anchor.row, anchor.column+_self.length), _self.othersClass, null, false); |
| 33070 |
}); |
| 33071 |
}; |
| 33072 |
this.hideOtherMarkers = function() { |
| 33073 |
if (!this.othersActive) return; |
| 33074 |
this.othersActive = false; |
| 33075 |
for (var i = 0; i < this.others.length; i++) { |
| 33076 |
this.session.removeMarker(this.others[i].markerId); |
| 33077 |
} |
| 33078 |
}; |
| 33079 |
this.onUpdate = function(delta) { |
| 33080 |
if (this.$updating) |
| 33081 |
return this.updateAnchors(delta); |
| 33082 |
|
| 33083 |
var range = delta; |
| 33084 |
if (range.start.row !== range.end.row) return; |
| 33085 |
if (range.start.row !== this.pos.row) return; |
| 33086 |
this.$updating = true; |
| 33087 |
var lengthDiff = delta.action === "insert" ? range.end.column - range.start.column : range.start.column - range.end.column; |
| 33088 |
var inMainRange = range.start.column >= this.pos.column && range.start.column <= this.pos.column + this.length + 1; |
| 33089 |
var distanceFromStart = range.start.column - this.pos.column; |
| 33090 |
|
| 33091 |
this.updateAnchors(delta); |
| 33092 |
|
| 33093 |
if (inMainRange) |
| 33094 |
this.length += lengthDiff; |
| 33095 |
|
| 33096 |
if (inMainRange && !this.session.$fromUndo) { |
| 33097 |
if (delta.action === 'insert') { |
| 33098 |
for (var i = this.others.length - 1; i >= 0; i--) { |
| 33099 |
var otherPos = this.others[i]; |
| 33100 |
var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart}; |
| 33101 |
this.doc.insertMergedLines(newPos, delta.lines); |
| 33102 |
} |
| 33103 |
} else if (delta.action === 'remove') { |
| 33104 |
for (var i = this.others.length - 1; i >= 0; i--) { |
| 33105 |
var otherPos = this.others[i]; |
| 33106 |
var newPos = {row: otherPos.row, column: otherPos.column + distanceFromStart}; |
| 33107 |
this.doc.remove(new Range(newPos.row, newPos.column, newPos.row, newPos.column - lengthDiff)); |
| 33108 |
} |
| 33109 |
} |
| 33110 |
} |
| 33111 |
|
| 33112 |
this.$updating = false; |
| 33113 |
this.updateMarkers(); |
| 33114 |
}; |
| 33115 |
|
| 33116 |
this.updateAnchors = function(delta) { |
| 33117 |
this.pos.onChange(delta); |
| 33118 |
for (var i = this.others.length; i--;) |
| 33119 |
this.others[i].onChange(delta); |
| 33120 |
this.updateMarkers(); |
| 33121 |
}; |
| 33122 |
|
| 33123 |
this.updateMarkers = function() { |
| 33124 |
if (this.$updating) |
| 33125 |
return; |
| 33126 |
var _self = this; |
| 33127 |
var session = this.session; |
| 33128 |
var updateMarker = function(pos, className) { |
| 33129 |
session.removeMarker(pos.markerId); |
| 33130 |
pos.markerId = session.addMarker(new Range(pos.row, pos.column, pos.row, pos.column+_self.length), className, null, false); |
| 33131 |
}; |
| 33132 |
updateMarker(this.pos, this.mainClass); |
| 33133 |
for (var i = this.others.length; i--;) |
| 33134 |
updateMarker(this.others[i], this.othersClass); |
| 33135 |
}; |
| 33136 |
|
| 33137 |
this.onCursorChange = function(event) { |
| 33138 |
if (this.$updating || !this.session) return; |
| 33139 |
var pos = this.session.selection.getCursor(); |
| 33140 |
if (pos.row === this.pos.row && pos.column >= this.pos.column && pos.column <= this.pos.column + this.length) { |
| 33141 |
this.showOtherMarkers(); |
| 33142 |
this._emit("cursorEnter", event); |
| 33143 |
} else { |
| 33144 |
this.hideOtherMarkers(); |
| 33145 |
this._emit("cursorLeave", event); |
| 33146 |
} |
| 33147 |
}; |
| 33148 |
this.detach = function() { |
| 33149 |
this.session.removeMarker(this.pos && this.pos.markerId); |
| 33150 |
this.hideOtherMarkers(); |
| 33151 |
this.doc.removeEventListener("change", this.$onUpdate); |
| 33152 |
this.session.selection.removeEventListener("changeCursor", this.$onCursorChange); |
| 33153 |
this.session.setUndoSelect(true); |
| 33154 |
this.session = null; |
| 33155 |
}; |
| 33156 |
this.cancel = function() { |
| 33157 |
if (this.$undoStackDepth === -1) |
| 33158 |
return; |
| 33159 |
var undoManager = this.session.getUndoManager(); |
| 33160 |
var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth; |
| 33161 |
for (var i = 0; i < undosRequired; i++) { |
| 33162 |
undoManager.undo(true); |
| 33163 |
} |
| 33164 |
if (this.selectionBefore) |
| 33165 |
this.session.selection.fromJSON(this.selectionBefore); |
| 33166 |
}; |
| 33167 |
}).call(PlaceHolder.prototype); |
| 33168 |
|
| 33169 |
|
| 33170 |
exports.PlaceHolder = PlaceHolder; |
| 33171 |
}); |
| 33172 |
|
| 33173 |
ace.define("ace/mouse/multi_select_handler",["require","exports","module","ace/lib/event","ace/lib/useragent"], function(acequire, exports, module) { |
| 33174 |
|
| 33175 |
var event = acequire("../lib/event"); |
| 33176 |
var useragent = acequire("../lib/useragent"); |
| 33177 |
function isSamePoint(p1, p2) { |
| 33178 |
return p1.row == p2.row && p1.column == p2.column; |
| 33179 |
} |
| 33180 |
|
| 33181 |
function onMouseDown(e) { |
| 33182 |
var ev = e.domEvent; |
| 33183 |
var alt = ev.altKey; |
| 33184 |
var shift = ev.shiftKey; |
| 33185 |
var ctrl = ev.ctrlKey; |
| 33186 |
var accel = e.getAccelKey(); |
| 33187 |
var button = e.getButton(); |
| 33188 |
|
| 33189 |
if (ctrl && useragent.isMac) |
| 33190 |
button = ev.button; |
| 33191 |
|
| 33192 |
if (e.editor.inMultiSelectMode && button == 2) { |
| 33193 |
e.editor.textInput.onContextMenu(e.domEvent); |
| 33194 |
return; |
| 33195 |
} |
| 33196 |
|
| 33197 |
if (!ctrl && !alt && !accel) { |
| 33198 |
if (button === 0 && e.editor.inMultiSelectMode) |
| 33199 |
e.editor.exitMultiSelectMode(); |
| 33200 |
return; |
| 33201 |
} |
| 33202 |
|
| 33203 |
if (button !== 0) |
| 33204 |
return; |
| 33205 |
|
| 33206 |
var editor = e.editor; |
| 33207 |
var selection = editor.selection; |
| 33208 |
var isMultiSelect = editor.inMultiSelectMode; |
| 33209 |
var pos = e.getDocumentPosition(); |
| 33210 |
var cursor = selection.getCursor(); |
| 33211 |
var inSelection = e.inSelection() || (selection.isEmpty() && isSamePoint(pos, cursor)); |
| 33212 |
|
| 33213 |
var mouseX = e.x, mouseY = e.y; |
| 33214 |
var onMouseSelection = function(e) { |
| 33215 |
mouseX = e.clientX; |
| 33216 |
mouseY = e.clientY; |
| 33217 |
}; |
| 33218 |
|
| 33219 |
var session = editor.session; |
| 33220 |
var screenAnchor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY); |
| 33221 |
var screenCursor = screenAnchor; |
| 33222 |
|
| 33223 |
var selectionMode; |
| 33224 |
if (editor.$mouseHandler.$enableJumpToDef) { |
| 33225 |
if (ctrl && alt || accel && alt) |
| 33226 |
selectionMode = shift ? "block" : "add"; |
| 33227 |
else if (alt && editor.$blockSelectEnabled) |
| 33228 |
selectionMode = "block"; |
| 33229 |
} else { |
| 33230 |
if (accel && !alt) { |
| 33231 |
selectionMode = "add"; |
| 33232 |
if (!isMultiSelect && shift) |
| 33233 |
return; |
| 33234 |
} else if (alt && editor.$blockSelectEnabled) { |
| 33235 |
selectionMode = "block"; |
| 33236 |
} |
| 33237 |
} |
| 33238 |
|
| 33239 |
if (selectionMode && useragent.isMac && ev.ctrlKey) { |
| 33240 |
editor.$mouseHandler.cancelContextMenu(); |
| 33241 |
} |
| 33242 |
|
| 33243 |
if (selectionMode == "add") { |
| 33244 |
if (!isMultiSelect && inSelection) |
| 33245 |
return; // dragging |
| 33246 |
|
| 33247 |
if (!isMultiSelect) { |
| 33248 |
var range = selection.toOrientedRange(); |
| 33249 |
editor.addSelectionMarker(range); |
| 33250 |
} |
| 33251 |
|
| 33252 |
var oldRange = selection.rangeList.rangeAtPoint(pos); |
| 33253 |
|
| 33254 |
|
| 33255 |
editor.$blockScrolling++; |
| 33256 |
editor.inVirtualSelectionMode = true; |
| 33257 |
|
| 33258 |
if (shift) { |
| 33259 |
oldRange = null; |
| 33260 |
range = selection.ranges[0] || range; |
| 33261 |
editor.removeSelectionMarker(range); |
| 33262 |
} |
| 33263 |
editor.once("mouseup", function() { |
| 33264 |
var tmpSel = selection.toOrientedRange(); |
| 33265 |
|
| 33266 |
if (oldRange && tmpSel.isEmpty() && isSamePoint(oldRange.cursor, tmpSel.cursor)) |
| 33267 |
selection.substractPoint(tmpSel.cursor); |
| 33268 |
else { |
| 33269 |
if (shift) { |
| 33270 |
selection.substractPoint(range.cursor); |
| 33271 |
} else if (range) { |
| 33272 |
editor.removeSelectionMarker(range); |
| 33273 |
selection.addRange(range); |
| 33274 |
} |
| 33275 |
selection.addRange(tmpSel); |
| 33276 |
} |
| 33277 |
editor.$blockScrolling--; |
| 33278 |
editor.inVirtualSelectionMode = false; |
| 33279 |
}); |
| 33280 |
|
| 33281 |
} else if (selectionMode == "block") { |
| 33282 |
e.stop(); |
| 33283 |
editor.inVirtualSelectionMode = true; |
| 33284 |
var initialRange; |
| 33285 |
var rectSel = []; |
| 33286 |
var blockSelect = function() { |
| 33287 |
var newCursor = editor.renderer.pixelToScreenCoordinates(mouseX, mouseY); |
| 33288 |
var cursor = session.screenToDocumentPosition(newCursor.row, newCursor.column); |
| 33289 |
|
| 33290 |
if (isSamePoint(screenCursor, newCursor) && isSamePoint(cursor, selection.lead)) |
| 33291 |
return; |
| 33292 |
screenCursor = newCursor; |
| 33293 |
|
| 33294 |
editor.$blockScrolling++; |
| 33295 |
editor.selection.moveToPosition(cursor); |
| 33296 |
editor.renderer.scrollCursorIntoView(); |
| 33297 |
|
| 33298 |
editor.removeSelectionMarkers(rectSel); |
| 33299 |
rectSel = selection.rectangularRangeBlock(screenCursor, screenAnchor); |
| 33300 |
if (editor.$mouseHandler.$clickSelection && rectSel.length == 1 && rectSel[0].isEmpty()) |
| 33301 |
rectSel[0] = editor.$mouseHandler.$clickSelection.clone(); |
| 33302 |
rectSel.forEach(editor.addSelectionMarker, editor); |
| 33303 |
editor.updateSelectionMarkers(); |
| 33304 |
editor.$blockScrolling--; |
| 33305 |
}; |
| 33306 |
editor.$blockScrolling++; |
| 33307 |
if (isMultiSelect && !accel) { |
| 33308 |
selection.toSingleRange(); |
| 33309 |
} else if (!isMultiSelect && accel) { |
| 33310 |
initialRange = selection.toOrientedRange(); |
| 33311 |
editor.addSelectionMarker(initialRange); |
| 33312 |
} |
| 33313 |
|
| 33314 |
if (shift) |
| 33315 |
screenAnchor = session.documentToScreenPosition(selection.lead); |
| 33316 |
else |
| 33317 |
selection.moveToPosition(pos); |
| 33318 |
editor.$blockScrolling--; |
| 33319 |
|
| 33320 |
screenCursor = {row: -1, column: -1}; |
| 33321 |
|
| 33322 |
var onMouseSelectionEnd = function(e) { |
| 33323 |
clearInterval(timerId); |
| 33324 |
editor.removeSelectionMarkers(rectSel); |
| 33325 |
if (!rectSel.length) |
| 33326 |
rectSel = [selection.toOrientedRange()]; |
| 33327 |
editor.$blockScrolling++; |
| 33328 |
if (initialRange) { |
| 33329 |
editor.removeSelectionMarker(initialRange); |
| 33330 |
selection.toSingleRange(initialRange); |
| 33331 |
} |
| 33332 |
for (var i = 0; i < rectSel.length; i++) |
| 33333 |
selection.addRange(rectSel[i]); |
| 33334 |
editor.inVirtualSelectionMode = false; |
| 33335 |
editor.$mouseHandler.$clickSelection = null; |
| 33336 |
editor.$blockScrolling--; |
| 33337 |
}; |
| 33338 |
|
| 33339 |
var onSelectionInterval = blockSelect; |
| 33340 |
|
| 33341 |
event.capture(editor.container, onMouseSelection, onMouseSelectionEnd); |
| 33342 |
var timerId = setInterval(function() {onSelectionInterval();}, 20); |
| 33343 |
|
| 33344 |
return e.preventDefault(); |
| 33345 |
} |
| 33346 |
} |
| 33347 |
|
| 33348 |
|
| 33349 |
exports.onMouseDown = onMouseDown; |
| 33350 |
|
| 33351 |
}); |
| 33352 |
|
| 33353 |
ace.define("ace/commands/multi_select_commands",["require","exports","module","ace/keyboard/hash_handler"], function(acequire, exports, module) { |
| 33354 |
exports.defaultCommands = [{ |
| 33355 |
name: "addCursorAbove", |
| 33356 |
exec: function(editor) { editor.selectMoreLines(-1); }, |
| 33357 |
bindKey: {win: "Ctrl-Alt-Up", mac: "Ctrl-Alt-Up"}, |
| 33358 |
scrollIntoView: "cursor", |
| 33359 |
readOnly: true |
| 33360 |
}, { |
| 33361 |
name: "addCursorBelow", |
| 33362 |
exec: function(editor) { editor.selectMoreLines(1); }, |
| 33363 |
bindKey: {win: "Ctrl-Alt-Down", mac: "Ctrl-Alt-Down"}, |
| 33364 |
scrollIntoView: "cursor", |
| 33365 |
readOnly: true |
| 33366 |
}, { |
| 33367 |
name: "addCursorAboveSkipCurrent", |
| 33368 |
exec: function(editor) { editor.selectMoreLines(-1, true); }, |
| 33369 |
bindKey: {win: "Ctrl-Alt-Shift-Up", mac: "Ctrl-Alt-Shift-Up"}, |
| 33370 |
scrollIntoView: "cursor", |
| 33371 |
readOnly: true |
| 33372 |
}, { |
| 33373 |
name: "addCursorBelowSkipCurrent", |
| 33374 |
exec: function(editor) { editor.selectMoreLines(1, true); }, |
| 33375 |
bindKey: {win: "Ctrl-Alt-Shift-Down", mac: "Ctrl-Alt-Shift-Down"}, |
| 33376 |
scrollIntoView: "cursor", |
| 33377 |
readOnly: true |
| 33378 |
}, { |
| 33379 |
name: "selectMoreBefore", |
| 33380 |
exec: function(editor) { editor.selectMore(-1); }, |
| 33381 |
bindKey: {win: "Ctrl-Alt-Left", mac: "Ctrl-Alt-Left"}, |
| 33382 |
scrollIntoView: "cursor", |
| 33383 |
readOnly: true |
| 33384 |
}, { |
| 33385 |
name: "selectMoreAfter", |
| 33386 |
exec: function(editor) { editor.selectMore(1); }, |
| 33387 |
bindKey: {win: "Ctrl-Alt-Right", mac: "Ctrl-Alt-Right"}, |
| 33388 |
scrollIntoView: "cursor", |
| 33389 |
readOnly: true |
| 33390 |
}, { |
| 33391 |
name: "selectNextBefore", |
| 33392 |
exec: function(editor) { editor.selectMore(-1, true); }, |
| 33393 |
bindKey: {win: "Ctrl-Alt-Shift-Left", mac: "Ctrl-Alt-Shift-Left"}, |
| 33394 |
scrollIntoView: "cursor", |
| 33395 |
readOnly: true |
| 33396 |
}, { |
| 33397 |
name: "selectNextAfter", |
| 33398 |
exec: function(editor) { editor.selectMore(1, true); }, |
| 33399 |
bindKey: {win: "Ctrl-Alt-Shift-Right", mac: "Ctrl-Alt-Shift-Right"}, |
| 33400 |
scrollIntoView: "cursor", |
| 33401 |
readOnly: true |
| 33402 |
}, { |
| 33403 |
name: "splitIntoLines", |
| 33404 |
exec: function(editor) { editor.multiSelect.splitIntoLines(); }, |
| 33405 |
bindKey: {win: "Ctrl-Alt-L", mac: "Ctrl-Alt-L"}, |
| 33406 |
readOnly: true |
| 33407 |
}, { |
| 33408 |
name: "alignCursors", |
| 33409 |
exec: function(editor) { editor.alignCursors(); }, |
| 33410 |
bindKey: {win: "Ctrl-Alt-A", mac: "Ctrl-Alt-A"}, |
| 33411 |
scrollIntoView: "cursor" |
| 33412 |
}, { |
| 33413 |
name: "findAll", |
| 33414 |
exec: function(editor) { editor.findAll(); }, |
| 33415 |
bindKey: {win: "Ctrl-Alt-K", mac: "Ctrl-Alt-G"}, |
| 33416 |
scrollIntoView: "cursor", |
| 33417 |
readOnly: true |
| 33418 |
}]; |
| 33419 |
exports.multiSelectCommands = [{ |
| 33420 |
name: "singleSelection", |
| 33421 |
bindKey: "esc", |
| 33422 |
exec: function(editor) { editor.exitMultiSelectMode(); }, |
| 33423 |
scrollIntoView: "cursor", |
| 33424 |
readOnly: true, |
| 33425 |
isAvailable: function(editor) {return editor && editor.inMultiSelectMode} |
| 33426 |
}]; |
| 33427 |
|
| 33428 |
var HashHandler = acequire("../keyboard/hash_handler").HashHandler; |
| 33429 |
exports.keyboardHandler = new HashHandler(exports.multiSelectCommands); |
| 33430 |
|
| 33431 |
}); |
| 33432 |
|
| 33433 |
ace.define("ace/multi_select",["require","exports","module","ace/range_list","ace/range","ace/selection","ace/mouse/multi_select_handler","ace/lib/event","ace/lib/lang","ace/commands/multi_select_commands","ace/search","ace/edit_session","ace/editor","ace/config"], function(acequire, exports, module) { |
| 33434 |
|
| 33435 |
var RangeList = acequire("./range_list").RangeList; |
| 33436 |
var Range = acequire("./range").Range; |
| 33437 |
var Selection = acequire("./selection").Selection; |
| 33438 |
var onMouseDown = acequire("./mouse/multi_select_handler").onMouseDown; |
| 33439 |
var event = acequire("./lib/event"); |
| 33440 |
var lang = acequire("./lib/lang"); |
| 33441 |
var commands = acequire("./commands/multi_select_commands"); |
| 33442 |
exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands); |
| 33443 |
var Search = acequire("./search").Search; |
| 33444 |
var search = new Search(); |
| 33445 |
|
| 33446 |
function find(session, needle, dir) { |
| 33447 |
search.$options.wrap = true; |
| 33448 |
search.$options.needle = needle; |
| 33449 |
search.$options.backwards = dir == -1; |
| 33450 |
return search.find(session); |
| 33451 |
} |
| 33452 |
var EditSession = acequire("./edit_session").EditSession; |
| 33453 |
(function() { |
| 33454 |
this.getSelectionMarkers = function() { |
| 33455 |
return this.$selectionMarkers; |
| 33456 |
}; |
| 33457 |
}).call(EditSession.prototype); |
| 33458 |
(function() { |
| 33459 |
this.ranges = null; |
| 33460 |
this.rangeList = null; |
| 33461 |
this.addRange = function(range, $blockChangeEvents) { |
| 33462 |
if (!range) |
| 33463 |
return; |
| 33464 |
|
| 33465 |
if (!this.inMultiSelectMode && this.rangeCount === 0) { |
| 33466 |
var oldRange = this.toOrientedRange(); |
| 33467 |
this.rangeList.add(oldRange); |
| 33468 |
this.rangeList.add(range); |
| 33469 |
if (this.rangeList.ranges.length != 2) { |
| 33470 |
this.rangeList.removeAll(); |
| 33471 |
return $blockChangeEvents || this.fromOrientedRange(range); |
| 33472 |
} |
| 33473 |
this.rangeList.removeAll(); |
| 33474 |
this.rangeList.add(oldRange); |
| 33475 |
this.$onAddRange(oldRange); |
| 33476 |
} |
| 33477 |
|
| 33478 |
if (!range.cursor) |
| 33479 |
range.cursor = range.end; |
| 33480 |
|
| 33481 |
var removed = this.rangeList.add(range); |
| 33482 |
|
| 33483 |
this.$onAddRange(range); |
| 33484 |
|
| 33485 |
if (removed.length) |
| 33486 |
this.$onRemoveRange(removed); |
| 33487 |
|
| 33488 |
if (this.rangeCount > 1 && !this.inMultiSelectMode) { |
| 33489 |
this._signal("multiSelect"); |
| 33490 |
this.inMultiSelectMode = true; |
| 33491 |
this.session.$undoSelect = false; |
| 33492 |
this.rangeList.attach(this.session); |
| 33493 |
} |
| 33494 |
|
| 33495 |
return $blockChangeEvents || this.fromOrientedRange(range); |
| 33496 |
}; |
| 33497 |
|
| 33498 |
this.toSingleRange = function(range) { |
| 33499 |
range = range || this.ranges[0]; |
| 33500 |
var removed = this.rangeList.removeAll(); |
| 33501 |
if (removed.length) |
| 33502 |
this.$onRemoveRange(removed); |
| 33503 |
|
| 33504 |
range && this.fromOrientedRange(range); |
| 33505 |
}; |
| 33506 |
this.substractPoint = function(pos) { |
| 33507 |
var removed = this.rangeList.substractPoint(pos); |
| 33508 |
if (removed) { |
| 33509 |
this.$onRemoveRange(removed); |
| 33510 |
return removed[0]; |
| 33511 |
} |
| 33512 |
}; |
| 33513 |
this.mergeOverlappingRanges = function() { |
| 33514 |
var removed = this.rangeList.merge(); |
| 33515 |
if (removed.length) |
| 33516 |
this.$onRemoveRange(removed); |
| 33517 |
else if(this.ranges[0]) |
| 33518 |
this.fromOrientedRange(this.ranges[0]); |
| 33519 |
}; |
| 33520 |
|
| 33521 |
this.$onAddRange = function(range) { |
| 33522 |
this.rangeCount = this.rangeList.ranges.length; |
| 33523 |
this.ranges.unshift(range); |
| 33524 |
this._signal("addRange", {range: range}); |
| 33525 |
}; |
| 33526 |
|
| 33527 |
this.$onRemoveRange = function(removed) { |
| 33528 |
this.rangeCount = this.rangeList.ranges.length; |
| 33529 |
if (this.rangeCount == 1 && this.inMultiSelectMode) { |
| 33530 |
var lastRange = this.rangeList.ranges.pop(); |
| 33531 |
removed.push(lastRange); |
| 33532 |
this.rangeCount = 0; |
| 33533 |
} |
| 33534 |
|
| 33535 |
for (var i = removed.length; i--; ) { |
| 33536 |
var index = this.ranges.indexOf(removed[i]); |
| 33537 |
this.ranges.splice(index, 1); |
| 33538 |
} |
| 33539 |
|
| 33540 |
this._signal("removeRange", {ranges: removed}); |
| 33541 |
|
| 33542 |
if (this.rangeCount === 0 && this.inMultiSelectMode) { |
| 33543 |
this.inMultiSelectMode = false; |
| 33544 |
this._signal("singleSelect"); |
| 33545 |
this.session.$undoSelect = true; |
| 33546 |
this.rangeList.detach(this.session); |
| 33547 |
} |
| 33548 |
|
| 33549 |
lastRange = lastRange || this.ranges[0]; |
| 33550 |
if (lastRange && !lastRange.isEqual(this.getRange())) |
| 33551 |
this.fromOrientedRange(lastRange); |
| 33552 |
}; |
| 33553 |
this.$initRangeList = function() { |
| 33554 |
if (this.rangeList) |
| 33555 |
return; |
| 33556 |
|
| 33557 |
this.rangeList = new RangeList(); |
| 33558 |
this.ranges = []; |
| 33559 |
this.rangeCount = 0; |
| 33560 |
}; |
| 33561 |
this.getAllRanges = function() { |
| 33562 |
return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()]; |
| 33563 |
}; |
| 33564 |
|
| 33565 |
this.splitIntoLines = function () { |
| 33566 |
if (this.rangeCount > 1) { |
| 33567 |
var ranges = this.rangeList.ranges; |
| 33568 |
var lastRange = ranges[ranges.length - 1]; |
| 33569 |
var range = Range.fromPoints(ranges[0].start, lastRange.end); |
| 33570 |
|
| 33571 |
this.toSingleRange(); |
| 33572 |
this.setSelectionRange(range, lastRange.cursor == lastRange.start); |
| 33573 |
} else { |
| 33574 |
var range = this.getRange(); |
| 33575 |
var isBackwards = this.isBackwards(); |
| 33576 |
var startRow = range.start.row; |
| 33577 |
var endRow = range.end.row; |
| 33578 |
if (startRow == endRow) { |
| 33579 |
if (isBackwards) |
| 33580 |
var start = range.end, end = range.start; |
| 33581 |
else |
| 33582 |
var start = range.start, end = range.end; |
| 33583 |
|
| 33584 |
this.addRange(Range.fromPoints(end, end)); |
| 33585 |
this.addRange(Range.fromPoints(start, start)); |
| 33586 |
return; |
| 33587 |
} |
| 33588 |
|
| 33589 |
var rectSel = []; |
| 33590 |
var r = this.getLineRange(startRow, true); |
| 33591 |
r.start.column = range.start.column; |
| 33592 |
rectSel.push(r); |
| 33593 |
|
| 33594 |
for (var i = startRow + 1; i < endRow; i++) |
| 33595 |
rectSel.push(this.getLineRange(i, true)); |
| 33596 |
|
| 33597 |
r = this.getLineRange(endRow, true); |
| 33598 |
r.end.column = range.end.column; |
| 33599 |
rectSel.push(r); |
| 33600 |
|
| 33601 |
rectSel.forEach(this.addRange, this); |
| 33602 |
} |
| 33603 |
}; |
| 33604 |
this.toggleBlockSelection = function () { |
| 33605 |
if (this.rangeCount > 1) { |
| 33606 |
var ranges = this.rangeList.ranges; |
| 33607 |
var lastRange = ranges[ranges.length - 1]; |
| 33608 |
var range = Range.fromPoints(ranges[0].start, lastRange.end); |
| 33609 |
|
| 33610 |
this.toSingleRange(); |
| 33611 |
this.setSelectionRange(range, lastRange.cursor == lastRange.start); |
| 33612 |
} else { |
| 33613 |
var cursor = this.session.documentToScreenPosition(this.selectionLead); |
| 33614 |
var anchor = this.session.documentToScreenPosition(this.selectionAnchor); |
| 33615 |
|
| 33616 |
var rectSel = this.rectangularRangeBlock(cursor, anchor); |
| 33617 |
rectSel.forEach(this.addRange, this); |
| 33618 |
} |
| 33619 |
}; |
| 33620 |
this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) { |
| 33621 |
var rectSel = []; |
| 33622 |
|
| 33623 |
var xBackwards = screenCursor.column < screenAnchor.column; |
| 33624 |
if (xBackwards) { |
| 33625 |
var startColumn = screenCursor.column; |
| 33626 |
var endColumn = screenAnchor.column; |
| 33627 |
} else { |
| 33628 |
var startColumn = screenAnchor.column; |
| 33629 |
var endColumn = screenCursor.column; |
| 33630 |
} |
| 33631 |
|
| 33632 |
var yBackwards = screenCursor.row < screenAnchor.row; |
| 33633 |
if (yBackwards) { |
| 33634 |
var startRow = screenCursor.row; |
| 33635 |
var endRow = screenAnchor.row; |
| 33636 |
} else { |
| 33637 |
var startRow = screenAnchor.row; |
| 33638 |
var endRow = screenCursor.row; |
| 33639 |
} |
| 33640 |
|
| 33641 |
if (startColumn < 0) |
| 33642 |
startColumn = 0; |
| 33643 |
if (startRow < 0) |
| 33644 |
startRow = 0; |
| 33645 |
|
| 33646 |
if (startRow == endRow) |
| 33647 |
includeEmptyLines = true; |
| 33648 |
|
| 33649 |
for (var row = startRow; row <= endRow; row++) { |
| 33650 |
var range = Range.fromPoints( |
| 33651 |
this.session.screenToDocumentPosition(row, startColumn), |
| 33652 |
this.session.screenToDocumentPosition(row, endColumn) |
| 33653 |
); |
| 33654 |
if (range.isEmpty()) { |
| 33655 |
if (docEnd && isSamePoint(range.end, docEnd)) |
| 33656 |
break; |
| 33657 |
var docEnd = range.end; |
| 33658 |
} |
| 33659 |
range.cursor = xBackwards ? range.start : range.end; |
| 33660 |
rectSel.push(range); |
| 33661 |
} |
| 33662 |
|
| 33663 |
if (yBackwards) |
| 33664 |
rectSel.reverse(); |
| 33665 |
|
| 33666 |
if (!includeEmptyLines) { |
| 33667 |
var end = rectSel.length - 1; |
| 33668 |
while (rectSel[end].isEmpty() && end > 0) |
| 33669 |
end--; |
| 33670 |
if (end > 0) { |
| 33671 |
var start = 0; |
| 33672 |
while (rectSel[start].isEmpty()) |
| 33673 |
start++; |
| 33674 |
} |
| 33675 |
for (var i = end; i >= start; i--) { |
| 33676 |
if (rectSel[i].isEmpty()) |
| 33677 |
rectSel.splice(i, 1); |
| 33678 |
} |
| 33679 |
} |
| 33680 |
|
| 33681 |
return rectSel; |
| 33682 |
}; |
| 33683 |
}).call(Selection.prototype); |
| 33684 |
var Editor = acequire("./editor").Editor; |
| 33685 |
(function() { |
| 33686 |
this.updateSelectionMarkers = function() { |
| 33687 |
this.renderer.updateCursor(); |
| 33688 |
this.renderer.updateBackMarkers(); |
| 33689 |
}; |
| 33690 |
this.addSelectionMarker = function(orientedRange) { |
| 33691 |
if (!orientedRange.cursor) |
| 33692 |
orientedRange.cursor = orientedRange.end; |
| 33693 |
|
| 33694 |
var style = this.getSelectionStyle(); |
| 33695 |
orientedRange.marker = this.session.addMarker(orientedRange, "ace_selection", style); |
| 33696 |
|
| 33697 |
this.session.$selectionMarkers.push(orientedRange); |
| 33698 |
this.session.selectionMarkerCount = this.session.$selectionMarkers.length; |
| 33699 |
return orientedRange; |
| 33700 |
}; |
| 33701 |
this.removeSelectionMarker = function(range) { |
| 33702 |
if (!range.marker) |
| 33703 |
return; |
| 33704 |
this.session.removeMarker(range.marker); |
| 33705 |
var index = this.session.$selectionMarkers.indexOf(range); |
| 33706 |
if (index != -1) |
| 33707 |
this.session.$selectionMarkers.splice(index, 1); |
| 33708 |
this.session.selectionMarkerCount = this.session.$selectionMarkers.length; |
| 33709 |
}; |
| 33710 |
|
| 33711 |
this.removeSelectionMarkers = function(ranges) { |
| 33712 |
var markerList = this.session.$selectionMarkers; |
| 33713 |
for (var i = ranges.length; i--; ) { |
| 33714 |
var range = ranges[i]; |
| 33715 |
if (!range.marker) |
| 33716 |
continue; |
| 33717 |
this.session.removeMarker(range.marker); |
| 33718 |
var index = markerList.indexOf(range); |
| 33719 |
if (index != -1) |
| 33720 |
markerList.splice(index, 1); |
| 33721 |
} |
| 33722 |
this.session.selectionMarkerCount = markerList.length; |
| 33723 |
}; |
| 33724 |
|
| 33725 |
this.$onAddRange = function(e) { |
| 33726 |
this.addSelectionMarker(e.range); |
| 33727 |
this.renderer.updateCursor(); |
| 33728 |
this.renderer.updateBackMarkers(); |
| 33729 |
}; |
| 33730 |
|
| 33731 |
this.$onRemoveRange = function(e) { |
| 33732 |
this.removeSelectionMarkers(e.ranges); |
| 33733 |
this.renderer.updateCursor(); |
| 33734 |
this.renderer.updateBackMarkers(); |
| 33735 |
}; |
| 33736 |
|
| 33737 |
this.$onMultiSelect = function(e) { |
| 33738 |
if (this.inMultiSelectMode) |
| 33739 |
return; |
| 33740 |
this.inMultiSelectMode = true; |
| 33741 |
|
| 33742 |
this.setStyle("ace_multiselect"); |
| 33743 |
this.keyBinding.addKeyboardHandler(commands.keyboardHandler); |
| 33744 |
this.commands.setDefaultHandler("exec", this.$onMultiSelectExec); |
| 33745 |
|
| 33746 |
this.renderer.updateCursor(); |
| 33747 |
this.renderer.updateBackMarkers(); |
| 33748 |
}; |
| 33749 |
|
| 33750 |
this.$onSingleSelect = function(e) { |
| 33751 |
if (this.session.multiSelect.inVirtualMode) |
| 33752 |
return; |
| 33753 |
this.inMultiSelectMode = false; |
| 33754 |
|
| 33755 |
this.unsetStyle("ace_multiselect"); |
| 33756 |
this.keyBinding.removeKeyboardHandler(commands.keyboardHandler); |
| 33757 |
|
| 33758 |
this.commands.removeDefaultHandler("exec", this.$onMultiSelectExec); |
| 33759 |
this.renderer.updateCursor(); |
| 33760 |
this.renderer.updateBackMarkers(); |
| 33761 |
this._emit("changeSelection"); |
| 33762 |
}; |
| 33763 |
|
| 33764 |
this.$onMultiSelectExec = function(e) { |
| 33765 |
var command = e.command; |
| 33766 |
var editor = e.editor; |
| 33767 |
if (!editor.multiSelect) |
| 33768 |
return; |
| 33769 |
if (!command.multiSelectAction) { |
| 33770 |
var result = command.exec(editor, e.args || {}); |
| 33771 |
editor.multiSelect.addRange(editor.multiSelect.toOrientedRange()); |
| 33772 |
editor.multiSelect.mergeOverlappingRanges(); |
| 33773 |
} else if (command.multiSelectAction == "forEach") { |
| 33774 |
result = editor.forEachSelection(command, e.args); |
| 33775 |
} else if (command.multiSelectAction == "forEachLine") { |
| 33776 |
result = editor.forEachSelection(command, e.args, true); |
| 33777 |
} else if (command.multiSelectAction == "single") { |
| 33778 |
editor.exitMultiSelectMode(); |
| 33779 |
result = command.exec(editor, e.args || {}); |
| 33780 |
} else { |
| 33781 |
result = command.multiSelectAction(editor, e.args || {}); |
| 33782 |
} |
| 33783 |
return result; |
| 33784 |
}; |
| 33785 |
this.forEachSelection = function(cmd, args, options) { |
| 33786 |
if (this.inVirtualSelectionMode) |
| 33787 |
return; |
| 33788 |
var keepOrder = options && options.keepOrder; |
| 33789 |
var $byLines = options == true || options && options.$byLines |
| 33790 |
var session = this.session; |
| 33791 |
var selection = this.selection; |
| 33792 |
var rangeList = selection.rangeList; |
| 33793 |
var ranges = (keepOrder ? selection : rangeList).ranges; |
| 33794 |
var result; |
| 33795 |
|
| 33796 |
if (!ranges.length) |
| 33797 |
return cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {}); |
| 33798 |
|
| 33799 |
var reg = selection._eventRegistry; |
| 33800 |
selection._eventRegistry = {}; |
| 33801 |
|
| 33802 |
var tmpSel = new Selection(session); |
| 33803 |
this.inVirtualSelectionMode = true; |
| 33804 |
for (var i = ranges.length; i--;) { |
| 33805 |
if ($byLines) { |
| 33806 |
while (i > 0 && ranges[i].start.row == ranges[i - 1].end.row) |
| 33807 |
i--; |
| 33808 |
} |
| 33809 |
tmpSel.fromOrientedRange(ranges[i]); |
| 33810 |
tmpSel.index = i; |
| 33811 |
this.selection = session.selection = tmpSel; |
| 33812 |
var cmdResult = cmd.exec ? cmd.exec(this, args || {}) : cmd(this, args || {}); |
| 33813 |
if (!result && cmdResult !== undefined) |
| 33814 |
result = cmdResult; |
| 33815 |
tmpSel.toOrientedRange(ranges[i]); |
| 33816 |
} |
| 33817 |
tmpSel.detach(); |
| 33818 |
|
| 33819 |
this.selection = session.selection = selection; |
| 33820 |
this.inVirtualSelectionMode = false; |
| 33821 |
selection._eventRegistry = reg; |
| 33822 |
selection.mergeOverlappingRanges(); |
| 33823 |
|
| 33824 |
var anim = this.renderer.$scrollAnimation; |
| 33825 |
this.onCursorChange(); |
| 33826 |
this.onSelectionChange(); |
| 33827 |
if (anim && anim.from == anim.to) |
| 33828 |
this.renderer.animateScrolling(anim.from); |
| 33829 |
|
| 33830 |
return result; |
| 33831 |
}; |
| 33832 |
this.exitMultiSelectMode = function() { |
| 33833 |
if (!this.inMultiSelectMode || this.inVirtualSelectionMode) |
| 33834 |
return; |
| 33835 |
this.multiSelect.toSingleRange(); |
| 33836 |
}; |
| 33837 |
|
| 33838 |
this.getSelectedText = function() { |
| 33839 |
var text = ""; |
| 33840 |
if (this.inMultiSelectMode && !this.inVirtualSelectionMode) { |
| 33841 |
var ranges = this.multiSelect.rangeList.ranges; |
| 33842 |
var buf = []; |
| 33843 |
for (var i = 0; i < ranges.length; i++) { |
| 33844 |
buf.push(this.session.getTextRange(ranges[i])); |
| 33845 |
} |
| 33846 |
var nl = this.session.getDocument().getNewLineCharacter(); |
| 33847 |
text = buf.join(nl); |
| 33848 |
if (text.length == (buf.length - 1) * nl.length) |
| 33849 |
text = ""; |
| 33850 |
} else if (!this.selection.isEmpty()) { |
| 33851 |
text = this.session.getTextRange(this.getSelectionRange()); |
| 33852 |
} |
| 33853 |
return text; |
| 33854 |
}; |
| 33855 |
|
| 33856 |
this.$checkMultiselectChange = function(e, anchor) { |
| 33857 |
if (this.inMultiSelectMode && !this.inVirtualSelectionMode) { |
| 33858 |
var range = this.multiSelect.ranges[0]; |
| 33859 |
if (this.multiSelect.isEmpty() && anchor == this.multiSelect.anchor) |
| 33860 |
return; |
| 33861 |
var pos = anchor == this.multiSelect.anchor |
| 33862 |
? range.cursor == range.start ? range.end : range.start |
| 33863 |
: range.cursor; |
| 33864 |
if (pos.row != anchor.row |
| 33865 |
|| this.session.$clipPositionToDocument(pos.row, pos.column).column != anchor.column) |
| 33866 |
this.multiSelect.toSingleRange(this.multiSelect.toOrientedRange()); |
| 33867 |
} |
| 33868 |
}; |
| 33869 |
this.findAll = function(needle, options, additive) { |
| 33870 |
options = options || {}; |
| 33871 |
options.needle = needle || options.needle; |
| 33872 |
if (options.needle == undefined) { |
| 33873 |
var range = this.selection.isEmpty() |
| 33874 |
? this.selection.getWordRange() |
| 33875 |
: this.selection.getRange(); |
| 33876 |
options.needle = this.session.getTextRange(range); |
| 33877 |
} |
| 33878 |
this.$search.set(options); |
| 33879 |
|
| 33880 |
var ranges = this.$search.findAll(this.session); |
| 33881 |
if (!ranges.length) |
| 33882 |
return 0; |
| 33883 |
|
| 33884 |
this.$blockScrolling += 1; |
| 33885 |
var selection = this.multiSelect; |
| 33886 |
|
| 33887 |
if (!additive) |
| 33888 |
selection.toSingleRange(ranges[0]); |
| 33889 |
|
| 33890 |
for (var i = ranges.length; i--; ) |
| 33891 |
selection.addRange(ranges[i], true); |
| 33892 |
if (range && selection.rangeList.rangeAtPoint(range.start)) |
| 33893 |
selection.addRange(range, true); |
| 33894 |
|
| 33895 |
this.$blockScrolling -= 1; |
| 33896 |
|
| 33897 |
return ranges.length; |
| 33898 |
}; |
| 33899 |
this.selectMoreLines = function(dir, skip) { |
| 33900 |
var range = this.selection.toOrientedRange(); |
| 33901 |
var isBackwards = range.cursor == range.end; |
| 33902 |
|
| 33903 |
var screenLead = this.session.documentToScreenPosition(range.cursor); |
| 33904 |
if (this.selection.$desiredColumn) |
| 33905 |
screenLead.column = this.selection.$desiredColumn; |
| 33906 |
|
| 33907 |
var lead = this.session.screenToDocumentPosition(screenLead.row + dir, screenLead.column); |
| 33908 |
|
| 33909 |
if (!range.isEmpty()) { |
| 33910 |
var screenAnchor = this.session.documentToScreenPosition(isBackwards ? range.end : range.start); |
| 33911 |
var anchor = this.session.screenToDocumentPosition(screenAnchor.row + dir, screenAnchor.column); |
| 33912 |
} else { |
| 33913 |
var anchor = lead; |
| 33914 |
} |
| 33915 |
|
| 33916 |
if (isBackwards) { |
| 33917 |
var newRange = Range.fromPoints(lead, anchor); |
| 33918 |
newRange.cursor = newRange.start; |
| 33919 |
} else { |
| 33920 |
var newRange = Range.fromPoints(anchor, lead); |
| 33921 |
newRange.cursor = newRange.end; |
| 33922 |
} |
| 33923 |
|
| 33924 |
newRange.desiredColumn = screenLead.column; |
| 33925 |
if (!this.selection.inMultiSelectMode) { |
| 33926 |
this.selection.addRange(range); |
| 33927 |
} else { |
| 33928 |
if (skip) |
| 33929 |
var toRemove = range.cursor; |
| 33930 |
} |
| 33931 |
|
| 33932 |
this.selection.addRange(newRange); |
| 33933 |
if (toRemove) |
| 33934 |
this.selection.substractPoint(toRemove); |
| 33935 |
}; |
| 33936 |
this.transposeSelections = function(dir) { |
| 33937 |
var session = this.session; |
| 33938 |
var sel = session.multiSelect; |
| 33939 |
var all = sel.ranges; |
| 33940 |
|
| 33941 |
for (var i = all.length; i--; ) { |
| 33942 |
var range = all[i]; |
| 33943 |
if (range.isEmpty()) { |
| 33944 |
var tmp = session.getWordRange(range.start.row, range.start.column); |
| 33945 |
range.start.row = tmp.start.row; |
| 33946 |
range.start.column = tmp.start.column; |
| 33947 |
range.end.row = tmp.end.row; |
| 33948 |
range.end.column = tmp.end.column; |
| 33949 |
} |
| 33950 |
} |
| 33951 |
sel.mergeOverlappingRanges(); |
| 33952 |
|
| 33953 |
var words = []; |
| 33954 |
for (var i = all.length; i--; ) { |
| 33955 |
var range = all[i]; |
| 33956 |
words.unshift(session.getTextRange(range)); |
| 33957 |
} |
| 33958 |
|
| 33959 |
if (dir < 0) |
| 33960 |
words.unshift(words.pop()); |
| 33961 |
else |
| 33962 |
words.push(words.shift()); |
| 33963 |
|
| 33964 |
for (var i = all.length; i--; ) { |
| 33965 |
var range = all[i]; |
| 33966 |
var tmp = range.clone(); |
| 33967 |
session.replace(range, words[i]); |
| 33968 |
range.start.row = tmp.start.row; |
| 33969 |
range.start.column = tmp.start.column; |
| 33970 |
} |
| 33971 |
}; |
| 33972 |
this.selectMore = function(dir, skip, stopAtFirst) { |
| 33973 |
var session = this.session; |
| 33974 |
var sel = session.multiSelect; |
| 33975 |
|
| 33976 |
var range = sel.toOrientedRange(); |
| 33977 |
if (range.isEmpty()) { |
| 33978 |
range = session.getWordRange(range.start.row, range.start.column); |
| 33979 |
range.cursor = dir == -1 ? range.start : range.end; |
| 33980 |
this.multiSelect.addRange(range); |
| 33981 |
if (stopAtFirst) |
| 33982 |
return; |
| 33983 |
} |
| 33984 |
var needle = session.getTextRange(range); |
| 33985 |
|
| 33986 |
var newRange = find(session, needle, dir); |
| 33987 |
if (newRange) { |
| 33988 |
newRange.cursor = dir == -1 ? newRange.start : newRange.end; |
| 33989 |
this.$blockScrolling += 1; |
| 33990 |
this.session.unfold(newRange); |
| 33991 |
this.multiSelect.addRange(newRange); |
| 33992 |
this.$blockScrolling -= 1; |
| 33993 |
this.renderer.scrollCursorIntoView(null, 0.5); |
| 33994 |
} |
| 33995 |
if (skip) |
| 33996 |
this.multiSelect.substractPoint(range.cursor); |
| 33997 |
}; |
| 33998 |
this.alignCursors = function() { |
| 33999 |
var session = this.session; |
| 34000 |
var sel = session.multiSelect; |
| 34001 |
var ranges = sel.ranges; |
| 34002 |
var row = -1; |
| 34003 |
var sameRowRanges = ranges.filter(function(r) { |
| 34004 |
if (r.cursor.row == row) |
| 34005 |
return true; |
| 34006 |
row = r.cursor.row; |
| 34007 |
}); |
| 34008 |
|
| 34009 |
if (!ranges.length || sameRowRanges.length == ranges.length - 1) { |
| 34010 |
var range = this.selection.getRange(); |
| 34011 |
var fr = range.start.row, lr = range.end.row; |
| 34012 |
var guessRange = fr == lr; |
| 34013 |
if (guessRange) { |
| 34014 |
var max = this.session.getLength(); |
| 34015 |
var line; |
| 34016 |
do { |
| 34017 |
line = this.session.getLine(lr); |
| 34018 |
} while (/[=:]/.test(line) && ++lr < max); |
| 34019 |
do { |
| 34020 |
line = this.session.getLine(fr); |
| 34021 |
} while (/[=:]/.test(line) && --fr > 0); |
| 34022 |
|
| 34023 |
if (fr < 0) fr = 0; |
| 34024 |
if (lr >= max) lr = max - 1; |
| 34025 |
} |
| 34026 |
var lines = this.session.removeFullLines(fr, lr); |
| 34027 |
lines = this.$reAlignText(lines, guessRange); |
| 34028 |
this.session.insert({row: fr, column: 0}, lines.join("\n") + "\n"); |
| 34029 |
if (!guessRange) { |
| 34030 |
range.start.column = 0; |
| 34031 |
range.end.column = lines[lines.length - 1].length; |
| 34032 |
} |
| 34033 |
this.selection.setRange(range); |
| 34034 |
} else { |
| 34035 |
sameRowRanges.forEach(function(r) { |
| 34036 |
sel.substractPoint(r.cursor); |
| 34037 |
}); |
| 34038 |
|
| 34039 |
var maxCol = 0; |
| 34040 |
var minSpace = Infinity; |
| 34041 |
var spaceOffsets = ranges.map(function(r) { |
| 34042 |
var p = r.cursor; |
| 34043 |
var line = session.getLine(p.row); |
| 34044 |
var spaceOffset = line.substr(p.column).search(/\S/g); |
| 34045 |
if (spaceOffset == -1) |
| 34046 |
spaceOffset = 0; |
| 34047 |
|
| 34048 |
if (p.column > maxCol) |
| 34049 |
maxCol = p.column; |
| 34050 |
if (spaceOffset < minSpace) |
| 34051 |
minSpace = spaceOffset; |
| 34052 |
return spaceOffset; |
| 34053 |
}); |
| 34054 |
ranges.forEach(function(r, i) { |
| 34055 |
var p = r.cursor; |
| 34056 |
var l = maxCol - p.column; |
| 34057 |
var d = spaceOffsets[i] - minSpace; |
| 34058 |
if (l > d) |
| 34059 |
session.insert(p, lang.stringRepeat(" ", l - d)); |
| 34060 |
else |
| 34061 |
session.remove(new Range(p.row, p.column, p.row, p.column - l + d)); |
| 34062 |
|
| 34063 |
r.start.column = r.end.column = maxCol; |
| 34064 |
r.start.row = r.end.row = p.row; |
| 34065 |
r.cursor = r.end; |
| 34066 |
}); |
| 34067 |
sel.fromOrientedRange(ranges[0]); |
| 34068 |
this.renderer.updateCursor(); |
| 34069 |
this.renderer.updateBackMarkers(); |
| 34070 |
} |
| 34071 |
}; |
| 34072 |
|
| 34073 |
this.$reAlignText = function(lines, forceLeft) { |
| 34074 |
var isLeftAligned = true, isRightAligned = true; |
| 34075 |
var startW, textW, endW; |
| 34076 |
|
| 34077 |
return lines.map(function(line) { |
| 34078 |
var m = line.match(/(\s*)(.*?)(\s*)([=:].*)/); |
| 34079 |
if (!m) |
| 34080 |
return [line]; |
| 34081 |
|
| 34082 |
if (startW == null) { |
| 34083 |
startW = m[1].length; |
| 34084 |
textW = m[2].length; |
| 34085 |
endW = m[3].length; |
| 34086 |
return m; |
| 34087 |
} |
| 34088 |
|
| 34089 |
if (startW + textW + endW != m[1].length + m[2].length + m[3].length) |
| 34090 |
isRightAligned = false; |
| 34091 |
if (startW != m[1].length) |
| 34092 |
isLeftAligned = false; |
| 34093 |
|
| 34094 |
if (startW > m[1].length) |
| 34095 |
startW = m[1].length; |
| 34096 |
if (textW < m[2].length) |
| 34097 |
textW = m[2].length; |
| 34098 |
if (endW > m[3].length) |
| 34099 |
endW = m[3].length; |
| 34100 |
|
| 34101 |
return m; |
| 34102 |
}).map(forceLeft ? alignLeft : |
| 34103 |
isLeftAligned ? isRightAligned ? alignRight : alignLeft : unAlign); |
| 34104 |
|
| 34105 |
function spaces(n) { |
| 34106 |
return lang.stringRepeat(" ", n); |
| 34107 |
} |
| 34108 |
|
| 34109 |
function alignLeft(m) { |
| 34110 |
return !m[2] ? m[0] : spaces(startW) + m[2] |
| 34111 |
+ spaces(textW - m[2].length + endW) |
| 34112 |
+ m[4].replace(/^([=:])\s+/, "$1 "); |
| 34113 |
} |
| 34114 |
function alignRight(m) { |
| 34115 |
return !m[2] ? m[0] : spaces(startW + textW - m[2].length) + m[2] |
| 34116 |
+ spaces(endW, " ") |
| 34117 |
+ m[4].replace(/^([=:])\s+/, "$1 "); |
| 34118 |
} |
| 34119 |
function unAlign(m) { |
| 34120 |
return !m[2] ? m[0] : spaces(startW) + m[2] |
| 34121 |
+ spaces(endW) |
| 34122 |
+ m[4].replace(/^([=:])\s+/, "$1 "); |
| 34123 |
} |
| 34124 |
}; |
| 34125 |
}).call(Editor.prototype); |
| 34126 |
|
| 34127 |
|
| 34128 |
function isSamePoint(p1, p2) { |
| 34129 |
return p1.row == p2.row && p1.column == p2.column; |
| 34130 |
} |
| 34131 |
exports.onSessionChange = function(e) { |
| 34132 |
var session = e.session; |
| 34133 |
if (session && !session.multiSelect) { |
| 34134 |
session.$selectionMarkers = []; |
| 34135 |
session.selection.$initRangeList(); |
| 34136 |
session.multiSelect = session.selection; |
| 34137 |
} |
| 34138 |
this.multiSelect = session && session.multiSelect; |
| 34139 |
|
| 34140 |
var oldSession = e.oldSession; |
| 34141 |
if (oldSession) { |
| 34142 |
oldSession.multiSelect.off("addRange", this.$onAddRange); |
| 34143 |
oldSession.multiSelect.off("removeRange", this.$onRemoveRange); |
| 34144 |
oldSession.multiSelect.off("multiSelect", this.$onMultiSelect); |
| 34145 |
oldSession.multiSelect.off("singleSelect", this.$onSingleSelect); |
| 34146 |
oldSession.multiSelect.lead.off("change", this.$checkMultiselectChange); |
| 34147 |
oldSession.multiSelect.anchor.off("change", this.$checkMultiselectChange); |
| 34148 |
} |
| 34149 |
|
| 34150 |
if (session) { |
| 34151 |
session.multiSelect.on("addRange", this.$onAddRange); |
| 34152 |
session.multiSelect.on("removeRange", this.$onRemoveRange); |
| 34153 |
session.multiSelect.on("multiSelect", this.$onMultiSelect); |
| 34154 |
session.multiSelect.on("singleSelect", this.$onSingleSelect); |
| 34155 |
session.multiSelect.lead.on("change", this.$checkMultiselectChange); |
| 34156 |
session.multiSelect.anchor.on("change", this.$checkMultiselectChange); |
| 34157 |
} |
| 34158 |
|
| 34159 |
if (session && this.inMultiSelectMode != session.selection.inMultiSelectMode) { |
| 34160 |
if (session.selection.inMultiSelectMode) |
| 34161 |
this.$onMultiSelect(); |
| 34162 |
else |
| 34163 |
this.$onSingleSelect(); |
| 34164 |
} |
| 34165 |
}; |
| 34166 |
function MultiSelect(editor) { |
| 34167 |
if (editor.$multiselectOnSessionChange) |
| 34168 |
return; |
| 34169 |
editor.$onAddRange = editor.$onAddRange.bind(editor); |
| 34170 |
editor.$onRemoveRange = editor.$onRemoveRange.bind(editor); |
| 34171 |
editor.$onMultiSelect = editor.$onMultiSelect.bind(editor); |
| 34172 |
editor.$onSingleSelect = editor.$onSingleSelect.bind(editor); |
| 34173 |
editor.$multiselectOnSessionChange = exports.onSessionChange.bind(editor); |
| 34174 |
editor.$checkMultiselectChange = editor.$checkMultiselectChange.bind(editor); |
| 34175 |
|
| 34176 |
editor.$multiselectOnSessionChange(editor); |
| 34177 |
editor.on("changeSession", editor.$multiselectOnSessionChange); |
| 34178 |
|
| 34179 |
editor.on("mousedown", onMouseDown); |
| 34180 |
editor.commands.addCommands(commands.defaultCommands); |
| 34181 |
|
| 34182 |
addAltCursorListeners(editor); |
| 34183 |
} |
| 34184 |
|
| 34185 |
function addAltCursorListeners(editor){ |
| 34186 |
var el = editor.textInput.getElement(); |
| 34187 |
var altCursor = false; |
| 34188 |
event.addListener(el, "keydown", function(e) { |
| 34189 |
var altDown = e.keyCode == 18 && !(e.ctrlKey || e.shiftKey || e.metaKey); |
| 34190 |
if (editor.$blockSelectEnabled && altDown) { |
| 34191 |
if (!altCursor) { |
| 34192 |
editor.renderer.setMouseCursor("crosshair"); |
| 34193 |
altCursor = true; |
| 34194 |
} |
| 34195 |
} else if (altCursor) { |
| 34196 |
reset(); |
| 34197 |
} |
| 34198 |
}); |
| 34199 |
|
| 34200 |
event.addListener(el, "keyup", reset); |
| 34201 |
event.addListener(el, "blur", reset); |
| 34202 |
function reset(e) { |
| 34203 |
if (altCursor) { |
| 34204 |
editor.renderer.setMouseCursor(""); |
| 34205 |
altCursor = false; |
| 34206 |
} |
| 34207 |
} |
| 34208 |
} |
| 34209 |
|
| 34210 |
exports.MultiSelect = MultiSelect; |
| 34211 |
|
| 34212 |
|
| 34213 |
acequire("./config").defineOptions(Editor.prototype, "editor", { |
| 34214 |
enableMultiselect: { |
| 34215 |
set: function(val) { |
| 34216 |
MultiSelect(this); |
| 34217 |
if (val) { |
| 34218 |
this.on("changeSession", this.$multiselectOnSessionChange); |
| 34219 |
this.on("mousedown", onMouseDown); |
| 34220 |
} else { |
| 34221 |
this.off("changeSession", this.$multiselectOnSessionChange); |
| 34222 |
this.off("mousedown", onMouseDown); |
| 34223 |
} |
| 34224 |
}, |
| 34225 |
value: true |
| 34226 |
}, |
| 34227 |
enableBlockSelect: { |
| 34228 |
set: function(val) { |
| 34229 |
this.$blockSelectEnabled = val; |
| 34230 |
}, |
| 34231 |
value: true |
| 34232 |
} |
| 34233 |
}); |
| 34234 |
|
| 34235 |
|
| 34236 |
|
| 34237 |
}); |
| 34238 |
|
| 34239 |
ace.define("ace/mode/folding/fold_mode",["require","exports","module","ace/range"], function(acequire, exports, module) { |
| 34240 |
"use strict"; |
| 34241 |
|
| 34242 |
var Range = acequire("../../range").Range; |
| 34243 |
|
| 34244 |
var FoldMode = exports.FoldMode = function() {}; |
| 34245 |
|
| 34246 |
(function() { |
| 34247 |
|
| 34248 |
this.foldingStartMarker = null; |
| 34249 |
this.foldingStopMarker = null; |
| 34250 |
this.getFoldWidget = function(session, foldStyle, row) { |
| 34251 |
var line = session.getLine(row); |
| 34252 |
if (this.foldingStartMarker.test(line)) |
| 34253 |
return "start"; |
| 34254 |
if (foldStyle == "markbeginend" |
| 34255 |
&& this.foldingStopMarker |
| 34256 |
&& this.foldingStopMarker.test(line)) |
| 34257 |
return "end"; |
| 34258 |
return ""; |
| 34259 |
}; |
| 34260 |
|
| 34261 |
this.getFoldWidgetRange = function(session, foldStyle, row) { |
| 34262 |
return null; |
| 34263 |
}; |
| 34264 |
|
| 34265 |
this.indentationBlock = function(session, row, column) { |
| 34266 |
var re = /\S/; |
| 34267 |
var line = session.getLine(row); |
| 34268 |
var startLevel = line.search(re); |
| 34269 |
if (startLevel == -1) |
| 34270 |
return; |
| 34271 |
|
| 34272 |
var startColumn = column || line.length; |
| 34273 |
var maxRow = session.getLength(); |
| 34274 |
var startRow = row; |
| 34275 |
var endRow = row; |
| 34276 |
|
| 34277 |
while (++row < maxRow) { |
| 34278 |
var level = session.getLine(row).search(re); |
| 34279 |
|
| 34280 |
if (level == -1) |
| 34281 |
continue; |
| 34282 |
|
| 34283 |
if (level <= startLevel) |
| 34284 |
break; |
| 34285 |
|
| 34286 |
endRow = row; |
| 34287 |
} |
| 34288 |
|
| 34289 |
if (endRow > startRow) { |
| 34290 |
var endColumn = session.getLine(endRow).length; |
| 34291 |
return new Range(startRow, startColumn, endRow, endColumn); |
| 34292 |
} |
| 34293 |
}; |
| 34294 |
|
| 34295 |
this.openingBracketBlock = function(session, bracket, row, column, typeRe) { |
| 34296 |
var start = {row: row, column: column + 1}; |
| 34297 |
var end = session.$findClosingBracket(bracket, start, typeRe); |
| 34298 |
if (!end) |
| 34299 |
return; |
| 34300 |
|
| 34301 |
var fw = session.foldWidgets[end.row]; |
| 34302 |
if (fw == null) |
| 34303 |
fw = session.getFoldWidget(end.row); |
| 34304 |
|
| 34305 |
if (fw == "start" && end.row > start.row) { |
| 34306 |
end.row --; |
| 34307 |
end.column = session.getLine(end.row).length; |
| 34308 |
} |
| 34309 |
return Range.fromPoints(start, end); |
| 34310 |
}; |
| 34311 |
|
| 34312 |
this.closingBracketBlock = function(session, bracket, row, column, typeRe) { |
| 34313 |
var end = {row: row, column: column}; |
| 34314 |
var start = session.$findOpeningBracket(bracket, end); |
| 34315 |
|
| 34316 |
if (!start) |
| 34317 |
return; |
| 34318 |
|
| 34319 |
start.column++; |
| 34320 |
end.column--; |
| 34321 |
|
| 34322 |
return Range.fromPoints(start, end); |
| 34323 |
}; |
| 34324 |
}).call(FoldMode.prototype); |
| 34325 |
|
| 34326 |
}); |
| 34327 |
|
| 34328 |
ace.define("ace/theme/textmate",["require","exports","module","ace/lib/dom"], function(acequire, exports, module) { |
| 34329 |
"use strict"; |
| 34330 |
|
| 34331 |
exports.isDark = false; |
| 34332 |
exports.cssClass = "ace-tm"; |
| 34333 |
exports.cssText = ".ace-tm .ace_gutter {\ |
| 34334 |
background: #f0f0f0;\ |
| 34335 |
color: #333;\ |
| 34336 |
}\ |
| 34337 |
.ace-tm .ace_print-margin {\ |
| 34338 |
width: 1px;\ |
| 34339 |
background: #e8e8e8;\ |
| 34340 |
}\ |
| 34341 |
.ace-tm .ace_fold {\ |
| 34342 |
background-color: #6B72E6;\ |
| 34343 |
}\ |
| 34344 |
.ace-tm {\ |
| 34345 |
background-color: #FFFFFF;\ |
| 34346 |
color: black;\ |
| 34347 |
}\ |
| 34348 |
.ace-tm .ace_cursor {\ |
| 34349 |
color: black;\ |
| 34350 |
}\ |
| 34351 |
.ace-tm .ace_invisible {\ |
| 34352 |
color: rgb(191, 191, 191);\ |
| 34353 |
}\ |
| 34354 |
.ace-tm .ace_storage,\ |
| 34355 |
.ace-tm .ace_keyword {\ |
| 34356 |
color: blue;\ |
| 34357 |
}\ |
| 34358 |
.ace-tm .ace_constant {\ |
| 34359 |
color: rgb(197, 6, 11);\ |
| 34360 |
}\ |
| 34361 |
.ace-tm .ace_constant.ace_buildin {\ |
| 34362 |
color: rgb(88, 72, 246);\ |
| 34363 |
}\ |
| 34364 |
.ace-tm .ace_constant.ace_language {\ |
| 34365 |
color: rgb(88, 92, 246);\ |
| 34366 |
}\ |
| 34367 |
.ace-tm .ace_constant.ace_library {\ |
| 34368 |
color: rgb(6, 150, 14);\ |
| 34369 |
}\ |
| 34370 |
.ace-tm .ace_invalid {\ |
| 34371 |
background-color: rgba(255, 0, 0, 0.1);\ |
| 34372 |
color: red;\ |
| 34373 |
}\ |
| 34374 |
.ace-tm .ace_support.ace_function {\ |
| 34375 |
color: rgb(60, 76, 114);\ |
| 34376 |
}\ |
| 34377 |
.ace-tm .ace_support.ace_constant {\ |
| 34378 |
color: rgb(6, 150, 14);\ |
| 34379 |
}\ |
| 34380 |
.ace-tm .ace_support.ace_type,\ |
| 34381 |
.ace-tm .ace_support.ace_class {\ |
| 34382 |
color: rgb(109, 121, 222);\ |
| 34383 |
}\ |
| 34384 |
.ace-tm .ace_keyword.ace_operator {\ |
| 34385 |
color: rgb(104, 118, 135);\ |
| 34386 |
}\ |
| 34387 |
.ace-tm .ace_string {\ |
| 34388 |
color: rgb(3, 106, 7);\ |
| 34389 |
}\ |
| 34390 |
.ace-tm .ace_comment {\ |
| 34391 |
color: rgb(76, 136, 107);\ |
| 34392 |
}\ |
| 34393 |
.ace-tm .ace_comment.ace_doc {\ |
| 34394 |
color: rgb(0, 102, 255);\ |
| 34395 |
}\ |
| 34396 |
.ace-tm .ace_comment.ace_doc.ace_tag {\ |
| 34397 |
color: rgb(128, 159, 191);\ |
| 34398 |
}\ |
| 34399 |
.ace-tm .ace_constant.ace_numeric {\ |
| 34400 |
color: rgb(0, 0, 205);\ |
| 34401 |
}\ |
| 34402 |
.ace-tm .ace_variable {\ |
| 34403 |
color: rgb(49, 132, 149);\ |
| 34404 |
}\ |
| 34405 |
.ace-tm .ace_xml-pe {\ |
| 34406 |
color: rgb(104, 104, 91);\ |
| 34407 |
}\ |
| 34408 |
.ace-tm .ace_entity.ace_name.ace_function {\ |
| 34409 |
color: #0000A2;\ |
| 34410 |
}\ |
| 34411 |
.ace-tm .ace_heading {\ |
| 34412 |
color: rgb(12, 7, 255);\ |
| 34413 |
}\ |
| 34414 |
.ace-tm .ace_list {\ |
| 34415 |
color:rgb(185, 6, 144);\ |
| 34416 |
}\ |
| 34417 |
.ace-tm .ace_meta.ace_tag {\ |
| 34418 |
color:rgb(0, 22, 142);\ |
| 34419 |
}\ |
| 34420 |
.ace-tm .ace_string.ace_regex {\ |
| 34421 |
color: rgb(255, 0, 0)\ |
| 34422 |
}\ |
| 34423 |
.ace-tm .ace_marker-layer .ace_selection {\ |
| 34424 |
background: rgb(181, 213, 255);\ |
| 34425 |
}\ |
| 34426 |
.ace-tm.ace_multiselect .ace_selection.ace_start {\ |
| 34427 |
box-shadow: 0 0 3px 0px white;\ |
| 34428 |
}\ |
| 34429 |
.ace-tm .ace_marker-layer .ace_step {\ |
| 34430 |
background: rgb(252, 255, 0);\ |
| 34431 |
}\ |
| 34432 |
.ace-tm .ace_marker-layer .ace_stack {\ |
| 34433 |
background: rgb(164, 229, 101);\ |
| 34434 |
}\ |
| 34435 |
.ace-tm .ace_marker-layer .ace_bracket {\ |
| 34436 |
margin: -1px 0 0 -1px;\ |
| 34437 |
border: 1px solid rgb(192, 192, 192);\ |
| 34438 |
}\ |
| 34439 |
.ace-tm .ace_marker-layer .ace_active-line {\ |
| 34440 |
background: rgba(0, 0, 0, 0.07);\ |
| 34441 |
}\ |
| 34442 |
.ace-tm .ace_gutter-active-line {\ |
| 34443 |
background-color : #dcdcdc;\ |
| 34444 |
}\ |
| 34445 |
.ace-tm .ace_marker-layer .ace_selected-word {\ |
| 34446 |
background: rgb(250, 250, 255);\ |
| 34447 |
border: 1px solid rgb(200, 200, 250);\ |
| 34448 |
}\ |
| 34449 |
.ace-tm .ace_indent-guide {\ |
| 34450 |
background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y;\ |
| 34451 |
}\ |
| 34452 |
"; |
| 34453 |
|
| 34454 |
var dom = acequire("../lib/dom"); |
| 34455 |
dom.importCssString(exports.cssText, exports.cssClass); |
| 34456 |
}); |
| 34457 |
|
| 34458 |
ace.define("ace/line_widgets",["require","exports","module","ace/lib/oop","ace/lib/dom","ace/range"], function(acequire, exports, module) { |
| 34459 |
"use strict"; |
| 34460 |
|
| 34461 |
var oop = acequire("./lib/oop"); |
| 34462 |
var dom = acequire("./lib/dom"); |
| 34463 |
var Range = acequire("./range").Range; |
| 34464 |
|
| 34465 |
|
| 34466 |
function LineWidgets(session) { |
| 34467 |
this.session = session; |
| 34468 |
this.session.widgetManager = this; |
| 34469 |
this.session.getRowLength = this.getRowLength; |
| 34470 |
this.session.$getWidgetScreenLength = this.$getWidgetScreenLength; |
| 34471 |
this.updateOnChange = this.updateOnChange.bind(this); |
| 34472 |
this.renderWidgets = this.renderWidgets.bind(this); |
| 34473 |
this.measureWidgets = this.measureWidgets.bind(this); |
| 34474 |
this.session._changedWidgets = []; |
| 34475 |
this.$onChangeEditor = this.$onChangeEditor.bind(this); |
| 34476 |
|
| 34477 |
this.session.on("change", this.updateOnChange); |
| 34478 |
this.session.on("changeFold", this.updateOnFold); |
| 34479 |
this.session.on("changeEditor", this.$onChangeEditor); |
| 34480 |
} |
| 34481 |
|
| 34482 |
(function() { |
| 34483 |
this.getRowLength = function(row) { |
| 34484 |
var h; |
| 34485 |
if (this.lineWidgets) |
| 34486 |
h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0; |
| 34487 |
else |
| 34488 |
h = 0; |
| 34489 |
if (!this.$useWrapMode || !this.$wrapData[row]) { |
| 34490 |
return 1 + h; |
| 34491 |
} else { |
| 34492 |
return this.$wrapData[row].length + 1 + h; |
| 34493 |
} |
| 34494 |
}; |
| 34495 |
|
| 34496 |
this.$getWidgetScreenLength = function() { |
| 34497 |
var screenRows = 0; |
| 34498 |
this.lineWidgets.forEach(function(w){ |
| 34499 |
if (w && w.rowCount && !w.hidden) |
| 34500 |
screenRows += w.rowCount; |
| 34501 |
}); |
| 34502 |
return screenRows; |
| 34503 |
}; |
| 34504 |
|
| 34505 |
this.$onChangeEditor = function(e) { |
| 34506 |
this.attach(e.editor); |
| 34507 |
}; |
| 34508 |
|
| 34509 |
this.attach = function(editor) { |
| 34510 |
if (editor && editor.widgetManager && editor.widgetManager != this) |
| 34511 |
editor.widgetManager.detach(); |
| 34512 |
|
| 34513 |
if (this.editor == editor) |
| 34514 |
return; |
| 34515 |
|
| 34516 |
this.detach(); |
| 34517 |
this.editor = editor; |
| 34518 |
|
| 34519 |
if (editor) { |
| 34520 |
editor.widgetManager = this; |
| 34521 |
editor.renderer.on("beforeRender", this.measureWidgets); |
| 34522 |
editor.renderer.on("afterRender", this.renderWidgets); |
| 34523 |
} |
| 34524 |
}; |
| 34525 |
this.detach = function(e) { |
| 34526 |
var editor = this.editor; |
| 34527 |
if (!editor) |
| 34528 |
return; |
| 34529 |
|
| 34530 |
this.editor = null; |
| 34531 |
editor.widgetManager = null; |
| 34532 |
|
| 34533 |
editor.renderer.off("beforeRender", this.measureWidgets); |
| 34534 |
editor.renderer.off("afterRender", this.renderWidgets); |
| 34535 |
var lineWidgets = this.session.lineWidgets; |
| 34536 |
lineWidgets && lineWidgets.forEach(function(w) { |
| 34537 |
if (w && w.el && w.el.parentNode) { |
| 34538 |
w._inDocument = false; |
| 34539 |
w.el.parentNode.removeChild(w.el); |
| 34540 |
} |
| 34541 |
}); |
| 34542 |
}; |
| 34543 |
|
| 34544 |
this.updateOnFold = function(e, session) { |
| 34545 |
var lineWidgets = session.lineWidgets; |
| 34546 |
if (!lineWidgets || !e.action) |
| 34547 |
return; |
| 34548 |
var fold = e.data; |
| 34549 |
var start = fold.start.row; |
| 34550 |
var end = fold.end.row; |
| 34551 |
var hide = e.action == "add"; |
| 34552 |
for (var i = start + 1; i < end; i++) { |
| 34553 |
if (lineWidgets[i]) |
| 34554 |
lineWidgets[i].hidden = hide; |
| 34555 |
} |
| 34556 |
if (lineWidgets[end]) { |
| 34557 |
if (hide) { |
| 34558 |
if (!lineWidgets[start]) |
| 34559 |
lineWidgets[start] = lineWidgets[end]; |
| 34560 |
else |
| 34561 |
lineWidgets[end].hidden = hide; |
| 34562 |
} else { |
| 34563 |
if (lineWidgets[start] == lineWidgets[end]) |
| 34564 |
lineWidgets[start] = undefined; |
| 34565 |
lineWidgets[end].hidden = hide; |
| 34566 |
} |
| 34567 |
} |
| 34568 |
}; |
| 34569 |
|
| 34570 |
this.updateOnChange = function(delta) { |
| 34571 |
var lineWidgets = this.session.lineWidgets; |
| 34572 |
if (!lineWidgets) return; |
| 34573 |
|
| 34574 |
var startRow = delta.start.row; |
| 34575 |
var len = delta.end.row - startRow; |
| 34576 |
|
| 34577 |
if (len === 0) { |
| 34578 |
} else if (delta.action == 'remove') { |
| 34579 |
var removed = lineWidgets.splice(startRow + 1, len); |
| 34580 |
removed.forEach(function(w) { |
| 34581 |
w && this.removeLineWidget(w); |
| 34582 |
}, this); |
| 34583 |
this.$updateRows(); |
| 34584 |
} else { |
| 34585 |
var args = new Array(len); |
| 34586 |
args.unshift(startRow, 0); |
| 34587 |
lineWidgets.splice.apply(lineWidgets, args); |
| 34588 |
this.$updateRows(); |
| 34589 |
} |
| 34590 |
}; |
| 34591 |
|
| 34592 |
this.$updateRows = function() { |
| 34593 |
var lineWidgets = this.session.lineWidgets; |
| 34594 |
if (!lineWidgets) return; |
| 34595 |
var noWidgets = true; |
| 34596 |
lineWidgets.forEach(function(w, i) { |
| 34597 |
if (w) { |
| 34598 |
noWidgets = false; |
| 34599 |
w.row = i; |
| 34600 |
while (w.$oldWidget) { |
| 34601 |
w.$oldWidget.row = i; |
| 34602 |
w = w.$oldWidget; |
| 34603 |
} |
| 34604 |
} |
| 34605 |
}); |
| 34606 |
if (noWidgets) |
| 34607 |
this.session.lineWidgets = null; |
| 34608 |
}; |
| 34609 |
|
| 34610 |
this.addLineWidget = function(w) { |
| 34611 |
if (!this.session.lineWidgets) |
| 34612 |
this.session.lineWidgets = new Array(this.session.getLength()); |
| 34613 |
|
| 34614 |
var old = this.session.lineWidgets[w.row]; |
| 34615 |
if (old) { |
| 34616 |
w.$oldWidget = old; |
| 34617 |
if (old.el && old.el.parentNode) { |
| 34618 |
old.el.parentNode.removeChild(old.el); |
| 34619 |
old._inDocument = false; |
| 34620 |
} |
| 34621 |
} |
| 34622 |
|
| 34623 |
this.session.lineWidgets[w.row] = w; |
| 34624 |
|
| 34625 |
w.session = this.session; |
| 34626 |
|
| 34627 |
var renderer = this.editor.renderer; |
| 34628 |
if (w.html && !w.el) { |
| 34629 |
w.el = dom.createElement("div"); |
| 34630 |
w.el.innerHTML = w.html; |
| 34631 |
} |
| 34632 |
if (w.el) { |
| 34633 |
dom.addCssClass(w.el, "ace_lineWidgetContainer"); |
| 34634 |
w.el.style.position = "absolute"; |
| 34635 |
w.el.style.zIndex = 5; |
| 34636 |
renderer.container.appendChild(w.el); |
| 34637 |
w._inDocument = true; |
| 34638 |
} |
| 34639 |
|
| 34640 |
if (!w.coverGutter) { |
| 34641 |
w.el.style.zIndex = 3; |
| 34642 |
} |
| 34643 |
if (!w.pixelHeight) { |
| 34644 |
w.pixelHeight = w.el.offsetHeight; |
| 34645 |
} |
| 34646 |
if (w.rowCount == null) { |
| 34647 |
w.rowCount = w.pixelHeight / renderer.layerConfig.lineHeight; |
| 34648 |
} |
| 34649 |
|
| 34650 |
var fold = this.session.getFoldAt(w.row, 0); |
| 34651 |
w.$fold = fold; |
| 34652 |
if (fold) { |
| 34653 |
var lineWidgets = this.session.lineWidgets; |
| 34654 |
if (w.row == fold.end.row && !lineWidgets[fold.start.row]) |
| 34655 |
lineWidgets[fold.start.row] = w; |
| 34656 |
else |
| 34657 |
w.hidden = true; |
| 34658 |
} |
| 34659 |
|
| 34660 |
this.session._emit("changeFold", {data:{start:{row: w.row}}}); |
| 34661 |
|
| 34662 |
this.$updateRows(); |
| 34663 |
this.renderWidgets(null, renderer); |
| 34664 |
this.onWidgetChanged(w); |
| 34665 |
return w; |
| 34666 |
}; |
| 34667 |
|
| 34668 |
this.removeLineWidget = function(w) { |
| 34669 |
w._inDocument = false; |
| 34670 |
w.session = null; |
| 34671 |
if (w.el && w.el.parentNode) |
| 34672 |
w.el.parentNode.removeChild(w.el); |
| 34673 |
if (w.editor && w.editor.destroy) try { |
| 34674 |
w.editor.destroy(); |
| 34675 |
} catch(e){} |
| 34676 |
if (this.session.lineWidgets) { |
| 34677 |
var w1 = this.session.lineWidgets[w.row] |
| 34678 |
if (w1 == w) { |
| 34679 |
this.session.lineWidgets[w.row] = w.$oldWidget; |
| 34680 |
if (w.$oldWidget) |
| 34681 |
this.onWidgetChanged(w.$oldWidget); |
| 34682 |
} else { |
| 34683 |
while (w1) { |
| 34684 |
if (w1.$oldWidget == w) { |
| 34685 |
w1.$oldWidget = w.$oldWidget; |
| 34686 |
break; |
| 34687 |
} |
| 34688 |
w1 = w1.$oldWidget; |
| 34689 |
} |
| 34690 |
} |
| 34691 |
} |
| 34692 |
this.session._emit("changeFold", {data:{start:{row: w.row}}}); |
| 34693 |
this.$updateRows(); |
| 34694 |
}; |
| 34695 |
|
| 34696 |
this.getWidgetsAtRow = function(row) { |
| 34697 |
var lineWidgets = this.session.lineWidgets; |
| 34698 |
var w = lineWidgets && lineWidgets[row]; |
| 34699 |
var list = []; |
| 34700 |
while (w) { |
| 34701 |
list.push(w); |
| 34702 |
w = w.$oldWidget; |
| 34703 |
} |
| 34704 |
return list; |
| 34705 |
}; |
| 34706 |
|
| 34707 |
this.onWidgetChanged = function(w) { |
| 34708 |
this.session._changedWidgets.push(w); |
| 34709 |
this.editor && this.editor.renderer.updateFull(); |
| 34710 |
}; |
| 34711 |
|
| 34712 |
this.measureWidgets = function(e, renderer) { |
| 34713 |
var changedWidgets = this.session._changedWidgets; |
| 34714 |
var config = renderer.layerConfig; |
| 34715 |
|
| 34716 |
if (!changedWidgets || !changedWidgets.length) return; |
| 34717 |
var min = Infinity; |
| 34718 |
for (var i = 0; i < changedWidgets.length; i++) { |
| 34719 |
var w = changedWidgets[i]; |
| 34720 |
if (!w || !w.el) continue; |
| 34721 |
if (w.session != this.session) continue; |
| 34722 |
if (!w._inDocument) { |
| 34723 |
if (this.session.lineWidgets[w.row] != w) |
| 34724 |
continue; |
| 34725 |
w._inDocument = true; |
| 34726 |
renderer.container.appendChild(w.el); |
| 34727 |
} |
| 34728 |
|
| 34729 |
w.h = w.el.offsetHeight; |
| 34730 |
|
| 34731 |
if (!w.fixedWidth) { |
| 34732 |
w.w = w.el.offsetWidth; |
| 34733 |
w.screenWidth = Math.ceil(w.w / config.characterWidth); |
| 34734 |
} |
| 34735 |
|
| 34736 |
var rowCount = w.h / config.lineHeight; |
| 34737 |
if (w.coverLine) { |
| 34738 |
rowCount -= this.session.getRowLineCount(w.row); |
| 34739 |
if (rowCount < 0) |
| 34740 |
rowCount = 0; |
| 34741 |
} |
| 34742 |
if (w.rowCount != rowCount) { |
| 34743 |
w.rowCount = rowCount; |
| 34744 |
if (w.row < min) |
| 34745 |
min = w.row; |
| 34746 |
} |
| 34747 |
} |
| 34748 |
if (min != Infinity) { |
| 34749 |
this.session._emit("changeFold", {data:{start:{row: min}}}); |
| 34750 |
this.session.lineWidgetWidth = null; |
| 34751 |
} |
| 34752 |
this.session._changedWidgets = []; |
| 34753 |
}; |
| 34754 |
|
| 34755 |
this.renderWidgets = function(e, renderer) { |
| 34756 |
var config = renderer.layerConfig; |
| 34757 |
var lineWidgets = this.session.lineWidgets; |
| 34758 |
if (!lineWidgets) |
| 34759 |
return; |
| 34760 |
var first = Math.min(this.firstRow, config.firstRow); |
| 34761 |
var last = Math.max(this.lastRow, config.lastRow, lineWidgets.length); |
| 34762 |
|
| 34763 |
while (first > 0 && !lineWidgets[first]) |
| 34764 |
first--; |
| 34765 |
|
| 34766 |
this.firstRow = config.firstRow; |
| 34767 |
this.lastRow = config.lastRow; |
| 34768 |
|
| 34769 |
renderer.$cursorLayer.config = config; |
| 34770 |
for (var i = first; i <= last; i++) { |
| 34771 |
var w = lineWidgets[i]; |
| 34772 |
if (!w || !w.el) continue; |
| 34773 |
if (w.hidden) { |
| 34774 |
w.el.style.top = -100 - (w.pixelHeight || 0) + "px"; |
| 34775 |
continue; |
| 34776 |
} |
| 34777 |
if (!w._inDocument) { |
| 34778 |
w._inDocument = true; |
| 34779 |
renderer.container.appendChild(w.el); |
| 34780 |
} |
| 34781 |
var top = renderer.$cursorLayer.getPixelPosition({row: i, column:0}, true).top; |
| 34782 |
if (!w.coverLine) |
| 34783 |
top += config.lineHeight * this.session.getRowLineCount(w.row); |
| 34784 |
w.el.style.top = top - config.offset + "px"; |
| 34785 |
|
| 34786 |
var left = w.coverGutter ? 0 : renderer.gutterWidth; |
| 34787 |
if (!w.fixedWidth) |
| 34788 |
left -= renderer.scrollLeft; |
| 34789 |
w.el.style.left = left + "px"; |
| 34790 |
|
| 34791 |
if (w.fullWidth && w.screenWidth) { |
| 34792 |
w.el.style.minWidth = config.width + 2 * config.padding + "px"; |
| 34793 |
} |
| 34794 |
|
| 34795 |
if (w.fixedWidth) { |
| 34796 |
w.el.style.right = renderer.scrollBar.getWidth() + "px"; |
| 34797 |
} else { |
| 34798 |
w.el.style.right = ""; |
| 34799 |
} |
| 34800 |
} |
| 34801 |
}; |
| 34802 |
|
| 34803 |
}).call(LineWidgets.prototype); |
| 34804 |
|
| 34805 |
|
| 34806 |
exports.LineWidgets = LineWidgets; |
| 34807 |
|
| 34808 |
}); |
| 34809 |
|
| 34810 |
ace.define("ace/ext/error_marker",["require","exports","module","ace/line_widgets","ace/lib/dom","ace/range"], function(acequire, exports, module) { |
| 34811 |
"use strict"; |
| 34812 |
var LineWidgets = acequire("../line_widgets").LineWidgets; |
| 34813 |
var dom = acequire("../lib/dom"); |
| 34814 |
var Range = acequire("../range").Range; |
| 34815 |
|
| 34816 |
function binarySearch(array, needle, comparator) { |
| 34817 |
var first = 0; |
| 34818 |
var last = array.length - 1; |
| 34819 |
|
| 34820 |
while (first <= last) { |
| 34821 |
var mid = (first + last) >> 1; |
| 34822 |
var c = comparator(needle, array[mid]); |
| 34823 |
if (c > 0) |
| 34824 |
first = mid + 1; |
| 34825 |
else if (c < 0) |
| 34826 |
last = mid - 1; |
| 34827 |
else |
| 34828 |
return mid; |
| 34829 |
} |
| 34830 |
return -(first + 1); |
| 34831 |
} |
| 34832 |
|
| 34833 |
function findAnnotations(session, row, dir) { |
| 34834 |
var annotations = session.getAnnotations().sort(Range.comparePoints); |
| 34835 |
if (!annotations.length) |
| 34836 |
return; |
| 34837 |
|
| 34838 |
var i = binarySearch(annotations, {row: row, column: -1}, Range.comparePoints); |
| 34839 |
if (i < 0) |
| 34840 |
i = -i - 1; |
| 34841 |
|
| 34842 |
if (i >= annotations.length) |
| 34843 |
i = dir > 0 ? 0 : annotations.length - 1; |
| 34844 |
else if (i === 0 && dir < 0) |
| 34845 |
i = annotations.length - 1; |
| 34846 |
|
| 34847 |
var annotation = annotations[i]; |
| 34848 |
if (!annotation || !dir) |
| 34849 |
return; |
| 34850 |
|
| 34851 |
if (annotation.row === row) { |
| 34852 |
do { |
| 34853 |
annotation = annotations[i += dir]; |
| 34854 |
} while (annotation && annotation.row === row); |
| 34855 |
if (!annotation) |
| 34856 |
return annotations.slice(); |
| 34857 |
} |
| 34858 |
|
| 34859 |
|
| 34860 |
var matched = []; |
| 34861 |
row = annotation.row; |
| 34862 |
do { |
| 34863 |
matched[dir < 0 ? "unshift" : "push"](annotation); |
| 34864 |
annotation = annotations[i += dir]; |
| 34865 |
} while (annotation && annotation.row == row); |
| 34866 |
return matched.length && matched; |
| 34867 |
} |
| 34868 |
|
| 34869 |
exports.showErrorMarker = function(editor, dir) { |
| 34870 |
var session = editor.session; |
| 34871 |
if (!session.widgetManager) { |
| 34872 |
session.widgetManager = new LineWidgets(session); |
| 34873 |
session.widgetManager.attach(editor); |
| 34874 |
} |
| 34875 |
|
| 34876 |
var pos = editor.getCursorPosition(); |
| 34877 |
var row = pos.row; |
| 34878 |
var oldWidget = session.widgetManager.getWidgetsAtRow(row).filter(function(w) { |
| 34879 |
return w.type == "errorMarker"; |
| 34880 |
})[0]; |
| 34881 |
if (oldWidget) { |
| 34882 |
oldWidget.destroy(); |
| 34883 |
} else { |
| 34884 |
row -= dir; |
| 34885 |
} |
| 34886 |
var annotations = findAnnotations(session, row, dir); |
| 34887 |
var gutterAnno; |
| 34888 |
if (annotations) { |
| 34889 |
var annotation = annotations[0]; |
| 34890 |
pos.column = (annotation.pos && typeof annotation.column != "number" |
| 34891 |
? annotation.pos.sc |
| 34892 |
: annotation.column) || 0; |
| 34893 |
pos.row = annotation.row; |
| 34894 |
gutterAnno = editor.renderer.$gutterLayer.$annotations[pos.row]; |
| 34895 |
} else if (oldWidget) { |
| 34896 |
return; |
| 34897 |
} else { |
| 34898 |
gutterAnno = { |
| 34899 |
text: ["Looks good!"], |
| 34900 |
className: "ace_ok" |
| 34901 |
}; |
| 34902 |
} |
| 34903 |
editor.session.unfold(pos.row); |
| 34904 |
editor.selection.moveToPosition(pos); |
| 34905 |
|
| 34906 |
var w = { |
| 34907 |
row: pos.row, |
| 34908 |
fixedWidth: true, |
| 34909 |
coverGutter: true, |
| 34910 |
el: dom.createElement("div"), |
| 34911 |
type: "errorMarker" |
| 34912 |
}; |
| 34913 |
var el = w.el.appendChild(dom.createElement("div")); |
| 34914 |
var arrow = w.el.appendChild(dom.createElement("div")); |
| 34915 |
arrow.className = "error_widget_arrow " + gutterAnno.className; |
| 34916 |
|
| 34917 |
var left = editor.renderer.$cursorLayer |
| 34918 |
.getPixelPosition(pos).left; |
| 34919 |
arrow.style.left = left + editor.renderer.gutterWidth - 5 + "px"; |
| 34920 |
|
| 34921 |
w.el.className = "error_widget_wrapper"; |
| 34922 |
el.className = "error_widget " + gutterAnno.className; |
| 34923 |
el.innerHTML = gutterAnno.text.join("<br>"); |
| 34924 |
|
| 34925 |
el.appendChild(dom.createElement("div")); |
| 34926 |
|
| 34927 |
var kb = function(_, hashId, keyString) { |
| 34928 |
if (hashId === 0 && (keyString === "esc" || keyString === "return")) { |
| 34929 |
w.destroy(); |
| 34930 |
return {command: "null"}; |
| 34931 |
} |
| 34932 |
}; |
| 34933 |
|
| 34934 |
w.destroy = function() { |
| 34935 |
if (editor.$mouseHandler.isMousePressed) |
| 34936 |
return; |
| 34937 |
editor.keyBinding.removeKeyboardHandler(kb); |
| 34938 |
session.widgetManager.removeLineWidget(w); |
| 34939 |
editor.off("changeSelection", w.destroy); |
| 34940 |
editor.off("changeSession", w.destroy); |
| 34941 |
editor.off("mouseup", w.destroy); |
| 34942 |
editor.off("change", w.destroy); |
| 34943 |
}; |
| 34944 |
|
| 34945 |
editor.keyBinding.addKeyboardHandler(kb); |
| 34946 |
editor.on("changeSelection", w.destroy); |
| 34947 |
editor.on("changeSession", w.destroy); |
| 34948 |
editor.on("mouseup", w.destroy); |
| 34949 |
editor.on("change", w.destroy); |
| 34950 |
|
| 34951 |
editor.session.widgetManager.addLineWidget(w); |
| 34952 |
|
| 34953 |
w.el.onmousedown = editor.focus.bind(editor); |
| 34954 |
|
| 34955 |
editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight}); |
| 34956 |
}; |
| 34957 |
|
| 34958 |
|
| 34959 |
dom.importCssString("\ |
| 34960 |
.error_widget_wrapper {\ |
| 34961 |
background: inherit;\ |
| 34962 |
color: inherit;\ |
| 34963 |
border:none\ |
| 34964 |
}\ |
| 34965 |
.error_widget {\ |
| 34966 |
border-top: solid 2px;\ |
| 34967 |
border-bottom: solid 2px;\ |
| 34968 |
margin: 5px 0;\ |
| 34969 |
padding: 10px 40px;\ |
| 34970 |
white-space: pre-wrap;\ |
| 34971 |
}\ |
| 34972 |
.error_widget.ace_error, .error_widget_arrow.ace_error{\ |
| 34973 |
border-color: #ff5a5a\ |
| 34974 |
}\ |
| 34975 |
.error_widget.ace_warning, .error_widget_arrow.ace_warning{\ |
| 34976 |
border-color: #F1D817\ |
| 34977 |
}\ |
| 34978 |
.error_widget.ace_info, .error_widget_arrow.ace_info{\ |
| 34979 |
border-color: #5a5a5a\ |
| 34980 |
}\ |
| 34981 |
.error_widget.ace_ok, .error_widget_arrow.ace_ok{\ |
| 34982 |
border-color: #5aaa5a\ |
| 34983 |
}\ |
| 34984 |
.error_widget_arrow {\ |
| 34985 |
position: absolute;\ |
| 34986 |
border: solid 5px;\ |
| 34987 |
border-top-color: transparent!important;\ |
| 34988 |
border-right-color: transparent!important;\ |
| 34989 |
border-left-color: transparent!important;\ |
| 34990 |
top: -5px;\ |
| 34991 |
}\ |
| 34992 |
", ""); |
| 34993 |
|
| 34994 |
}); |
| 34995 |
|
| 34996 |
ace.define("ace/ace",["require","exports","module","ace/lib/fixoldbrowsers","ace/lib/dom","ace/lib/event","ace/editor","ace/edit_session","ace/undomanager","ace/virtual_renderer","ace/worker/worker_client","ace/keyboard/hash_handler","ace/placeholder","ace/multi_select","ace/mode/folding/fold_mode","ace/theme/textmate","ace/ext/error_marker","ace/config"], function(acequire, exports, module) { |
| 34997 |
"use strict"; |
| 34998 |
|
| 34999 |
acequire("./lib/fixoldbrowsers"); |
| 35000 |
|
| 35001 |
var dom = acequire("./lib/dom"); |
| 35002 |
var event = acequire("./lib/event"); |
| 35003 |
|
| 35004 |
var Editor = acequire("./editor").Editor; |
| 35005 |
var EditSession = acequire("./edit_session").EditSession; |
| 35006 |
var UndoManager = acequire("./undomanager").UndoManager; |
| 35007 |
var Renderer = acequire("./virtual_renderer").VirtualRenderer; |
| 35008 |
acequire("./worker/worker_client"); |
| 35009 |
acequire("./keyboard/hash_handler"); |
| 35010 |
acequire("./placeholder"); |
| 35011 |
acequire("./multi_select"); |
| 35012 |
acequire("./mode/folding/fold_mode"); |
| 35013 |
acequire("./theme/textmate"); |
| 35014 |
acequire("./ext/error_marker"); |
| 35015 |
|
| 35016 |
exports.config = acequire("./config"); |
| 35017 |
exports.acequire = acequire; |
| 35018 |
exports.edit = function(el) { |
| 35019 |
if (typeof el == "string") { |
| 35020 |
var _id = el; |
| 35021 |
el = document.getElementById(_id); |
| 35022 |
if (!el) |
| 35023 |
throw new Error("ace.edit can't find div #" + _id); |
| 35024 |
} |
| 35025 |
|
| 35026 |
if (el && el.env && el.env.editor instanceof Editor) |
| 35027 |
return el.env.editor; |
| 35028 |
|
| 35029 |
var value = ""; |
| 35030 |
if (el && /input|textarea/i.test(el.tagName)) { |
| 35031 |
var oldNode = el; |
| 35032 |
value = oldNode.value; |
| 35033 |
el = dom.createElement("pre"); |
| 35034 |
oldNode.parentNode.replaceChild(el, oldNode); |
| 35035 |
} else if (el) { |
| 35036 |
value = dom.getInnerText(el); |
| 35037 |
el.innerHTML = ""; |
| 35038 |
} |
| 35039 |
|
| 35040 |
var doc = exports.createEditSession(value); |
| 35041 |
|
| 35042 |
var editor = new Editor(new Renderer(el)); |
| 35043 |
editor.setSession(doc); |
| 35044 |
|
| 35045 |
var env = { |
| 35046 |
document: doc, |
| 35047 |
editor: editor, |
| 35048 |
onResize: editor.resize.bind(editor, null) |
| 35049 |
}; |
| 35050 |
if (oldNode) env.textarea = oldNode; |
| 35051 |
event.addListener(window, "resize", env.onResize); |
| 35052 |
editor.on("destroy", function() { |
| 35053 |
event.removeListener(window, "resize", env.onResize); |
| 35054 |
env.editor.container.env = null; // prevent memory leak on old ie |
| 35055 |
}); |
| 35056 |
editor.container.env = editor.env = env; |
| 35057 |
return editor; |
| 35058 |
}; |
| 35059 |
exports.createEditSession = function(text, mode) { |
| 35060 |
var doc = new EditSession(text, mode); |
| 35061 |
doc.setUndoManager(new UndoManager()); |
| 35062 |
return doc; |
| 35063 |
} |
| 35064 |
exports.EditSession = EditSession; |
| 35065 |
exports.UndoManager = UndoManager; |
| 35066 |
exports.version = "1.2.3"; |
| 35067 |
}); |
| 35068 |
(function() { |
| 35069 |
ace.acequire(["ace/ace"], function(a) { |
| 35070 |
a && a.config.init(true); |
| 35071 |
if (!window.ace) |
| 35072 |
window.ace = a; |
| 35073 |
for (var key in a) if (a.hasOwnProperty(key)) |
| 35074 |
window.ace[key] = a[key]; |
| 35075 |
}); |
| 35076 |
})(); |
| 35077 |
|
| 35078 |
module.exports = window.ace.acequire("ace/ace"); |
| 35079 |
|
| 35080 |
/***/ }, |
| 35081 |
/* 65 */ |
| 35082 |
/***/ function(module, exports) { |
| 35083 |
|
| 35084 |
module.exports = function() { throw new Error("define cannot be used indirect"); }; |
| 35085 |
|
| 35086 |
|
| 35087 |
/***/ }, |
| 35088 |
/* 66 */ |
| 35089 |
/***/ function(module, exports) { |
| 35090 |
|
| 35091 |
/* WEBPACK VAR INJECTION */(function(global) {module.exports = get_blob() |
| 35092 |
|
| 35093 |
function get_blob() { |
| 35094 |
if(global.Blob) { |
| 35095 |
try { |
| 35096 |
new Blob(['asdf'], {type: 'text/plain'}) |
| 35097 |
return Blob |
| 35098 |
} catch(err) {} |
| 35099 |
} |
| 35100 |
|
| 35101 |
var Builder = global.WebKitBlobBuilder || |
| 35102 |
global.MozBlobBuilder || |
| 35103 |
global.MSBlobBuilder |
| 35104 |
|
| 35105 |
return function(parts, bag) { |
| 35106 |
var builder = new Builder |
| 35107 |
, endings = bag.endings |
| 35108 |
, type = bag.type |
| 35109 |
|
| 35110 |
if(endings) for(var i = 0, len = parts.length; i < len; ++i) { |
| 35111 |
builder.append(parts[i], endings) |
| 35112 |
} else for(var i = 0, len = parts.length; i < len; ++i) { |
| 35113 |
builder.append(parts[i]) |
| 35114 |
} |
| 35115 |
|
| 35116 |
return type ? builder.getBlob(type) : builder.getBlob() |
| 35117 |
} |
| 35118 |
} |
| 35119 |
|
| 35120 |
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }()))) |
| 35121 |
|
| 35122 |
/***/ }, |
| 35123 |
/* 67 */ |
| 35124 |
/***/ function(module, exports, __webpack_require__) { |
| 35125 |
|
| 35126 |
ace.define("ace/mode/json_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(acequire, exports, module) { |
| 35127 |
"use strict"; |
| 35128 |
|
| 35129 |
var oop = acequire("../lib/oop"); |
| 35130 |
var TextHighlightRules = acequire("./text_highlight_rules").TextHighlightRules; |
| 35131 |
|
| 35132 |
var JsonHighlightRules = function() { |
| 35133 |
this.$rules = { |
| 35134 |
"start" : [ |
| 35135 |
{ |
| 35136 |
token : "variable", // single line |
| 35137 |
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]\\s*(?=:)' |
| 35138 |
}, { |
| 35139 |
token : "string", // single line |
| 35140 |
regex : '"', |
| 35141 |
next : "string" |
| 35142 |
}, { |
| 35143 |
token : "constant.numeric", // hex |
| 35144 |
regex : "0[xX][0-9a-fA-F]+\\b" |
| 35145 |
}, { |
| 35146 |
token : "constant.numeric", // float |
| 35147 |
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" |
| 35148 |
}, { |
| 35149 |
token : "constant.language.boolean", |
| 35150 |
regex : "(?:true|false)\\b" |
| 35151 |
}, { |
| 35152 |
token : "invalid.illegal", // single quoted strings are not allowed |
| 35153 |
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" |
| 35154 |
}, { |
| 35155 |
token : "invalid.illegal", // comments are not allowed |
| 35156 |
regex : "\\/\\/.*$" |
| 35157 |
}, { |
| 35158 |
token : "paren.lparen", |
| 35159 |
regex : "[[({]" |
| 35160 |
}, { |
| 35161 |
token : "paren.rparen", |
| 35162 |
regex : "[\\])}]" |
| 35163 |
}, { |
| 35164 |
token : "text", |
| 35165 |
regex : "\\s+" |
| 35166 |
} |
| 35167 |
], |
| 35168 |
"string" : [ |
| 35169 |
{ |
| 35170 |
token : "constant.language.escape", |
| 35171 |
regex : /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|["\\\/bfnrt])/ |
| 35172 |
}, { |
| 35173 |
token : "string", |
| 35174 |
regex : '[^"\\\\]+' |
| 35175 |
}, { |
| 35176 |
token : "string", |
| 35177 |
regex : '"', |
| 35178 |
next : "start" |
| 35179 |
}, { |
| 35180 |
token : "string", |
| 35181 |
regex : "", |
| 35182 |
next : "start" |
| 35183 |
} |
| 35184 |
] |
| 35185 |
}; |
| 35186 |
|
| 35187 |
}; |
| 35188 |
|
| 35189 |
oop.inherits(JsonHighlightRules, TextHighlightRules); |
| 35190 |
|
| 35191 |
exports.JsonHighlightRules = JsonHighlightRules; |
| 35192 |
}); |
| 35193 |
|
| 35194 |
ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(acequire, exports, module) { |
| 35195 |
"use strict"; |
| 35196 |
|
| 35197 |
var Range = acequire("../range").Range; |
| 35198 |
|
| 35199 |
var MatchingBraceOutdent = function() {}; |
| 35200 |
|
| 35201 |
(function() { |
| 35202 |
|
| 35203 |
this.checkOutdent = function(line, input) { |
| 35204 |
if (! /^\s+$/.test(line)) |
| 35205 |
return false; |
| 35206 |
|
| 35207 |
return /^\s*\}/.test(input); |
| 35208 |
}; |
| 35209 |
|
| 35210 |
this.autoOutdent = function(doc, row) { |
| 35211 |
var line = doc.getLine(row); |
| 35212 |
var match = line.match(/^(\s*\})/); |
| 35213 |
|
| 35214 |
if (!match) return 0; |
| 35215 |
|
| 35216 |
var column = match[1].length; |
| 35217 |
var openBracePos = doc.findMatchingBracket({row: row, column: column}); |
| 35218 |
|
| 35219 |
if (!openBracePos || openBracePos.row == row) return 0; |
| 35220 |
|
| 35221 |
var indent = this.$getIndent(doc.getLine(openBracePos.row)); |
| 35222 |
doc.replace(new Range(row, 0, row, column-1), indent); |
| 35223 |
}; |
| 35224 |
|
| 35225 |
this.$getIndent = function(line) { |
| 35226 |
return line.match(/^\s*/)[0]; |
| 35227 |
}; |
| 35228 |
|
| 35229 |
}).call(MatchingBraceOutdent.prototype); |
| 35230 |
|
| 35231 |
exports.MatchingBraceOutdent = MatchingBraceOutdent; |
| 35232 |
}); |
| 35233 |
|
| 35234 |
ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(acequire, exports, module) { |
| 35235 |
"use strict"; |
| 35236 |
|
| 35237 |
var oop = acequire("../../lib/oop"); |
| 35238 |
var Behaviour = acequire("../behaviour").Behaviour; |
| 35239 |
var TokenIterator = acequire("../../token_iterator").TokenIterator; |
| 35240 |
var lang = acequire("../../lib/lang"); |
| 35241 |
|
| 35242 |
var SAFE_INSERT_IN_TOKENS = |
| 35243 |
["text", "paren.rparen", "punctuation.operator"]; |
| 35244 |
var SAFE_INSERT_BEFORE_TOKENS = |
| 35245 |
["text", "paren.rparen", "punctuation.operator", "comment"]; |
| 35246 |
|
| 35247 |
var context; |
| 35248 |
var contextCache = {}; |
| 35249 |
var initContext = function(editor) { |
| 35250 |
var id = -1; |
| 35251 |
if (editor.multiSelect) { |
| 35252 |
id = editor.selection.index; |
| 35253 |
if (contextCache.rangeCount != editor.multiSelect.rangeCount) |
| 35254 |
contextCache = {rangeCount: editor.multiSelect.rangeCount}; |
| 35255 |
} |
| 35256 |
if (contextCache[id]) |
| 35257 |
return context = contextCache[id]; |
| 35258 |
context = contextCache[id] = { |
| 35259 |
autoInsertedBrackets: 0, |
| 35260 |
autoInsertedRow: -1, |
| 35261 |
autoInsertedLineEnd: "", |
| 35262 |
maybeInsertedBrackets: 0, |
| 35263 |
maybeInsertedRow: -1, |
| 35264 |
maybeInsertedLineStart: "", |
| 35265 |
maybeInsertedLineEnd: "" |
| 35266 |
}; |
| 35267 |
}; |
| 35268 |
|
| 35269 |
var getWrapped = function(selection, selected, opening, closing) { |
| 35270 |
var rowDiff = selection.end.row - selection.start.row; |
| 35271 |
return { |
| 35272 |
text: opening + selected + closing, |
| 35273 |
selection: [ |
| 35274 |
0, |
| 35275 |
selection.start.column + 1, |
| 35276 |
rowDiff, |
| 35277 |
selection.end.column + (rowDiff ? 0 : 1) |
| 35278 |
] |
| 35279 |
}; |
| 35280 |
}; |
| 35281 |
|
| 35282 |
var CstyleBehaviour = function() { |
| 35283 |
this.add("braces", "insertion", function(state, action, editor, session, text) { |
| 35284 |
var cursor = editor.getCursorPosition(); |
| 35285 |
var line = session.doc.getLine(cursor.row); |
| 35286 |
if (text == '{') { |
| 35287 |
initContext(editor); |
| 35288 |
var selection = editor.getSelectionRange(); |
| 35289 |
var selected = session.doc.getTextRange(selection); |
| 35290 |
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) { |
| 35291 |
return getWrapped(selection, selected, '{', '}'); |
| 35292 |
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) { |
| 35293 |
if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) { |
| 35294 |
CstyleBehaviour.recordAutoInsert(editor, session, "}"); |
| 35295 |
return { |
| 35296 |
text: '{}', |
| 35297 |
selection: [1, 1] |
| 35298 |
}; |
| 35299 |
} else { |
| 35300 |
CstyleBehaviour.recordMaybeInsert(editor, session, "{"); |
| 35301 |
return { |
| 35302 |
text: '{', |
| 35303 |
selection: [1, 1] |
| 35304 |
}; |
| 35305 |
} |
| 35306 |
} |
| 35307 |
} else if (text == '}') { |
| 35308 |
initContext(editor); |
| 35309 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
| 35310 |
if (rightChar == '}') { |
| 35311 |
var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row}); |
| 35312 |
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { |
| 35313 |
CstyleBehaviour.popAutoInsertedClosing(); |
| 35314 |
return { |
| 35315 |
text: '', |
| 35316 |
selection: [1, 1] |
| 35317 |
}; |
| 35318 |
} |
| 35319 |
} |
| 35320 |
} else if (text == "\n" || text == "\r\n") { |
| 35321 |
initContext(editor); |
| 35322 |
var closing = ""; |
| 35323 |
if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) { |
| 35324 |
closing = lang.stringRepeat("}", context.maybeInsertedBrackets); |
| 35325 |
CstyleBehaviour.clearMaybeInsertedClosing(); |
| 35326 |
} |
| 35327 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
| 35328 |
if (rightChar === '}') { |
| 35329 |
var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}'); |
| 35330 |
if (!openBracePos) |
| 35331 |
return null; |
| 35332 |
var next_indent = this.$getIndent(session.getLine(openBracePos.row)); |
| 35333 |
} else if (closing) { |
| 35334 |
var next_indent = this.$getIndent(line); |
| 35335 |
} else { |
| 35336 |
CstyleBehaviour.clearMaybeInsertedClosing(); |
| 35337 |
return; |
| 35338 |
} |
| 35339 |
var indent = next_indent + session.getTabString(); |
| 35340 |
|
| 35341 |
return { |
| 35342 |
text: '\n' + indent + '\n' + next_indent + closing, |
| 35343 |
selection: [1, indent.length, 1, indent.length] |
| 35344 |
}; |
| 35345 |
} else { |
| 35346 |
CstyleBehaviour.clearMaybeInsertedClosing(); |
| 35347 |
} |
| 35348 |
}); |
| 35349 |
|
| 35350 |
this.add("braces", "deletion", function(state, action, editor, session, range) { |
| 35351 |
var selected = session.doc.getTextRange(range); |
| 35352 |
if (!range.isMultiLine() && selected == '{') { |
| 35353 |
initContext(editor); |
| 35354 |
var line = session.doc.getLine(range.start.row); |
| 35355 |
var rightChar = line.substring(range.end.column, range.end.column + 1); |
| 35356 |
if (rightChar == '}') { |
| 35357 |
range.end.column++; |
| 35358 |
return range; |
| 35359 |
} else { |
| 35360 |
context.maybeInsertedBrackets--; |
| 35361 |
} |
| 35362 |
} |
| 35363 |
}); |
| 35364 |
|
| 35365 |
this.add("parens", "insertion", function(state, action, editor, session, text) { |
| 35366 |
if (text == '(') { |
| 35367 |
initContext(editor); |
| 35368 |
var selection = editor.getSelectionRange(); |
| 35369 |
var selected = session.doc.getTextRange(selection); |
| 35370 |
if (selected !== "" && editor.getWrapBehavioursEnabled()) { |
| 35371 |
return getWrapped(selection, selected, '(', ')'); |
| 35372 |
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) { |
| 35373 |
CstyleBehaviour.recordAutoInsert(editor, session, ")"); |
| 35374 |
return { |
| 35375 |
text: '()', |
| 35376 |
selection: [1, 1] |
| 35377 |
}; |
| 35378 |
} |
| 35379 |
} else if (text == ')') { |
| 35380 |
initContext(editor); |
| 35381 |
var cursor = editor.getCursorPosition(); |
| 35382 |
var line = session.doc.getLine(cursor.row); |
| 35383 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
| 35384 |
if (rightChar == ')') { |
| 35385 |
var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row}); |
| 35386 |
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { |
| 35387 |
CstyleBehaviour.popAutoInsertedClosing(); |
| 35388 |
return { |
| 35389 |
text: '', |
| 35390 |
selection: [1, 1] |
| 35391 |
}; |
| 35392 |
} |
| 35393 |
} |
| 35394 |
} |
| 35395 |
}); |
| 35396 |
|
| 35397 |
this.add("parens", "deletion", function(state, action, editor, session, range) { |
| 35398 |
var selected = session.doc.getTextRange(range); |
| 35399 |
if (!range.isMultiLine() && selected == '(') { |
| 35400 |
initContext(editor); |
| 35401 |
var line = session.doc.getLine(range.start.row); |
| 35402 |
var rightChar = line.substring(range.start.column + 1, range.start.column + 2); |
| 35403 |
if (rightChar == ')') { |
| 35404 |
range.end.column++; |
| 35405 |
return range; |
| 35406 |
} |
| 35407 |
} |
| 35408 |
}); |
| 35409 |
|
| 35410 |
this.add("brackets", "insertion", function(state, action, editor, session, text) { |
| 35411 |
if (text == '[') { |
| 35412 |
initContext(editor); |
| 35413 |
var selection = editor.getSelectionRange(); |
| 35414 |
var selected = session.doc.getTextRange(selection); |
| 35415 |
if (selected !== "" && editor.getWrapBehavioursEnabled()) { |
| 35416 |
return getWrapped(selection, selected, '[', ']'); |
| 35417 |
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) { |
| 35418 |
CstyleBehaviour.recordAutoInsert(editor, session, "]"); |
| 35419 |
return { |
| 35420 |
text: '[]', |
| 35421 |
selection: [1, 1] |
| 35422 |
}; |
| 35423 |
} |
| 35424 |
} else if (text == ']') { |
| 35425 |
initContext(editor); |
| 35426 |
var cursor = editor.getCursorPosition(); |
| 35427 |
var line = session.doc.getLine(cursor.row); |
| 35428 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
| 35429 |
if (rightChar == ']') { |
| 35430 |
var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row}); |
| 35431 |
if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { |
| 35432 |
CstyleBehaviour.popAutoInsertedClosing(); |
| 35433 |
return { |
| 35434 |
text: '', |
| 35435 |
selection: [1, 1] |
| 35436 |
}; |
| 35437 |
} |
| 35438 |
} |
| 35439 |
} |
| 35440 |
}); |
| 35441 |
|
| 35442 |
this.add("brackets", "deletion", function(state, action, editor, session, range) { |
| 35443 |
var selected = session.doc.getTextRange(range); |
| 35444 |
if (!range.isMultiLine() && selected == '[') { |
| 35445 |
initContext(editor); |
| 35446 |
var line = session.doc.getLine(range.start.row); |
| 35447 |
var rightChar = line.substring(range.start.column + 1, range.start.column + 2); |
| 35448 |
if (rightChar == ']') { |
| 35449 |
range.end.column++; |
| 35450 |
return range; |
| 35451 |
} |
| 35452 |
} |
| 35453 |
}); |
| 35454 |
|
| 35455 |
this.add("string_dquotes", "insertion", function(state, action, editor, session, text) { |
| 35456 |
if (text == '"' || text == "'") { |
| 35457 |
initContext(editor); |
| 35458 |
var quote = text; |
| 35459 |
var selection = editor.getSelectionRange(); |
| 35460 |
var selected = session.doc.getTextRange(selection); |
| 35461 |
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) { |
| 35462 |
return getWrapped(selection, selected, quote, quote); |
| 35463 |
} else if (!selected) { |
| 35464 |
var cursor = editor.getCursorPosition(); |
| 35465 |
var line = session.doc.getLine(cursor.row); |
| 35466 |
var leftChar = line.substring(cursor.column-1, cursor.column); |
| 35467 |
var rightChar = line.substring(cursor.column, cursor.column + 1); |
| 35468 |
|
| 35469 |
var token = session.getTokenAt(cursor.row, cursor.column); |
| 35470 |
var rightToken = session.getTokenAt(cursor.row, cursor.column + 1); |
| 35471 |
if (leftChar == "\\" && token && /escape/.test(token.type)) |
| 35472 |
return null; |
| 35473 |
|
| 35474 |
var stringBefore = token && /string|escape/.test(token.type); |
| 35475 |
var stringAfter = !rightToken || /string|escape/.test(rightToken.type); |
| 35476 |
|
| 35477 |
var pair; |
| 35478 |
if (rightChar == quote) { |
| 35479 |
pair = stringBefore !== stringAfter; |
| 35480 |
} else { |
| 35481 |
if (stringBefore && !stringAfter) |
| 35482 |
return null; // wrap string with different quote |
| 35483 |
if (stringBefore && stringAfter) |
| 35484 |
return null; // do not pair quotes inside strings |
| 35485 |
var wordRe = session.$mode.tokenRe; |
| 35486 |
wordRe.lastIndex = 0; |
| 35487 |
var isWordBefore = wordRe.test(leftChar); |
| 35488 |
wordRe.lastIndex = 0; |
| 35489 |
var isWordAfter = wordRe.test(leftChar); |
| 35490 |
if (isWordBefore || isWordAfter) |
| 35491 |
return null; // before or after alphanumeric |
| 35492 |
if (rightChar && !/[\s;,.})\]\\]/.test(rightChar)) |
| 35493 |
return null; // there is rightChar and it isn't closing |
| 35494 |
pair = true; |
| 35495 |
} |
| 35496 |
return { |
| 35497 |
text: pair ? quote + quote : "", |
| 35498 |
selection: [1,1] |
| 35499 |
}; |
| 35500 |
} |
| 35501 |
} |
| 35502 |
}); |
| 35503 |
|
| 35504 |
this.add("string_dquotes", "deletion", function(state, action, editor, session, range) { |
| 35505 |
var selected = session.doc.getTextRange(range); |
| 35506 |
if (!range.isMultiLine() && (selected == '"' || selected == "'")) { |
| 35507 |
initContext(editor); |
| 35508 |
var line = session.doc.getLine(range.start.row); |
| 35509 |
var rightChar = line.substring(range.start.column + 1, range.start.column + 2); |
| 35510 |
if (rightChar == selected) { |
| 35511 |
range.end.column++; |
| 35512 |
return range; |
| 35513 |
} |
| 35514 |
} |
| 35515 |
}); |
| 35516 |
|
| 35517 |
}; |
| 35518 |
|
| 35519 |
|
| 35520 |
CstyleBehaviour.isSaneInsertion = function(editor, session) { |
| 35521 |
var cursor = editor.getCursorPosition(); |
| 35522 |
var iterator = new TokenIterator(session, cursor.row, cursor.column); |
| 35523 |
if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) { |
| 35524 |
var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1); |
| 35525 |
if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) |
| 35526 |
return false; |
| 35527 |
} |
| 35528 |
iterator.stepForward(); |
| 35529 |
return iterator.getCurrentTokenRow() !== cursor.row || |
| 35530 |
this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS); |
| 35531 |
}; |
| 35532 |
|
| 35533 |
CstyleBehaviour.$matchTokenType = function(token, types) { |
| 35534 |
return types.indexOf(token.type || token) > -1; |
| 35535 |
}; |
| 35536 |
|
| 35537 |
CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) { |
| 35538 |
var cursor = editor.getCursorPosition(); |
| 35539 |
var line = session.doc.getLine(cursor.row); |
| 35540 |
if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0])) |
| 35541 |
context.autoInsertedBrackets = 0; |
| 35542 |
context.autoInsertedRow = cursor.row; |
| 35543 |
context.autoInsertedLineEnd = bracket + line.substr(cursor.column); |
| 35544 |
context.autoInsertedBrackets++; |
| 35545 |
}; |
| 35546 |
|
| 35547 |
CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) { |
| 35548 |
var cursor = editor.getCursorPosition(); |
| 35549 |
var line = session.doc.getLine(cursor.row); |
| 35550 |
if (!this.isMaybeInsertedClosing(cursor, line)) |
| 35551 |
context.maybeInsertedBrackets = 0; |
| 35552 |
context.maybeInsertedRow = cursor.row; |
| 35553 |
context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket; |
| 35554 |
context.maybeInsertedLineEnd = line.substr(cursor.column); |
| 35555 |
context.maybeInsertedBrackets++; |
| 35556 |
}; |
| 35557 |
|
| 35558 |
CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) { |
| 35559 |
return context.autoInsertedBrackets > 0 && |
| 35560 |
cursor.row === context.autoInsertedRow && |
| 35561 |
bracket === context.autoInsertedLineEnd[0] && |
| 35562 |
line.substr(cursor.column) === context.autoInsertedLineEnd; |
| 35563 |
}; |
| 35564 |
|
| 35565 |
CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) { |
| 35566 |
return context.maybeInsertedBrackets > 0 && |
| 35567 |
cursor.row === context.maybeInsertedRow && |
| 35568 |
line.substr(cursor.column) === context.maybeInsertedLineEnd && |
| 35569 |
line.substr(0, cursor.column) == context.maybeInsertedLineStart; |
| 35570 |
}; |
| 35571 |
|
| 35572 |
CstyleBehaviour.popAutoInsertedClosing = function() { |
| 35573 |
context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1); |
| 35574 |
context.autoInsertedBrackets--; |
| 35575 |
}; |
| 35576 |
|
| 35577 |
CstyleBehaviour.clearMaybeInsertedClosing = function() { |
| 35578 |
if (context) { |
| 35579 |
context.maybeInsertedBrackets = 0; |
| 35580 |
context.maybeInsertedRow = -1; |
| 35581 |
} |
| 35582 |
}; |
| 35583 |
|
| 35584 |
|
| 35585 |
|
| 35586 |
oop.inherits(CstyleBehaviour, Behaviour); |
| 35587 |
|
| 35588 |
exports.CstyleBehaviour = CstyleBehaviour; |
| 35589 |
}); |
| 35590 |
|
| 35591 |
ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(acequire, exports, module) { |
| 35592 |
"use strict"; |
| 35593 |
|
| 35594 |
var oop = acequire("../../lib/oop"); |
| 35595 |
var Range = acequire("../../range").Range; |
| 35596 |
var BaseFoldMode = acequire("./fold_mode").FoldMode; |
| 35597 |
|
| 35598 |
var FoldMode = exports.FoldMode = function(commentRegex) { |
| 35599 |
if (commentRegex) { |
| 35600 |
this.foldingStartMarker = new RegExp( |
| 35601 |
this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start) |
| 35602 |
); |
| 35603 |
this.foldingStopMarker = new RegExp( |
| 35604 |
this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end) |
| 35605 |
); |
| 35606 |
} |
| 35607 |
}; |
| 35608 |
oop.inherits(FoldMode, BaseFoldMode); |
| 35609 |
|
| 35610 |
(function() { |
| 35611 |
|
| 35612 |
this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/; |
| 35613 |
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/; |
| 35614 |
this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/; |
| 35615 |
this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/; |
| 35616 |
this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/; |
| 35617 |
this._getFoldWidgetBase = this.getFoldWidget; |
| 35618 |
this.getFoldWidget = function(session, foldStyle, row) { |
| 35619 |
var line = session.getLine(row); |
| 35620 |
|
| 35621 |
if (this.singleLineBlockCommentRe.test(line)) { |
| 35622 |
if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line)) |
| 35623 |
return ""; |
| 35624 |
} |
| 35625 |
|
| 35626 |
var fw = this._getFoldWidgetBase(session, foldStyle, row); |
| 35627 |
|
| 35628 |
if (!fw && this.startRegionRe.test(line)) |
| 35629 |
return "start"; // lineCommentRegionStart |
| 35630 |
|
| 35631 |
return fw; |
| 35632 |
}; |
| 35633 |
|
| 35634 |
this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) { |
| 35635 |
var line = session.getLine(row); |
| 35636 |
|
| 35637 |
if (this.startRegionRe.test(line)) |
| 35638 |
return this.getCommentRegionBlock(session, line, row); |
| 35639 |
|
| 35640 |
var match = line.match(this.foldingStartMarker); |
| 35641 |
if (match) { |
| 35642 |
var i = match.index; |
| 35643 |
|
| 35644 |
if (match[1]) |
| 35645 |
return this.openingBracketBlock(session, match[1], row, i); |
| 35646 |
|
| 35647 |
var range = session.getCommentFoldRange(row, i + match[0].length, 1); |
| 35648 |
|
| 35649 |
if (range && !range.isMultiLine()) { |
| 35650 |
if (forceMultiline) { |
| 35651 |
range = this.getSectionRange(session, row); |
| 35652 |
} else if (foldStyle != "all") |
| 35653 |
range = null; |
| 35654 |
} |
| 35655 |
|
| 35656 |
return range; |
| 35657 |
} |
| 35658 |
|
| 35659 |
if (foldStyle === "markbegin") |
| 35660 |
return; |
| 35661 |
|
| 35662 |
var match = line.match(this.foldingStopMarker); |
| 35663 |
if (match) { |
| 35664 |
var i = match.index + match[0].length; |
| 35665 |
|
| 35666 |
if (match[1]) |
| 35667 |
return this.closingBracketBlock(session, match[1], row, i); |
| 35668 |
|
| 35669 |
return session.getCommentFoldRange(row, i, -1); |
| 35670 |
} |
| 35671 |
}; |
| 35672 |
|
| 35673 |
this.getSectionRange = function(session, row) { |
| 35674 |
var line = session.getLine(row); |
| 35675 |
var startIndent = line.search(/\S/); |
| 35676 |
var startRow = row; |
| 35677 |
var startColumn = line.length; |
| 35678 |
row = row + 1; |
| 35679 |
var endRow = row; |
| 35680 |
var maxRow = session.getLength(); |
| 35681 |
while (++row < maxRow) { |
| 35682 |
line = session.getLine(row); |
| 35683 |
var indent = line.search(/\S/); |
| 35684 |
if (indent === -1) |
| 35685 |
continue; |
| 35686 |
if (startIndent > indent) |
| 35687 |
break; |
| 35688 |
var subRange = this.getFoldWidgetRange(session, "all", row); |
| 35689 |
|
| 35690 |
if (subRange) { |
| 35691 |
if (subRange.start.row <= startRow) { |
| 35692 |
break; |
| 35693 |
} else if (subRange.isMultiLine()) { |
| 35694 |
row = subRange.end.row; |
| 35695 |
} else if (startIndent == indent) { |
| 35696 |
break; |
| 35697 |
} |
| 35698 |
} |
| 35699 |
endRow = row; |
| 35700 |
} |
| 35701 |
|
| 35702 |
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length); |
| 35703 |
}; |
| 35704 |
this.getCommentRegionBlock = function(session, line, row) { |
| 35705 |
var startColumn = line.search(/\s*$/); |
| 35706 |
var maxRow = session.getLength(); |
| 35707 |
var startRow = row; |
| 35708 |
|
| 35709 |
var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/; |
| 35710 |
var depth = 1; |
| 35711 |
while (++row < maxRow) { |
| 35712 |
line = session.getLine(row); |
| 35713 |
var m = re.exec(line); |
| 35714 |
if (!m) continue; |
| 35715 |
if (m[1]) depth--; |
| 35716 |
else depth++; |
| 35717 |
|
| 35718 |
if (!depth) break; |
| 35719 |
} |
| 35720 |
|
| 35721 |
var endRow = row; |
| 35722 |
if (endRow > startRow) { |
| 35723 |
return new Range(startRow, startColumn, endRow, line.length); |
| 35724 |
} |
| 35725 |
}; |
| 35726 |
|
| 35727 |
}).call(FoldMode.prototype); |
| 35728 |
|
| 35729 |
}); |
| 35730 |
|
| 35731 |
ace.define("ace/mode/json",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/json_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle","ace/worker/worker_client"], function(acequire, exports, module) { |
| 35732 |
"use strict"; |
| 35733 |
|
| 35734 |
var oop = acequire("../lib/oop"); |
| 35735 |
var TextMode = acequire("./text").Mode; |
| 35736 |
var HighlightRules = acequire("./json_highlight_rules").JsonHighlightRules; |
| 35737 |
var MatchingBraceOutdent = acequire("./matching_brace_outdent").MatchingBraceOutdent; |
| 35738 |
var CstyleBehaviour = acequire("./behaviour/cstyle").CstyleBehaviour; |
| 35739 |
var CStyleFoldMode = acequire("./folding/cstyle").FoldMode; |
| 35740 |
var WorkerClient = acequire("../worker/worker_client").WorkerClient; |
| 35741 |
|
| 35742 |
var Mode = function() { |
| 35743 |
this.HighlightRules = HighlightRules; |
| 35744 |
this.$outdent = new MatchingBraceOutdent(); |
| 35745 |
this.$behaviour = new CstyleBehaviour(); |
| 35746 |
this.foldingRules = new CStyleFoldMode(); |
| 35747 |
}; |
| 35748 |
oop.inherits(Mode, TextMode); |
| 35749 |
|
| 35750 |
(function() { |
| 35751 |
|
| 35752 |
this.getNextLineIndent = function(state, line, tab) { |
| 35753 |
var indent = this.$getIndent(line); |
| 35754 |
|
| 35755 |
if (state == "start") { |
| 35756 |
var match = line.match(/^.*[\{\(\[]\s*$/); |
| 35757 |
if (match) { |
| 35758 |
indent += tab; |
| 35759 |
} |
| 35760 |
} |
| 35761 |
|
| 35762 |
return indent; |
| 35763 |
}; |
| 35764 |
|
| 35765 |
this.checkOutdent = function(state, line, input) { |
| 35766 |
return this.$outdent.checkOutdent(line, input); |
| 35767 |
}; |
| 35768 |
|
| 35769 |
this.autoOutdent = function(state, doc, row) { |
| 35770 |
this.$outdent.autoOutdent(doc, row); |
| 35771 |
}; |
| 35772 |
|
| 35773 |
this.createWorker = function(session) { |
| 35774 |
var worker = new WorkerClient(["ace"], __webpack_require__(68), "JsonWorker"); |
| 35775 |
worker.attachToDocument(session.getDocument()); |
| 35776 |
|
| 35777 |
worker.on("annotate", function(e) { |
| 35778 |
session.setAnnotations(e.data); |
| 35779 |
}); |
| 35780 |
|
| 35781 |
worker.on("terminate", function() { |
| 35782 |
session.clearAnnotations(); |
| 35783 |
}); |
| 35784 |
|
| 35785 |
return worker; |
| 35786 |
}; |
| 35787 |
|
| 35788 |
|
| 35789 |
this.$id = "ace/mode/json"; |
| 35790 |
}).call(Mode.prototype); |
| 35791 |
|
| 35792 |
exports.Mode = Mode; |
| 35793 |
}); |
| 35794 |
|
| 35795 |
|
| 35796 |
/***/ }, |
| 35797 |
/* 68 */ |
| 35798 |
/***/ function(module, exports) { |
| 35799 |
|
| 35800 |
module.exports.id = 'ace/mode/json_worker'; |
| 35801 |
module.exports.src = "\"no use strict\";(function(window){function resolveModuleId(id,paths){for(var testPath=id,tail=\"\";testPath;){var alias=paths[testPath];if(\"string\"==typeof alias)return alias+tail;if(alias)return alias.location.replace(/\\/*$/,\"/\")+(tail||alias.main||alias.name);if(alias===!1)return\"\";var i=testPath.lastIndexOf(\"/\");if(-1===i)break;tail=testPath.substr(i)+tail,testPath=testPath.slice(0,i)}return id}if(!(void 0!==window.window&&window.document||window.acequire&&window.define)){window.console||(window.console=function(){var msgs=Array.prototype.slice.call(arguments,0);postMessage({type:\"log\",data:msgs})},window.console.error=window.console.warn=window.console.log=window.console.trace=window.console),window.window=window,window.ace=window,window.onerror=function(message,file,line,col,err){postMessage({type:\"error\",data:{message:message,data:err.data,file:file,line:line,col:col,stack:err.stack}})},window.normalizeModule=function(parentId,moduleName){if(-1!==moduleName.indexOf(\"!\")){var chunks=moduleName.split(\"!\");return window.normalizeModule(parentId,chunks[0])+\"!\"+window.normalizeModule(parentId,chunks[1])}if(\".\"==moduleName.charAt(0)){var base=parentId.split(\"/\").slice(0,-1).join(\"/\");for(moduleName=(base?base+\"/\":\"\")+moduleName;-1!==moduleName.indexOf(\".\")&&previous!=moduleName;){var previous=moduleName;moduleName=moduleName.replace(/^\\.\\//,\"\").replace(/\\/\\.\\//,\"/\").replace(/[^\\/]+\\/\\.\\.\\//,\"\")}}return moduleName},window.acequire=function acequire(parentId,id){if(id||(id=parentId,parentId=null),!id.charAt)throw Error(\"worker.js acequire() accepts only (parentId, id) as arguments\");id=window.normalizeModule(parentId,id);var module=window.acequire.modules[id];if(module)return module.initialized||(module.initialized=!0,module.exports=module.factory().exports),module.exports;if(!window.acequire.tlns)return console.log(\"unable to load \"+id);var path=resolveModuleId(id,window.acequire.tlns);return\".js\"!=path.slice(-3)&&(path+=\".js\"),window.acequire.id=id,window.acequire.modules[id]={},importScripts(path),window.acequire(parentId,id)},window.acequire.modules={},window.acequire.tlns={},window.define=function(id,deps,factory){if(2==arguments.length?(factory=deps,\"string\"!=typeof id&&(deps=id,id=window.acequire.id)):1==arguments.length&&(factory=id,deps=[],id=window.acequire.id),\"function\"!=typeof factory)return window.acequire.modules[id]={exports:factory,initialized:!0},void 0;deps.length||(deps=[\"require\",\"exports\",\"module\"]);var req=function(childId){return window.acequire(id,childId)};window.acequire.modules[id]={exports:{},factory:function(){var module=this,returnExports=factory.apply(this,deps.map(function(dep){switch(dep){case\"require\":return req;case\"exports\":return module.exports;case\"module\":return module;default:return req(dep)}}));return returnExports&&(module.exports=returnExports),module}}},window.define.amd={},acequire.tlns={},window.initBaseUrls=function(topLevelNamespaces){for(var i in topLevelNamespaces)acequire.tlns[i]=topLevelNamespaces[i]},window.initSender=function(){var EventEmitter=window.acequire(\"ace/lib/event_emitter\").EventEmitter,oop=window.acequire(\"ace/lib/oop\"),Sender=function(){};return function(){oop.implement(this,EventEmitter),this.callback=function(data,callbackId){postMessage({type:\"call\",id:callbackId,data:data})},this.emit=function(name,data){postMessage({type:\"event\",name:name,data:data})}}.call(Sender.prototype),new Sender};var main=window.main=null,sender=window.sender=null;window.onmessage=function(e){var msg=e.data;if(msg.event&&sender)sender._signal(msg.event,msg.data);else if(msg.command)if(main[msg.command])main[msg.command].apply(main,msg.args);else{if(!window[msg.command])throw Error(\"Unknown command:\"+msg.command);window[msg.command].apply(window,msg.args)}else if(msg.init){window.initBaseUrls(msg.tlns),acequire(\"ace/lib/es5-shim\"),sender=window.sender=window.initSender();var clazz=acequire(msg.module)[msg.classname];main=window.main=new clazz(sender)}}}})(this),ace.define(\"ace/lib/oop\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";exports.inherits=function(ctor,superCtor){ctor.super_=superCtor,ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:!1,writable:!0,configurable:!0}})},exports.mixin=function(obj,mixin){for(var key in mixin)obj[key]=mixin[key];return obj},exports.implement=function(proto,mixin){exports.mixin(proto,mixin)}}),ace.define(\"ace/range\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";var comparePoints=function(p1,p2){return p1.row-p2.row||p1.column-p2.column},Range=function(startRow,startColumn,endRow,endColumn){this.start={row:startRow,column:startColumn},this.end={row:endRow,column:endColumn}};(function(){this.isEqual=function(range){return this.start.row===range.start.row&&this.end.row===range.end.row&&this.start.column===range.start.column&&this.end.column===range.end.column},this.toString=function(){return\"Range: [\"+this.start.row+\"/\"+this.start.column+\"] -> [\"+this.end.row+\"/\"+this.end.column+\"]\"},this.contains=function(row,column){return 0==this.compare(row,column)},this.compareRange=function(range){var cmp,end=range.end,start=range.start;return cmp=this.compare(end.row,end.column),1==cmp?(cmp=this.compare(start.row,start.column),1==cmp?2:0==cmp?1:0):-1==cmp?-2:(cmp=this.compare(start.row,start.column),-1==cmp?-1:1==cmp?42:0)},this.comparePoint=function(p){return this.compare(p.row,p.column)},this.containsRange=function(range){return 0==this.comparePoint(range.start)&&0==this.comparePoint(range.end)},this.intersects=function(range){var cmp=this.compareRange(range);return-1==cmp||0==cmp||1==cmp},this.isEnd=function(row,column){return this.end.row==row&&this.end.column==column},this.isStart=function(row,column){return this.start.row==row&&this.start.column==column},this.setStart=function(row,column){\"object\"==typeof row?(this.start.column=row.column,this.start.row=row.row):(this.start.row=row,this.start.column=column)},this.setEnd=function(row,column){\"object\"==typeof row?(this.end.column=row.column,this.end.row=row.row):(this.end.row=row,this.end.column=column)},this.inside=function(row,column){return 0==this.compare(row,column)?this.isEnd(row,column)||this.isStart(row,column)?!1:!0:!1},this.insideStart=function(row,column){return 0==this.compare(row,column)?this.isEnd(row,column)?!1:!0:!1},this.insideEnd=function(row,column){return 0==this.compare(row,column)?this.isStart(row,column)?!1:!0:!1},this.compare=function(row,column){return this.isMultiLine()||row!==this.start.row?this.start.row>row?-1:row>this.end.row?1:this.start.row===row?column>=this.start.column?0:-1:this.end.row===row?this.end.column>=column?0:1:0:this.start.column>column?-1:column>this.end.column?1:0},this.compareStart=function(row,column){return this.start.row==row&&this.start.column==column?-1:this.compare(row,column)},this.compareEnd=function(row,column){return this.end.row==row&&this.end.column==column?1:this.compare(row,column)},this.compareInside=function(row,column){return this.end.row==row&&this.end.column==column?1:this.start.row==row&&this.start.column==column?-1:this.compare(row,column)},this.clipRows=function(firstRow,lastRow){if(this.end.row>lastRow)var end={row:lastRow+1,column:0};else if(firstRow>this.end.row)var end={row:firstRow,column:0};if(this.start.row>lastRow)var start={row:lastRow+1,column:0};else if(firstRow>this.start.row)var start={row:firstRow,column:0};return Range.fromPoints(start||this.start,end||this.end)},this.extend=function(row,column){var cmp=this.compare(row,column);if(0==cmp)return this;if(-1==cmp)var start={row:row,column:column};else var end={row:row,column:column};return Range.fromPoints(start||this.start,end||this.end)},this.isEmpty=function(){return this.start.row===this.end.row&&this.start.column===this.end.column},this.isMultiLine=function(){return this.start.row!==this.end.row},this.clone=function(){return Range.fromPoints(this.start,this.end)},this.collapseRows=function(){return 0==this.end.column?new Range(this.start.row,0,Math.max(this.start.row,this.end.row-1),0):new Range(this.start.row,0,this.end.row,0)},this.toScreenRange=function(session){var screenPosStart=session.documentToScreenPosition(this.start),screenPosEnd=session.documentToScreenPosition(this.end);return new Range(screenPosStart.row,screenPosStart.column,screenPosEnd.row,screenPosEnd.column)},this.moveBy=function(row,column){this.start.row+=row,this.start.column+=column,this.end.row+=row,this.end.column+=column}}).call(Range.prototype),Range.fromPoints=function(start,end){return new Range(start.row,start.column,end.row,end.column)},Range.comparePoints=comparePoints,Range.comparePoints=function(p1,p2){return p1.row-p2.row||p1.column-p2.column},exports.Range=Range}),ace.define(\"ace/apply_delta\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";exports.applyDelta=function(docLines,delta){var row=delta.start.row,startColumn=delta.start.column,line=docLines[row]||\"\";switch(delta.action){case\"insert\":var lines=delta.lines;if(1===lines.length)docLines[row]=line.substring(0,startColumn)+delta.lines[0]+line.substring(startColumn);else{var args=[row,1].concat(delta.lines);docLines.splice.apply(docLines,args),docLines[row]=line.substring(0,startColumn)+docLines[row],docLines[row+delta.lines.length-1]+=line.substring(startColumn)}break;case\"remove\":var endColumn=delta.end.column,endRow=delta.end.row;row===endRow?docLines[row]=line.substring(0,startColumn)+line.substring(endColumn):docLines.splice(row,endRow-row+1,line.substring(0,startColumn)+docLines[endRow].substring(endColumn))}}}),ace.define(\"ace/lib/event_emitter\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";var EventEmitter={},stopPropagation=function(){this.propagationStopped=!0},preventDefault=function(){this.defaultPrevented=!0};EventEmitter._emit=EventEmitter._dispatchEvent=function(eventName,e){this._eventRegistry||(this._eventRegistry={}),this._defaultHandlers||(this._defaultHandlers={});var listeners=this._eventRegistry[eventName]||[],defaultHandler=this._defaultHandlers[eventName];if(listeners.length||defaultHandler){\"object\"==typeof e&&e||(e={}),e.type||(e.type=eventName),e.stopPropagation||(e.stopPropagation=stopPropagation),e.preventDefault||(e.preventDefault=preventDefault),listeners=listeners.slice();for(var i=0;listeners.length>i&&(listeners[i](e,this),!e.propagationStopped);i++);return defaultHandler&&!e.defaultPrevented?defaultHandler(e,this):void 0}},EventEmitter._signal=function(eventName,e){var listeners=(this._eventRegistry||{})[eventName];if(listeners){listeners=listeners.slice();for(var i=0;listeners.length>i;i++)listeners[i](e,this)}},EventEmitter.once=function(eventName,callback){var _self=this;callback&&this.addEventListener(eventName,function newCallback(){_self.removeEventListener(eventName,newCallback),callback.apply(null,arguments)})},EventEmitter.setDefaultHandler=function(eventName,callback){var handlers=this._defaultHandlers;if(handlers||(handlers=this._defaultHandlers={_disabled_:{}}),handlers[eventName]){var old=handlers[eventName],disabled=handlers._disabled_[eventName];disabled||(handlers._disabled_[eventName]=disabled=[]),disabled.push(old);var i=disabled.indexOf(callback);-1!=i&&disabled.splice(i,1)}handlers[eventName]=callback},EventEmitter.removeDefaultHandler=function(eventName,callback){var handlers=this._defaultHandlers;if(handlers){var disabled=handlers._disabled_[eventName];if(handlers[eventName]==callback)handlers[eventName],disabled&&this.setDefaultHandler(eventName,disabled.pop());else if(disabled){var i=disabled.indexOf(callback);-1!=i&&disabled.splice(i,1)}}},EventEmitter.on=EventEmitter.addEventListener=function(eventName,callback,capturing){this._eventRegistry=this._eventRegistry||{};var listeners=this._eventRegistry[eventName];return listeners||(listeners=this._eventRegistry[eventName]=[]),-1==listeners.indexOf(callback)&&listeners[capturing?\"unshift\":\"push\"](callback),callback},EventEmitter.off=EventEmitter.removeListener=EventEmitter.removeEventListener=function(eventName,callback){this._eventRegistry=this._eventRegistry||{};var listeners=this._eventRegistry[eventName];if(listeners){var index=listeners.indexOf(callback);-1!==index&&listeners.splice(index,1)}},EventEmitter.removeAllListeners=function(eventName){this._eventRegistry&&(this._eventRegistry[eventName]=[])},exports.EventEmitter=EventEmitter}),ace.define(\"ace/anchor\",[\"require\",\"exports\",\"module\",\"ace/lib/oop\",\"ace/lib/event_emitter\"],function(acequire,exports){\"use strict\";var oop=acequire(\"./lib/oop\"),EventEmitter=acequire(\"./lib/event_emitter\").EventEmitter,Anchor=exports.Anchor=function(doc,row,column){this.$onChange=this.onChange.bind(this),this.attach(doc),column===void 0?this.setPosition(row.row,row.column):this.setPosition(row,column)};(function(){function $pointsInOrder(point1,point2,equalPointsInOrder){var bColIsAfter=equalPointsInOrder?point1.column<=point2.column:point1.column<point2.column;return point1.row<point2.row||point1.row==point2.row&&bColIsAfter}function $getTransformedPoint(delta,point,moveIfEqual){var deltaIsInsert=\"insert\"==delta.action,deltaRowShift=(deltaIsInsert?1:-1)*(delta.end.row-delta.start.row),deltaColShift=(deltaIsInsert?1:-1)*(delta.end.column-delta.start.column),deltaStart=delta.start,deltaEnd=deltaIsInsert?deltaStart:delta.end;return $pointsInOrder(point,deltaStart,moveIfEqual)?{row:point.row,column:point.column}:$pointsInOrder(deltaEnd,point,!moveIfEqual)?{row:point.row+deltaRowShift,column:point.column+(point.row==deltaEnd.row?deltaColShift:0)}:{row:deltaStart.row,column:deltaStart.column}}oop.implement(this,EventEmitter),this.getPosition=function(){return this.$clipPositionToDocument(this.row,this.column)},this.getDocument=function(){return this.document},this.$insertRight=!1,this.onChange=function(delta){if(!(delta.start.row==delta.end.row&&delta.start.row!=this.row||delta.start.row>this.row)){var point=$getTransformedPoint(delta,{row:this.row,column:this.column},this.$insertRight);this.setPosition(point.row,point.column,!0)}},this.setPosition=function(row,column,noClip){var pos;if(pos=noClip?{row:row,column:column}:this.$clipPositionToDocument(row,column),this.row!=pos.row||this.column!=pos.column){var old={row:this.row,column:this.column};this.row=pos.row,this.column=pos.column,this._signal(\"change\",{old:old,value:pos})}},this.detach=function(){this.document.removeEventListener(\"change\",this.$onChange)},this.attach=function(doc){this.document=doc||this.document,this.document.on(\"change\",this.$onChange)},this.$clipPositionToDocument=function(row,column){var pos={};return row>=this.document.getLength()?(pos.row=Math.max(0,this.document.getLength()-1),pos.column=this.document.getLine(pos.row).length):0>row?(pos.row=0,pos.column=0):(pos.row=row,pos.column=Math.min(this.document.getLine(pos.row).length,Math.max(0,column))),0>column&&(pos.column=0),pos}}).call(Anchor.prototype)}),ace.define(\"ace/document\",[\"require\",\"exports\",\"module\",\"ace/lib/oop\",\"ace/apply_delta\",\"ace/lib/event_emitter\",\"ace/range\",\"ace/anchor\"],function(acequire,exports){\"use strict\";var oop=acequire(\"./lib/oop\"),applyDelta=acequire(\"./apply_delta\").applyDelta,EventEmitter=acequire(\"./lib/event_emitter\").EventEmitter,Range=acequire(\"./range\").Range,Anchor=acequire(\"./anchor\").Anchor,Document=function(textOrLines){this.$lines=[\"\"],0===textOrLines.length?this.$lines=[\"\"]:Array.isArray(textOrLines)?this.insertMergedLines({row:0,column:0},textOrLines):this.insert({row:0,column:0},textOrLines)};(function(){oop.implement(this,EventEmitter),this.setValue=function(text){var len=this.getLength()-1;this.remove(new Range(0,0,len,this.getLine(len).length)),this.insert({row:0,column:0},text)},this.getValue=function(){return this.getAllLines().join(this.getNewLineCharacter())},this.createAnchor=function(row,column){return new Anchor(this,row,column)},this.$split=0===\"aaa\".split(/a/).length?function(text){return text.replace(/\\r\\n|\\r/g,\"\\n\").split(\"\\n\")}:function(text){return text.split(/\\r\\n|\\r|\\n/)},this.$detectNewLine=function(text){var match=text.match(/^.*?(\\r\\n|\\r|\\n)/m);this.$autoNewLine=match?match[1]:\"\\n\",this._signal(\"changeNewLineMode\")},this.getNewLineCharacter=function(){switch(this.$newLineMode){case\"windows\":return\"\\r\\n\";case\"unix\":return\"\\n\";default:return this.$autoNewLine||\"\\n\"}},this.$autoNewLine=\"\",this.$newLineMode=\"auto\",this.setNewLineMode=function(newLineMode){this.$newLineMode!==newLineMode&&(this.$newLineMode=newLineMode,this._signal(\"changeNewLineMode\"))},this.getNewLineMode=function(){return this.$newLineMode},this.isNewLine=function(text){return\"\\r\\n\"==text||\"\\r\"==text||\"\\n\"==text},this.getLine=function(row){return this.$lines[row]||\"\"},this.getLines=function(firstRow,lastRow){return this.$lines.slice(firstRow,lastRow+1)},this.getAllLines=function(){return this.getLines(0,this.getLength())},this.getLength=function(){return this.$lines.length},this.getTextRange=function(range){return this.getLinesForRange(range).join(this.getNewLineCharacter())},this.getLinesForRange=function(range){var lines;if(range.start.row===range.end.row)lines=[this.getLine(range.start.row).substring(range.start.column,range.end.column)];else{lines=this.getLines(range.start.row,range.end.row),lines[0]=(lines[0]||\"\").substring(range.start.column);var l=lines.length-1;range.end.row-range.start.row==l&&(lines[l]=lines[l].substring(0,range.end.column))}return lines},this.insertLines=function(row,lines){return console.warn(\"Use of document.insertLines is deprecated. Use the insertFullLines method instead.\"),this.insertFullLines(row,lines)},this.removeLines=function(firstRow,lastRow){return console.warn(\"Use of document.removeLines is deprecated. Use the removeFullLines method instead.\"),this.removeFullLines(firstRow,lastRow)},this.insertNewLine=function(position){return console.warn(\"Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead.\"),this.insertMergedLines(position,[\"\",\"\"])},this.insert=function(position,text){return 1>=this.getLength()&&this.$detectNewLine(text),this.insertMergedLines(position,this.$split(text))},this.insertInLine=function(position,text){var start=this.clippedPos(position.row,position.column),end=this.pos(position.row,position.column+text.length);return this.applyDelta({start:start,end:end,action:\"insert\",lines:[text]},!0),this.clonePos(end)},this.clippedPos=function(row,column){var length=this.getLength();void 0===row?row=length:0>row?row=0:row>=length&&(row=length-1,column=void 0);var line=this.getLine(row);return void 0==column&&(column=line.length),column=Math.min(Math.max(column,0),line.length),{row:row,column:column}},this.clonePos=function(pos){return{row:pos.row,column:pos.column}},this.pos=function(row,column){return{row:row,column:column}},this.$clipPosition=function(position){var length=this.getLength();return position.row>=length?(position.row=Math.max(0,length-1),position.column=this.getLine(length-1).length):(position.row=Math.max(0,position.row),position.column=Math.min(Math.max(position.column,0),this.getLine(position.row).length)),position},this.insertFullLines=function(row,lines){row=Math.min(Math.max(row,0),this.getLength());var column=0;this.getLength()>row?(lines=lines.concat([\"\"]),column=0):(lines=[\"\"].concat(lines),row--,column=this.$lines[row].length),this.insertMergedLines({row:row,column:column},lines)},this.insertMergedLines=function(position,lines){var start=this.clippedPos(position.row,position.column),end={row:start.row+lines.length-1,column:(1==lines.length?start.column:0)+lines[lines.length-1].length};return this.applyDelta({start:start,end:end,action:\"insert\",lines:lines}),this.clonePos(end)},this.remove=function(range){var start=this.clippedPos(range.start.row,range.start.column),end=this.clippedPos(range.end.row,range.end.column);return this.applyDelta({start:start,end:end,action:\"remove\",lines:this.getLinesForRange({start:start,end:end})}),this.clonePos(start)},this.removeInLine=function(row,startColumn,endColumn){var start=this.clippedPos(row,startColumn),end=this.clippedPos(row,endColumn);return this.applyDelta({start:start,end:end,action:\"remove\",lines:this.getLinesForRange({start:start,end:end})},!0),this.clonePos(start)},this.removeFullLines=function(firstRow,lastRow){firstRow=Math.min(Math.max(0,firstRow),this.getLength()-1),lastRow=Math.min(Math.max(0,lastRow),this.getLength()-1);var deleteFirstNewLine=lastRow==this.getLength()-1&&firstRow>0,deleteLastNewLine=this.getLength()-1>lastRow,startRow=deleteFirstNewLine?firstRow-1:firstRow,startCol=deleteFirstNewLine?this.getLine(startRow).length:0,endRow=deleteLastNewLine?lastRow+1:lastRow,endCol=deleteLastNewLine?0:this.getLine(endRow).length,range=new Range(startRow,startCol,endRow,endCol),deletedLines=this.$lines.slice(firstRow,lastRow+1);return this.applyDelta({start:range.start,end:range.end,action:\"remove\",lines:this.getLinesForRange(range)}),deletedLines},this.removeNewLine=function(row){this.getLength()-1>row&&row>=0&&this.applyDelta({start:this.pos(row,this.getLine(row).length),end:this.pos(row+1,0),action:\"remove\",lines:[\"\",\"\"]})},this.replace=function(range,text){if(range instanceof Range||(range=Range.fromPoints(range.start,range.end)),0===text.length&&range.isEmpty())return range.start;if(text==this.getTextRange(range))return range.end;this.remove(range);var end;return end=text?this.insert(range.start,text):range.start},this.applyDeltas=function(deltas){for(var i=0;deltas.length>i;i++)this.applyDelta(deltas[i])},this.revertDeltas=function(deltas){for(var i=deltas.length-1;i>=0;i--)this.revertDelta(deltas[i])},this.applyDelta=function(delta,doNotValidate){var isInsert=\"insert\"==delta.action;(isInsert?1>=delta.lines.length&&!delta.lines[0]:!Range.comparePoints(delta.start,delta.end))||(isInsert&&delta.lines.length>2e4&&this.$splitAndapplyLargeDelta(delta,2e4),applyDelta(this.$lines,delta,doNotValidate),this._signal(\"change\",delta))},this.$splitAndapplyLargeDelta=function(delta,MAX){for(var lines=delta.lines,l=lines.length,row=delta.start.row,column=delta.start.column,from=0,to=0;;){from=to,to+=MAX-1;var chunk=lines.slice(from,to);if(to>l){delta.lines=chunk,delta.start.row=row+from,delta.start.column=column;break}chunk.push(\"\"),this.applyDelta({start:this.pos(row+from,column),end:this.pos(row+to,column=0),action:delta.action,lines:chunk},!0)}},this.revertDelta=function(delta){this.applyDelta({start:this.clonePos(delta.start),end:this.clonePos(delta.end),action:\"insert\"==delta.action?\"remove\":\"insert\",lines:delta.lines.slice()})},this.indexToPosition=function(index,startRow){for(var lines=this.$lines||this.getAllLines(),newlineLength=this.getNewLineCharacter().length,i=startRow||0,l=lines.length;l>i;i++)if(index-=lines[i].length+newlineLength,0>index)return{row:i,column:index+lines[i].length+newlineLength};return{row:l-1,column:lines[l-1].length}},this.positionToIndex=function(pos,startRow){for(var lines=this.$lines||this.getAllLines(),newlineLength=this.getNewLineCharacter().length,index=0,row=Math.min(pos.row,lines.length),i=startRow||0;row>i;++i)index+=lines[i].length+newlineLength;return index+pos.column}}).call(Document.prototype),exports.Document=Document}),ace.define(\"ace/lib/lang\",[\"require\",\"exports\",\"module\"],function(acequire,exports){\"use strict\";exports.last=function(a){return a[a.length-1]},exports.stringReverse=function(string){return string.split(\"\").reverse().join(\"\")},exports.stringRepeat=function(string,count){for(var result=\"\";count>0;)1&count&&(result+=string),(count>>=1)&&(string+=string);return result};var trimBeginRegexp=/^\\s\\s*/,trimEndRegexp=/\\s\\s*$/;exports.stringTrimLeft=function(string){return string.replace(trimBeginRegexp,\"\")},exports.stringTrimRight=function(string){return string.replace(trimEndRegexp,\"\")},exports.copyObject=function(obj){var copy={};for(var key in obj)copy[key]=obj[key];return copy},exports.copyArray=function(array){for(var copy=[],i=0,l=array.length;l>i;i++)copy[i]=array[i]&&\"object\"==typeof array[i]?this.copyObject(array[i]):array[i];return copy},exports.deepCopy=function deepCopy(obj){if(\"object\"!=typeof obj||!obj)return obj;var copy;if(Array.isArray(obj)){copy=[];for(var key=0;obj.length>key;key++)copy[key]=deepCopy(obj[key]);return copy}var cons=obj.constructor;if(cons===RegExp)return obj;copy=cons();for(var key in obj)copy[key]=deepCopy(obj[key]);return copy},exports.arrayToMap=function(arr){for(var map={},i=0;arr.length>i;i++)map[arr[i]]=1;return map},exports.createMap=function(props){var map=Object.create(null);for(var i in props)map[i]=props[i];return map},exports.arrayRemove=function(array,value){for(var i=0;array.length>=i;i++)value===array[i]&&array.splice(i,1)},exports.escapeRegExp=function(str){return str.replace(/([.*+?^${}()|[\\]\\/\\\\])/g,\"\\\\$1\")},exports.escapeHTML=function(str){return str.replace(/&/g,\"&\").replace(/\"/g,\""\").replace(/'/g,\"'\").replace(/</g,\"<\")},exports.getMatchOffsets=function(string,regExp){var matches=[];return string.replace(regExp,function(str){matches.push({offset:arguments[arguments.length-2],length:str.length})}),matches},exports.deferredCall=function(fcn){var timer=null,callback=function(){timer=null,fcn()},deferred=function(timeout){return deferred.cancel(),timer=setTimeout(callback,timeout||0),deferred};return deferred.schedule=deferred,deferred.call=function(){return this.cancel(),fcn(),deferred},deferred.cancel=function(){return clearTimeout(timer),timer=null,deferred},deferred.isPending=function(){return timer},deferred},exports.delayedCall=function(fcn,defaultTimeout){var timer=null,callback=function(){timer=null,fcn()},_self=function(timeout){null==timer&&(timer=setTimeout(callback,timeout||defaultTimeout))};return _self.delay=function(timeout){timer&&clearTimeout(timer),timer=setTimeout(callback,timeout||defaultTimeout)},_self.schedule=_self,_self.call=function(){this.cancel(),fcn()},_self.cancel=function(){timer&&clearTimeout(timer),timer=null},_self.isPending=function(){return timer},_self}}),ace.define(\"ace/worker/mirror\",[\"require\",\"exports\",\"module\",\"ace/range\",\"ace/document\",\"ace/lib/lang\"],function(acequire,exports){\"use strict\";acequire(\"../range\").Range;var Document=acequire(\"../document\").Document,lang=acequire(\"../lib/lang\"),Mirror=exports.Mirror=function(sender){this.sender=sender;var doc=this.doc=new Document(\"\"),deferredUpdate=this.deferredUpdate=lang.delayedCall(this.onUpdate.bind(this)),_self=this;sender.on(\"change\",function(e){var data=e.data;if(data[0].start)doc.applyDeltas(data);else for(var i=0;data.length>i;i+=2){if(Array.isArray(data[i+1]))var d={action:\"insert\",start:data[i],lines:data[i+1]};else var d={action:\"remove\",start:data[i],end:data[i+1]};doc.applyDelta(d,!0)}return _self.$timeout?deferredUpdate.schedule(_self.$timeout):(_self.onUpdate(),void 0)})};(function(){this.$timeout=500,this.setTimeout=function(timeout){this.$timeout=timeout},this.setValue=function(value){this.doc.setValue(value),this.deferredUpdate.schedule(this.$timeout)},this.getValue=function(callbackId){this.sender.callback(this.doc.getValue(),callbackId)},this.onUpdate=function(){},this.isPending=function(){return this.deferredUpdate.isPending()}}).call(Mirror.prototype)}),ace.define(\"ace/mode/json/json_parse\",[\"require\",\"exports\",\"module\"],function(){\"use strict\";var at,ch,text,value,escapee={'\"':'\"',\"\\\\\":\"\\\\\",\"/\":\"/\",b:\"\\b\",f:\"\\f\",n:\"\\n\",r:\"\\r\",t:\"\t\"},error=function(m){throw{name:\"SyntaxError\",message:m,at:at,text:text}},next=function(c){return c&&c!==ch&&error(\"Expected '\"+c+\"' instead of '\"+ch+\"'\"),ch=text.charAt(at),at+=1,ch},number=function(){var number,string=\"\";for(\"-\"===ch&&(string=\"-\",next(\"-\"));ch>=\"0\"&&\"9\">=ch;)string+=ch,next();if(\".\"===ch)for(string+=\".\";next()&&ch>=\"0\"&&\"9\">=ch;)string+=ch;if(\"e\"===ch||\"E\"===ch)for(string+=ch,next(),(\"-\"===ch||\"+\"===ch)&&(string+=ch,next());ch>=\"0\"&&\"9\">=ch;)string+=ch,next();return number=+string,isNaN(number)?(error(\"Bad number\"),void 0):number},string=function(){var hex,i,uffff,string=\"\";if('\"'===ch)for(;next();){if('\"'===ch)return next(),string;if(\"\\\\\"===ch)if(next(),\"u\"===ch){for(uffff=0,i=0;4>i&&(hex=parseInt(next(),16),isFinite(hex));i+=1)uffff=16*uffff+hex;string+=String.fromCharCode(uffff)}else{if(\"string\"!=typeof escapee[ch])break;string+=escapee[ch]}else string+=ch}error(\"Bad string\")},white=function(){for(;ch&&\" \">=ch;)next()},word=function(){switch(ch){case\"t\":return next(\"t\"),next(\"r\"),next(\"u\"),next(\"e\"),!0;case\"f\":return next(\"f\"),next(\"a\"),next(\"l\"),next(\"s\"),next(\"e\"),!1;case\"n\":return next(\"n\"),next(\"u\"),next(\"l\"),next(\"l\"),null}error(\"Unexpected '\"+ch+\"'\")},array=function(){var array=[];if(\"[\"===ch){if(next(\"[\"),white(),\"]\"===ch)return next(\"]\"),array;for(;ch;){if(array.push(value()),white(),\"]\"===ch)return next(\"]\"),array;next(\",\"),white()}}error(\"Bad array\")},object=function(){var key,object={};if(\"{\"===ch){if(next(\"{\"),white(),\"}\"===ch)return next(\"}\"),object;for(;ch;){if(key=string(),white(),next(\":\"),Object.hasOwnProperty.call(object,key)&&error('Duplicate key \"'+key+'\"'),object[key]=value(),white(),\"}\"===ch)return next(\"}\"),object;next(\",\"),white()}}error(\"Bad object\")};return value=function(){switch(white(),ch){case\"{\":return object();case\"[\":return array();case'\"':return string();case\"-\":return number();default:return ch>=\"0\"&&\"9\">=ch?number():word()}},function(source,reviver){var result;return text=source,at=0,ch=\" \",result=value(),white(),ch&&error(\"Syntax error\"),\"function\"==typeof reviver?function walk(holder,key){var k,v,value=holder[key];if(value&&\"object\"==typeof value)for(k in value)Object.hasOwnProperty.call(value,k)&&(v=walk(value,k),void 0!==v?value[k]=v:delete value[k]);return reviver.call(holder,key,value)}({\"\":result},\"\"):result}}),ace.define(\"ace/mode/json_worker\",[\"require\",\"exports\",\"module\",\"ace/lib/oop\",\"ace/worker/mirror\",\"ace/mode/json/json_parse\"],function(acequire,exports){\"use strict\";var oop=acequire(\"../lib/oop\"),Mirror=acequire(\"../worker/mirror\").Mirror,parse=acequire(\"./json/json_parse\"),JsonWorker=exports.JsonWorker=function(sender){Mirror.call(this,sender),this.setTimeout(200)};oop.inherits(JsonWorker,Mirror),function(){this.onUpdate=function(){var value=this.doc.getValue(),errors=[];try{value&&parse(value)}catch(e){var pos=this.doc.indexToPosition(e.at-1);errors.push({row:pos.row,column:pos.column,text:e.message,type:\"error\"})}this.sender.emit(\"annotate\",errors)}}.call(JsonWorker.prototype)}),ace.define(\"ace/lib/es5-shim\",[\"require\",\"exports\",\"module\"],function(){function Empty(){}function doesDefinePropertyWork(object){try{return Object.defineProperty(object,\"sentinel\",{}),\"sentinel\"in object}catch(exception){}}function toInteger(n){return n=+n,n!==n?n=0:0!==n&&n!==1/0&&n!==-(1/0)&&(n=(n>0||-1)*Math.floor(Math.abs(n))),n}Function.prototype.bind||(Function.prototype.bind=function(that){var target=this;if(\"function\"!=typeof target)throw new TypeError(\"Function.prototype.bind called on incompatible \"+target);var args=slice.call(arguments,1),bound=function(){if(this instanceof bound){var result=target.apply(this,args.concat(slice.call(arguments)));return Object(result)===result?result:this}return target.apply(that,args.concat(slice.call(arguments)))};return target.prototype&&(Empty.prototype=target.prototype,bound.prototype=new Empty,Empty.prototype=null),bound});var defineGetter,defineSetter,lookupGetter,lookupSetter,supportsAccessors,call=Function.prototype.call,prototypeOfArray=Array.prototype,prototypeOfObject=Object.prototype,slice=prototypeOfArray.slice,_toString=call.bind(prototypeOfObject.toString),owns=call.bind(prototypeOfObject.hasOwnProperty);if((supportsAccessors=owns(prototypeOfObject,\"__defineGetter__\"))&&(defineGetter=call.bind(prototypeOfObject.__defineGetter__),defineSetter=call.bind(prototypeOfObject.__defineSetter__),lookupGetter=call.bind(prototypeOfObject.__lookupGetter__),lookupSetter=call.bind(prototypeOfObject.__lookupSetter__)),2!=[1,2].splice(0).length)if(function(){function makeArray(l){var a=Array(l+2);return a[0]=a[1]=0,a}var lengthBefore,array=[];return array.splice.apply(array,makeArray(20)),array.splice.apply(array,makeArray(26)),lengthBefore=array.length,array.splice(5,0,\"XXX\"),lengthBefore+1==array.length,lengthBefore+1==array.length?!0:void 0\n}()){var array_splice=Array.prototype.splice;Array.prototype.splice=function(start,deleteCount){return arguments.length?array_splice.apply(this,[void 0===start?0:start,void 0===deleteCount?this.length-start:deleteCount].concat(slice.call(arguments,2))):[]}}else Array.prototype.splice=function(pos,removeCount){var length=this.length;pos>0?pos>length&&(pos=length):void 0==pos?pos=0:0>pos&&(pos=Math.max(length+pos,0)),length>pos+removeCount||(removeCount=length-pos);var removed=this.slice(pos,pos+removeCount),insert=slice.call(arguments,2),add=insert.length;if(pos===length)add&&this.push.apply(this,insert);else{var remove=Math.min(removeCount,length-pos),tailOldPos=pos+remove,tailNewPos=tailOldPos+add-remove,tailCount=length-tailOldPos,lengthAfterRemove=length-remove;if(tailOldPos>tailNewPos)for(var i=0;tailCount>i;++i)this[tailNewPos+i]=this[tailOldPos+i];else if(tailNewPos>tailOldPos)for(i=tailCount;i--;)this[tailNewPos+i]=this[tailOldPos+i];if(add&&pos===lengthAfterRemove)this.length=lengthAfterRemove,this.push.apply(this,insert);else for(this.length=lengthAfterRemove+add,i=0;add>i;++i)this[pos+i]=insert[i]}return removed};Array.isArray||(Array.isArray=function(obj){return\"[object Array]\"==_toString(obj)});var boxedString=Object(\"a\"),splitString=\"a\"!=boxedString[0]||!(0 in boxedString);if(Array.prototype.forEach||(Array.prototype.forEach=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,thisp=arguments[1],i=-1,length=self.length>>>0;if(\"[object Function]\"!=_toString(fun))throw new TypeError;for(;length>++i;)i in self&&fun.call(thisp,self[i],i,object)}),Array.prototype.map||(Array.prototype.map=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0,result=Array(length),thisp=arguments[1];if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");for(var i=0;length>i;i++)i in self&&(result[i]=fun.call(thisp,self[i],i,object));return result}),Array.prototype.filter||(Array.prototype.filter=function(fun){var value,object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0,result=[],thisp=arguments[1];if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");for(var i=0;length>i;i++)i in self&&(value=self[i],fun.call(thisp,value,i,object)&&result.push(value));return result}),Array.prototype.every||(Array.prototype.every=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0,thisp=arguments[1];if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");for(var i=0;length>i;i++)if(i in self&&!fun.call(thisp,self[i],i,object))return!1;return!0}),Array.prototype.some||(Array.prototype.some=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0,thisp=arguments[1];if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");for(var i=0;length>i;i++)if(i in self&&fun.call(thisp,self[i],i,object))return!0;return!1}),Array.prototype.reduce||(Array.prototype.reduce=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0;if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");if(!length&&1==arguments.length)throw new TypeError(\"reduce of empty array with no initial value\");var result,i=0;if(arguments.length>=2)result=arguments[1];else for(;;){if(i in self){result=self[i++];break}if(++i>=length)throw new TypeError(\"reduce of empty array with no initial value\")}for(;length>i;i++)i in self&&(result=fun.call(void 0,result,self[i],i,object));return result}),Array.prototype.reduceRight||(Array.prototype.reduceRight=function(fun){var object=toObject(this),self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):object,length=self.length>>>0;if(\"[object Function]\"!=_toString(fun))throw new TypeError(fun+\" is not a function\");if(!length&&1==arguments.length)throw new TypeError(\"reduceRight of empty array with no initial value\");var result,i=length-1;if(arguments.length>=2)result=arguments[1];else for(;;){if(i in self){result=self[i--];break}if(0>--i)throw new TypeError(\"reduceRight of empty array with no initial value\")}do i in this&&(result=fun.call(void 0,result,self[i],i,object));while(i--);return result}),Array.prototype.indexOf&&-1==[0,1].indexOf(1,2)||(Array.prototype.indexOf=function(sought){var self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):toObject(this),length=self.length>>>0;if(!length)return-1;var i=0;for(arguments.length>1&&(i=toInteger(arguments[1])),i=i>=0?i:Math.max(0,length+i);length>i;i++)if(i in self&&self[i]===sought)return i;return-1}),Array.prototype.lastIndexOf&&-1==[0,1].lastIndexOf(0,-3)||(Array.prototype.lastIndexOf=function(sought){var self=splitString&&\"[object String]\"==_toString(this)?this.split(\"\"):toObject(this),length=self.length>>>0;if(!length)return-1;var i=length-1;for(arguments.length>1&&(i=Math.min(i,toInteger(arguments[1]))),i=i>=0?i:length-Math.abs(i);i>=0;i--)if(i in self&&sought===self[i])return i;return-1}),Object.getPrototypeOf||(Object.getPrototypeOf=function(object){return object.__proto__||(object.constructor?object.constructor.prototype:prototypeOfObject)}),!Object.getOwnPropertyDescriptor){var ERR_NON_OBJECT=\"Object.getOwnPropertyDescriptor called on a non-object: \";Object.getOwnPropertyDescriptor=function(object,property){if(\"object\"!=typeof object&&\"function\"!=typeof object||null===object)throw new TypeError(ERR_NON_OBJECT+object);if(owns(object,property)){var descriptor,getter,setter;if(descriptor={enumerable:!0,configurable:!0},supportsAccessors){var prototype=object.__proto__;object.__proto__=prototypeOfObject;var getter=lookupGetter(object,property),setter=lookupSetter(object,property);if(object.__proto__=prototype,getter||setter)return getter&&(descriptor.get=getter),setter&&(descriptor.set=setter),descriptor}return descriptor.value=object[property],descriptor}}}if(Object.getOwnPropertyNames||(Object.getOwnPropertyNames=function(object){return Object.keys(object)}),!Object.create){var createEmpty;createEmpty=null===Object.prototype.__proto__?function(){return{__proto__:null}}:function(){var empty={};for(var i in empty)empty[i]=null;return empty.constructor=empty.hasOwnProperty=empty.propertyIsEnumerable=empty.isPrototypeOf=empty.toLocaleString=empty.toString=empty.valueOf=empty.__proto__=null,empty},Object.create=function(prototype,properties){var object;if(null===prototype)object=createEmpty();else{if(\"object\"!=typeof prototype)throw new TypeError(\"typeof prototype[\"+typeof prototype+\"] != 'object'\");var Type=function(){};Type.prototype=prototype,object=new Type,object.__proto__=prototype}return void 0!==properties&&Object.defineProperties(object,properties),object}}if(Object.defineProperty){var definePropertyWorksOnObject=doesDefinePropertyWork({}),definePropertyWorksOnDom=\"undefined\"==typeof document||doesDefinePropertyWork(document.createElement(\"div\"));if(!definePropertyWorksOnObject||!definePropertyWorksOnDom)var definePropertyFallback=Object.defineProperty}if(!Object.defineProperty||definePropertyFallback){var ERR_NON_OBJECT_DESCRIPTOR=\"Property description must be an object: \",ERR_NON_OBJECT_TARGET=\"Object.defineProperty called on non-object: \",ERR_ACCESSORS_NOT_SUPPORTED=\"getters & setters can not be defined on this javascript engine\";Object.defineProperty=function(object,property,descriptor){if(\"object\"!=typeof object&&\"function\"!=typeof object||null===object)throw new TypeError(ERR_NON_OBJECT_TARGET+object);if(\"object\"!=typeof descriptor&&\"function\"!=typeof descriptor||null===descriptor)throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR+descriptor);if(definePropertyFallback)try{return definePropertyFallback.call(Object,object,property,descriptor)}catch(exception){}if(owns(descriptor,\"value\"))if(supportsAccessors&&(lookupGetter(object,property)||lookupSetter(object,property))){var prototype=object.__proto__;object.__proto__=prototypeOfObject,delete object[property],object[property]=descriptor.value,object.__proto__=prototype}else object[property]=descriptor.value;else{if(!supportsAccessors)throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);owns(descriptor,\"get\")&&defineGetter(object,property,descriptor.get),owns(descriptor,\"set\")&&defineSetter(object,property,descriptor.set)}return object}}Object.defineProperties||(Object.defineProperties=function(object,properties){for(var property in properties)owns(properties,property)&&Object.defineProperty(object,property,properties[property]);return object}),Object.seal||(Object.seal=function(object){return object}),Object.freeze||(Object.freeze=function(object){return object});try{Object.freeze(function(){})}catch(exception){Object.freeze=function(freezeObject){return function(object){return\"function\"==typeof object?object:freezeObject(object)}}(Object.freeze)}if(Object.preventExtensions||(Object.preventExtensions=function(object){return object}),Object.isSealed||(Object.isSealed=function(){return!1}),Object.isFrozen||(Object.isFrozen=function(){return!1}),Object.isExtensible||(Object.isExtensible=function(object){if(Object(object)===object)throw new TypeError;for(var name=\"\";owns(object,name);)name+=\"?\";object[name]=!0;var returnValue=owns(object,name);return delete object[name],returnValue}),!Object.keys){var hasDontEnumBug=!0,dontEnums=[\"toString\",\"toLocaleString\",\"valueOf\",\"hasOwnProperty\",\"isPrototypeOf\",\"propertyIsEnumerable\",\"constructor\"],dontEnumsLength=dontEnums.length;for(var key in{toString:null})hasDontEnumBug=!1;Object.keys=function(object){if(\"object\"!=typeof object&&\"function\"!=typeof object||null===object)throw new TypeError(\"Object.keys called on a non-object\");var keys=[];for(var name in object)owns(object,name)&&keys.push(name);if(hasDontEnumBug)for(var i=0,ii=dontEnumsLength;ii>i;i++){var dontEnum=dontEnums[i];owns(object,dontEnum)&&keys.push(dontEnum)}return keys}}Date.now||(Date.now=function(){return(new Date).getTime()});var ws=\"\t\\n\u000b\\f\\r \\u2028\\u2029\";if(!String.prototype.trim||ws.trim()){ws=\"[\"+ws+\"]\";var trimBeginRegexp=RegExp(\"^\"+ws+ws+\"*\"),trimEndRegexp=RegExp(ws+ws+\"*$\");String.prototype.trim=function(){return(this+\"\").replace(trimBeginRegexp,\"\").replace(trimEndRegexp,\"\")}}var toObject=function(o){if(null==o)throw new TypeError(\"can't convert \"+o+\" to object\");return Object(o)}});"; |
| 35802 |
|
| 35803 |
/***/ }, |
| 35804 |
/* 69 */ |
| 35805 |
/***/ function(module, exports) { |
| 35806 |
|
| 35807 |
ace.define("ace/ext/searchbox",["require","exports","module","ace/lib/dom","ace/lib/lang","ace/lib/event","ace/keyboard/hash_handler","ace/lib/keys"], function(acequire, exports, module) { |
| 35808 |
"use strict"; |
| 35809 |
|
| 35810 |
var dom = acequire("../lib/dom"); |
| 35811 |
var lang = acequire("../lib/lang"); |
| 35812 |
var event = acequire("../lib/event"); |
| 35813 |
var searchboxCss = "\ |
| 35814 |
.ace_search {\ |
| 35815 |
background-color: #ddd;\ |
| 35816 |
border: 1px solid #cbcbcb;\ |
| 35817 |
border-top: 0 none;\ |
| 35818 |
max-width: 325px;\ |
| 35819 |
overflow: hidden;\ |
| 35820 |
margin: 0;\ |
| 35821 |
padding: 4px;\ |
| 35822 |
padding-right: 6px;\ |
| 35823 |
padding-bottom: 0;\ |
| 35824 |
position: absolute;\ |
| 35825 |
top: 0px;\ |
| 35826 |
z-index: 99;\ |
| 35827 |
white-space: normal;\ |
| 35828 |
}\ |
| 35829 |
.ace_search.left {\ |
| 35830 |
border-left: 0 none;\ |
| 35831 |
border-radius: 0px 0px 5px 0px;\ |
| 35832 |
left: 0;\ |
| 35833 |
}\ |
| 35834 |
.ace_search.right {\ |
| 35835 |
border-radius: 0px 0px 0px 5px;\ |
| 35836 |
border-right: 0 none;\ |
| 35837 |
right: 0;\ |
| 35838 |
}\ |
| 35839 |
.ace_search_form, .ace_replace_form {\ |
| 35840 |
border-radius: 3px;\ |
| 35841 |
border: 1px solid #cbcbcb;\ |
| 35842 |
float: left;\ |
| 35843 |
margin-bottom: 4px;\ |
| 35844 |
overflow: hidden;\ |
| 35845 |
}\ |
| 35846 |
.ace_search_form.ace_nomatch {\ |
| 35847 |
outline: 1px solid red;\ |
| 35848 |
}\ |
| 35849 |
.ace_search_field {\ |
| 35850 |
background-color: white;\ |
| 35851 |
border-right: 1px solid #cbcbcb;\ |
| 35852 |
border: 0 none;\ |
| 35853 |
-webkit-box-sizing: border-box;\ |
| 35854 |
-moz-box-sizing: border-box;\ |
| 35855 |
box-sizing: border-box;\ |
| 35856 |
float: left;\ |
| 35857 |
height: 22px;\ |
| 35858 |
outline: 0;\ |
| 35859 |
padding: 0 7px;\ |
| 35860 |
width: 214px;\ |
| 35861 |
margin: 0;\ |
| 35862 |
}\ |
| 35863 |
.ace_searchbtn,\ |
| 35864 |
.ace_replacebtn {\ |
| 35865 |
background: #fff;\ |
| 35866 |
border: 0 none;\ |
| 35867 |
border-left: 1px solid #dcdcdc;\ |
| 35868 |
cursor: pointer;\ |
| 35869 |
float: left;\ |
| 35870 |
height: 22px;\ |
| 35871 |
margin: 0;\ |
| 35872 |
position: relative;\ |
| 35873 |
}\ |
| 35874 |
.ace_searchbtn:last-child,\ |
| 35875 |
.ace_replacebtn:last-child {\ |
| 35876 |
border-top-right-radius: 3px;\ |
| 35877 |
border-bottom-right-radius: 3px;\ |
| 35878 |
}\ |
| 35879 |
.ace_searchbtn:disabled {\ |
| 35880 |
background: none;\ |
| 35881 |
cursor: default;\ |
| 35882 |
}\ |
| 35883 |
.ace_searchbtn {\ |
| 35884 |
background-position: 50% 50%;\ |
| 35885 |
background-repeat: no-repeat;\ |
| 35886 |
width: 27px;\ |
| 35887 |
}\ |
| 35888 |
.ace_searchbtn.prev {\ |
| 35889 |
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAFCAYAAAB4ka1VAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADFJREFUeNpiSU1NZUAC/6E0I0yACYskCpsJiySKIiY0SUZk40FyTEgCjGgKwTRAgAEAQJUIPCE+qfkAAAAASUVORK5CYII=); \ |
| 35890 |
}\ |
| 35891 |
.ace_searchbtn.next {\ |
| 35892 |
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAFCAYAAAB4ka1VAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADRJREFUeNpiTE1NZQCC/0DMyIAKwGJMUAYDEo3M/s+EpvM/mkKwCQxYjIeLMaELoLMBAgwAU7UJObTKsvAAAAAASUVORK5CYII=); \ |
| 35893 |
}\ |
| 35894 |
.ace_searchbtn_close {\ |
| 35895 |
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAcCAYAAABRVo5BAAAAZ0lEQVR42u2SUQrAMAhDvazn8OjZBilCkYVVxiis8H4CT0VrAJb4WHT3C5xU2a2IQZXJjiQIRMdkEoJ5Q2yMqpfDIo+XY4k6h+YXOyKqTIj5REaxloNAd0xiKmAtsTHqW8sR2W5f7gCu5nWFUpVjZwAAAABJRU5ErkJggg==) no-repeat 50% 0;\ |
| 35896 |
border-radius: 50%;\ |
| 35897 |
border: 0 none;\ |
| 35898 |
color: #656565;\ |
| 35899 |
cursor: pointer;\ |
| 35900 |
float: right;\ |
| 35901 |
font: 16px/16px Arial;\ |
| 35902 |
height: 14px;\ |
| 35903 |
margin: 5px 1px 9px 5px;\ |
| 35904 |
padding: 0;\ |
| 35905 |
text-align: center;\ |
| 35906 |
width: 14px;\ |
| 35907 |
}\ |
| 35908 |
.ace_searchbtn_close:hover {\ |
| 35909 |
background-color: #656565;\ |
| 35910 |
background-position: 50% 100%;\ |
| 35911 |
color: white;\ |
| 35912 |
}\ |
| 35913 |
.ace_replacebtn.prev {\ |
| 35914 |
width: 54px\ |
| 35915 |
}\ |
| 35916 |
.ace_replacebtn.next {\ |
| 35917 |
width: 27px\ |
| 35918 |
}\ |
| 35919 |
.ace_button {\ |
| 35920 |
margin-left: 2px;\ |
| 35921 |
cursor: pointer;\ |
| 35922 |
-webkit-user-select: none;\ |
| 35923 |
-moz-user-select: none;\ |
| 35924 |
-o-user-select: none;\ |
| 35925 |
-ms-user-select: none;\ |
| 35926 |
user-select: none;\ |
| 35927 |
overflow: hidden;\ |
| 35928 |
opacity: 0.7;\ |
| 35929 |
border: 1px solid rgba(100,100,100,0.23);\ |
| 35930 |
padding: 1px;\ |
| 35931 |
-moz-box-sizing: border-box;\ |
| 35932 |
box-sizing: border-box;\ |
| 35933 |
color: black;\ |
| 35934 |
}\ |
| 35935 |
.ace_button:hover {\ |
| 35936 |
background-color: #eee;\ |
| 35937 |
opacity:1;\ |
| 35938 |
}\ |
| 35939 |
.ace_button:active {\ |
| 35940 |
background-color: #ddd;\ |
| 35941 |
}\ |
| 35942 |
.ace_button.checked {\ |
| 35943 |
border-color: #3399ff;\ |
| 35944 |
opacity:1;\ |
| 35945 |
}\ |
| 35946 |
.ace_search_options{\ |
| 35947 |
margin-bottom: 3px;\ |
| 35948 |
text-align: right;\ |
| 35949 |
-webkit-user-select: none;\ |
| 35950 |
-moz-user-select: none;\ |
| 35951 |
-o-user-select: none;\ |
| 35952 |
-ms-user-select: none;\ |
| 35953 |
user-select: none;\ |
| 35954 |
}"; |
| 35955 |
var HashHandler = acequire("../keyboard/hash_handler").HashHandler; |
| 35956 |
var keyUtil = acequire("../lib/keys"); |
| 35957 |
|
| 35958 |
dom.importCssString(searchboxCss, "ace_searchbox"); |
| 35959 |
|
| 35960 |
var html = '<div class="ace_search right">\ |
| 35961 |
<button type="button" action="hide" class="ace_searchbtn_close"></button>\ |
| 35962 |
<div class="ace_search_form">\ |
| 35963 |
<input class="ace_search_field" placeholder="Search for" spellcheck="false"></input>\ |
| 35964 |
<button type="button" action="findNext" class="ace_searchbtn next"></button>\ |
| 35965 |
<button type="button" action="findPrev" class="ace_searchbtn prev"></button>\ |
| 35966 |
<button type="button" action="findAll" class="ace_searchbtn" title="Alt-Enter">All</button>\ |
| 35967 |
</div>\ |
| 35968 |
<div class="ace_replace_form">\ |
| 35969 |
<input class="ace_search_field" placeholder="Replace with" spellcheck="false"></input>\ |
| 35970 |
<button type="button" action="replaceAndFindNext" class="ace_replacebtn">Replace</button>\ |
| 35971 |
<button type="button" action="replaceAll" class="ace_replacebtn">All</button>\ |
| 35972 |
</div>\ |
| 35973 |
<div class="ace_search_options">\ |
| 35974 |
<span action="toggleRegexpMode" class="ace_button" title="RegExp Search">.*</span>\ |
| 35975 |
<span action="toggleCaseSensitive" class="ace_button" title="CaseSensitive Search">Aa</span>\ |
| 35976 |
<span action="toggleWholeWords" class="ace_button" title="Whole Word Search">\\b</span>\ |
| 35977 |
</div>\ |
| 35978 |
</div>'.replace(/>\s+/g, ">"); |
| 35979 |
|
| 35980 |
var SearchBox = function(editor, range, showReplaceForm) { |
| 35981 |
var div = dom.createElement("div"); |
| 35982 |
div.innerHTML = html; |
| 35983 |
this.element = div.firstChild; |
| 35984 |
|
| 35985 |
this.$init(); |
| 35986 |
this.setEditor(editor); |
| 35987 |
}; |
| 35988 |
|
| 35989 |
(function() { |
| 35990 |
this.setEditor = function(editor) { |
| 35991 |
editor.searchBox = this; |
| 35992 |
editor.container.appendChild(this.element); |
| 35993 |
this.editor = editor; |
| 35994 |
}; |
| 35995 |
|
| 35996 |
this.$initElements = function(sb) { |
| 35997 |
this.searchBox = sb.querySelector(".ace_search_form"); |
| 35998 |
this.replaceBox = sb.querySelector(".ace_replace_form"); |
| 35999 |
this.searchOptions = sb.querySelector(".ace_search_options"); |
| 36000 |
this.regExpOption = sb.querySelector("[action=toggleRegexpMode]"); |
| 36001 |
this.caseSensitiveOption = sb.querySelector("[action=toggleCaseSensitive]"); |
| 36002 |
this.wholeWordOption = sb.querySelector("[action=toggleWholeWords]"); |
| 36003 |
this.searchInput = this.searchBox.querySelector(".ace_search_field"); |
| 36004 |
this.replaceInput = this.replaceBox.querySelector(".ace_search_field"); |
| 36005 |
}; |
| 36006 |
|
| 36007 |
this.$init = function() { |
| 36008 |
var sb = this.element; |
| 36009 |
|
| 36010 |
this.$initElements(sb); |
| 36011 |
|
| 36012 |
var _this = this; |
| 36013 |
event.addListener(sb, "mousedown", function(e) { |
| 36014 |
setTimeout(function(){ |
| 36015 |
_this.activeInput.focus(); |
| 36016 |
}, 0); |
| 36017 |
event.stopPropagation(e); |
| 36018 |
}); |
| 36019 |
event.addListener(sb, "click", function(e) { |
| 36020 |
var t = e.target || e.srcElement; |
| 36021 |
var action = t.getAttribute("action"); |
| 36022 |
if (action && _this[action]) |
| 36023 |
_this[action](); |
| 36024 |
else if (_this.$searchBarKb.commands[action]) |
| 36025 |
_this.$searchBarKb.commands[action].exec(_this); |
| 36026 |
event.stopPropagation(e); |
| 36027 |
}); |
| 36028 |
|
| 36029 |
event.addCommandKeyListener(sb, function(e, hashId, keyCode) { |
| 36030 |
var keyString = keyUtil.keyCodeToString(keyCode); |
| 36031 |
var command = _this.$searchBarKb.findKeyCommand(hashId, keyString); |
| 36032 |
if (command && command.exec) { |
| 36033 |
command.exec(_this); |
| 36034 |
event.stopEvent(e); |
| 36035 |
} |
| 36036 |
}); |
| 36037 |
|
| 36038 |
this.$onChange = lang.delayedCall(function() { |
| 36039 |
_this.find(false, false); |
| 36040 |
}); |
| 36041 |
|
| 36042 |
event.addListener(this.searchInput, "input", function() { |
| 36043 |
_this.$onChange.schedule(20); |
| 36044 |
}); |
| 36045 |
event.addListener(this.searchInput, "focus", function() { |
| 36046 |
_this.activeInput = _this.searchInput; |
| 36047 |
_this.searchInput.value && _this.highlight(); |
| 36048 |
}); |
| 36049 |
event.addListener(this.replaceInput, "focus", function() { |
| 36050 |
_this.activeInput = _this.replaceInput; |
| 36051 |
_this.searchInput.value && _this.highlight(); |
| 36052 |
}); |
| 36053 |
}; |
| 36054 |
this.$closeSearchBarKb = new HashHandler([{ |
| 36055 |
bindKey: "Esc", |
| 36056 |
name: "closeSearchBar", |
| 36057 |
exec: function(editor) { |
| 36058 |
editor.searchBox.hide(); |
| 36059 |
} |
| 36060 |
}]); |
| 36061 |
this.$searchBarKb = new HashHandler(); |
| 36062 |
this.$searchBarKb.bindKeys({ |
| 36063 |
"Ctrl-f|Command-f": function(sb) { |
| 36064 |
var isReplace = sb.isReplace = !sb.isReplace; |
| 36065 |
sb.replaceBox.style.display = isReplace ? "" : "none"; |
| 36066 |
sb.searchInput.focus(); |
| 36067 |
}, |
| 36068 |
"Ctrl-H|Command-Option-F": function(sb) { |
| 36069 |
sb.replaceBox.style.display = ""; |
| 36070 |
sb.replaceInput.focus(); |
| 36071 |
}, |
| 36072 |
"Ctrl-G|Command-G": function(sb) { |
| 36073 |
sb.findNext(); |
| 36074 |
}, |
| 36075 |
"Ctrl-Shift-G|Command-Shift-G": function(sb) { |
| 36076 |
sb.findPrev(); |
| 36077 |
}, |
| 36078 |
"esc": function(sb) { |
| 36079 |
setTimeout(function() { sb.hide();}); |
| 36080 |
}, |
| 36081 |
"Return": function(sb) { |
| 36082 |
if (sb.activeInput == sb.replaceInput) |
| 36083 |
sb.replace(); |
| 36084 |
sb.findNext(); |
| 36085 |
}, |
| 36086 |
"Shift-Return": function(sb) { |
| 36087 |
if (sb.activeInput == sb.replaceInput) |
| 36088 |
sb.replace(); |
| 36089 |
sb.findPrev(); |
| 36090 |
}, |
| 36091 |
"Alt-Return": function(sb) { |
| 36092 |
if (sb.activeInput == sb.replaceInput) |
| 36093 |
sb.replaceAll(); |
| 36094 |
sb.findAll(); |
| 36095 |
}, |
| 36096 |
"Tab": function(sb) { |
| 36097 |
(sb.activeInput == sb.replaceInput ? sb.searchInput : sb.replaceInput).focus(); |
| 36098 |
} |
| 36099 |
}); |
| 36100 |
|
| 36101 |
this.$searchBarKb.addCommands([{ |
| 36102 |
name: "toggleRegexpMode", |
| 36103 |
bindKey: {win: "Alt-R|Alt-/", mac: "Ctrl-Alt-R|Ctrl-Alt-/"}, |
| 36104 |
exec: function(sb) { |
| 36105 |
sb.regExpOption.checked = !sb.regExpOption.checked; |
| 36106 |
sb.$syncOptions(); |
| 36107 |
} |
| 36108 |
}, { |
| 36109 |
name: "toggleCaseSensitive", |
| 36110 |
bindKey: {win: "Alt-C|Alt-I", mac: "Ctrl-Alt-R|Ctrl-Alt-I"}, |
| 36111 |
exec: function(sb) { |
| 36112 |
sb.caseSensitiveOption.checked = !sb.caseSensitiveOption.checked; |
| 36113 |
sb.$syncOptions(); |
| 36114 |
} |
| 36115 |
}, { |
| 36116 |
name: "toggleWholeWords", |
| 36117 |
bindKey: {win: "Alt-B|Alt-W", mac: "Ctrl-Alt-B|Ctrl-Alt-W"}, |
| 36118 |
exec: function(sb) { |
| 36119 |
sb.wholeWordOption.checked = !sb.wholeWordOption.checked; |
| 36120 |
sb.$syncOptions(); |
| 36121 |
} |
| 36122 |
}]); |
| 36123 |
|
| 36124 |
this.$syncOptions = function() { |
| 36125 |
dom.setCssClass(this.regExpOption, "checked", this.regExpOption.checked); |
| 36126 |
dom.setCssClass(this.wholeWordOption, "checked", this.wholeWordOption.checked); |
| 36127 |
dom.setCssClass(this.caseSensitiveOption, "checked", this.caseSensitiveOption.checked); |
| 36128 |
this.find(false, false); |
| 36129 |
}; |
| 36130 |
|
| 36131 |
this.highlight = function(re) { |
| 36132 |
this.editor.session.highlight(re || this.editor.$search.$options.re); |
| 36133 |
this.editor.renderer.updateBackMarkers() |
| 36134 |
}; |
| 36135 |
this.find = function(skipCurrent, backwards, preventScroll) { |
| 36136 |
var range = this.editor.find(this.searchInput.value, { |
| 36137 |
skipCurrent: skipCurrent, |
| 36138 |
backwards: backwards, |
| 36139 |
wrap: true, |
| 36140 |
regExp: this.regExpOption.checked, |
| 36141 |
caseSensitive: this.caseSensitiveOption.checked, |
| 36142 |
wholeWord: this.wholeWordOption.checked, |
| 36143 |
preventScroll: preventScroll |
| 36144 |
}); |
| 36145 |
var noMatch = !range && this.searchInput.value; |
| 36146 |
dom.setCssClass(this.searchBox, "ace_nomatch", noMatch); |
| 36147 |
this.editor._emit("findSearchBox", { match: !noMatch }); |
| 36148 |
this.highlight(); |
| 36149 |
}; |
| 36150 |
this.findNext = function() { |
| 36151 |
this.find(true, false); |
| 36152 |
}; |
| 36153 |
this.findPrev = function() { |
| 36154 |
this.find(true, true); |
| 36155 |
}; |
| 36156 |
this.findAll = function(){ |
| 36157 |
var range = this.editor.findAll(this.searchInput.value, { |
| 36158 |
regExp: this.regExpOption.checked, |
| 36159 |
caseSensitive: this.caseSensitiveOption.checked, |
| 36160 |
wholeWord: this.wholeWordOption.checked |
| 36161 |
}); |
| 36162 |
var noMatch = !range && this.searchInput.value; |
| 36163 |
dom.setCssClass(this.searchBox, "ace_nomatch", noMatch); |
| 36164 |
this.editor._emit("findSearchBox", { match: !noMatch }); |
| 36165 |
this.highlight(); |
| 36166 |
this.hide(); |
| 36167 |
}; |
| 36168 |
this.replace = function() { |
| 36169 |
if (!this.editor.getReadOnly()) |
| 36170 |
this.editor.replace(this.replaceInput.value); |
| 36171 |
}; |
| 36172 |
this.replaceAndFindNext = function() { |
| 36173 |
if (!this.editor.getReadOnly()) { |
| 36174 |
this.editor.replace(this.replaceInput.value); |
| 36175 |
this.findNext() |
| 36176 |
} |
| 36177 |
}; |
| 36178 |
this.replaceAll = function() { |
| 36179 |
if (!this.editor.getReadOnly()) |
| 36180 |
this.editor.replaceAll(this.replaceInput.value); |
| 36181 |
}; |
| 36182 |
|
| 36183 |
this.hide = function() { |
| 36184 |
this.element.style.display = "none"; |
| 36185 |
this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb); |
| 36186 |
this.editor.focus(); |
| 36187 |
}; |
| 36188 |
this.show = function(value, isReplace) { |
| 36189 |
this.element.style.display = ""; |
| 36190 |
this.replaceBox.style.display = isReplace ? "" : "none"; |
| 36191 |
|
| 36192 |
this.isReplace = isReplace; |
| 36193 |
|
| 36194 |
if (value) |
| 36195 |
this.searchInput.value = value; |
| 36196 |
|
| 36197 |
this.find(false, false, true); |
| 36198 |
|
| 36199 |
this.searchInput.focus(); |
| 36200 |
this.searchInput.select(); |
| 36201 |
|
| 36202 |
this.editor.keyBinding.addKeyboardHandler(this.$closeSearchBarKb); |
| 36203 |
}; |
| 36204 |
|
| 36205 |
this.isFocused = function() { |
| 36206 |
var el = document.activeElement; |
| 36207 |
return el == this.searchInput || el == this.replaceInput; |
| 36208 |
} |
| 36209 |
}).call(SearchBox.prototype); |
| 36210 |
|
| 36211 |
exports.SearchBox = SearchBox; |
| 36212 |
|
| 36213 |
exports.Search = function(editor, isReplace) { |
| 36214 |
var sb = editor.searchBox || new SearchBox(editor); |
| 36215 |
sb.show(editor.session.getTextRange(), isReplace); |
| 36216 |
}; |
| 36217 |
|
| 36218 |
}); |
| 36219 |
(function() { |
| 36220 |
ace.acequire(["ace/ext/searchbox"], function() {}); |
| 36221 |
})(); |
| 36222 |
|
| 36223 |
|
| 36224 |
/***/ }, |
| 36225 |
/* 70 */ |
| 36226 |
/***/ function(module, exports) { |
| 36227 |
|
| 36228 |
/* ***** BEGIN LICENSE BLOCK ***** |
| 36229 |
* Distributed under the BSD license: |
| 36230 |
* |
| 36231 |
* Copyright (c) 2010, Ajax.org B.V. |
| 36232 |
* All rights reserved. |
| 36233 |
* |
| 36234 |
* Redistribution and use in source and binary forms, with or without |
| 36235 |
* modification, are permitted provided that the following conditions are met: |
| 36236 |
* * Redistributions of source code must retain the above copyright |
| 36237 |
* notice, this list of conditions and the following disclaimer. |
| 36238 |
* * Redistributions in binary form must reproduce the above copyright |
| 36239 |
* notice, this list of conditions and the following disclaimer in the |
| 36240 |
* documentation and/or other materials provided with the distribution. |
| 36241 |
* * Neither the name of Ajax.org B.V. nor the |
| 36242 |
* names of its contributors may be used to endorse or promote products |
| 36243 |
* derived from this software without specific prior written permission. |
| 36244 |
* |
| 36245 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 36246 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 36247 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 36248 |
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY |
| 36249 |
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 36250 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 36251 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 36252 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 36253 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 36254 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36255 |
* |
| 36256 |
* ***** END LICENSE BLOCK ***** */ |
| 36257 |
|
| 36258 |
ace.define('ace/theme/jsoneditor', ['require', 'exports', 'module', 'ace/lib/dom'], function(acequire, exports, module) { |
| 36259 |
|
| 36260 |
exports.isDark = false; |
| 36261 |
exports.cssClass = "ace-jsoneditor"; |
| 36262 |
exports.cssText = ".ace-jsoneditor .ace_gutter {\ |
| 36263 |
background: #ebebeb;\ |
| 36264 |
color: #333\ |
| 36265 |
}\ |
| 36266 |
\ |
| 36267 |
.ace-jsoneditor.ace_editor {\ |
| 36268 |
font-family: droid sans mono, consolas, monospace, courier new, courier, sans-serif;\ |
| 36269 |
line-height: 1.3;\ |
| 36270 |
}\ |
| 36271 |
.ace-jsoneditor .ace_print-margin {\ |
| 36272 |
width: 1px;\ |
| 36273 |
background: #e8e8e8\ |
| 36274 |
}\ |
| 36275 |
.ace-jsoneditor .ace_scroller {\ |
| 36276 |
background-color: #FFFFFF\ |
| 36277 |
}\ |
| 36278 |
.ace-jsoneditor .ace_text-layer {\ |
| 36279 |
color: gray\ |
| 36280 |
}\ |
| 36281 |
.ace-jsoneditor .ace_variable {\ |
| 36282 |
color: #1a1a1a\ |
| 36283 |
}\ |
| 36284 |
.ace-jsoneditor .ace_cursor {\ |
| 36285 |
border-left: 2px solid #000000\ |
| 36286 |
}\ |
| 36287 |
.ace-jsoneditor .ace_overwrite-cursors .ace_cursor {\ |
| 36288 |
border-left: 0px;\ |
| 36289 |
border-bottom: 1px solid #000000\ |
| 36290 |
}\ |
| 36291 |
.ace-jsoneditor .ace_marker-layer .ace_selection {\ |
| 36292 |
background: lightgray\ |
| 36293 |
}\ |
| 36294 |
.ace-jsoneditor.ace_multiselect .ace_selection.ace_start {\ |
| 36295 |
box-shadow: 0 0 3px 0px #FFFFFF;\ |
| 36296 |
border-radius: 2px\ |
| 36297 |
}\ |
| 36298 |
.ace-jsoneditor .ace_marker-layer .ace_step {\ |
| 36299 |
background: rgb(255, 255, 0)\ |
| 36300 |
}\ |
| 36301 |
.ace-jsoneditor .ace_marker-layer .ace_bracket {\ |
| 36302 |
margin: -1px 0 0 -1px;\ |
| 36303 |
border: 1px solid #BFBFBF\ |
| 36304 |
}\ |
| 36305 |
.ace-jsoneditor .ace_marker-layer .ace_active-line {\ |
| 36306 |
background: #FFFBD1\ |
| 36307 |
}\ |
| 36308 |
.ace-jsoneditor .ace_gutter-active-line {\ |
| 36309 |
background-color : #dcdcdc\ |
| 36310 |
}\ |
| 36311 |
.ace-jsoneditor .ace_marker-layer .ace_selected-word {\ |
| 36312 |
border: 1px solid lightgray\ |
| 36313 |
}\ |
| 36314 |
.ace-jsoneditor .ace_invisible {\ |
| 36315 |
color: #BFBFBF\ |
| 36316 |
}\ |
| 36317 |
.ace-jsoneditor .ace_keyword,\ |
| 36318 |
.ace-jsoneditor .ace_meta,\ |
| 36319 |
.ace-jsoneditor .ace_support.ace_constant.ace_property-value {\ |
| 36320 |
color: #AF956F\ |
| 36321 |
}\ |
| 36322 |
.ace-jsoneditor .ace_keyword.ace_operator {\ |
| 36323 |
color: #484848\ |
| 36324 |
}\ |
| 36325 |
.ace-jsoneditor .ace_keyword.ace_other.ace_unit {\ |
| 36326 |
color: #96DC5F\ |
| 36327 |
}\ |
| 36328 |
.ace-jsoneditor .ace_constant.ace_language {\ |
| 36329 |
color: darkorange\ |
| 36330 |
}\ |
| 36331 |
.ace-jsoneditor .ace_constant.ace_numeric {\ |
| 36332 |
color: red\ |
| 36333 |
}\ |
| 36334 |
.ace-jsoneditor .ace_constant.ace_character.ace_entity {\ |
| 36335 |
color: #BF78CC\ |
| 36336 |
}\ |
| 36337 |
.ace-jsoneditor .ace_invalid {\ |
| 36338 |
color: #FFFFFF;\ |
| 36339 |
background-color: #FF002A;\ |
| 36340 |
}\ |
| 36341 |
.ace-jsoneditor .ace_fold {\ |
| 36342 |
background-color: #AF956F;\ |
| 36343 |
border-color: #000000\ |
| 36344 |
}\ |
| 36345 |
.ace-jsoneditor .ace_storage,\ |
| 36346 |
.ace-jsoneditor .ace_support.ace_class,\ |
| 36347 |
.ace-jsoneditor .ace_support.ace_function,\ |
| 36348 |
.ace-jsoneditor .ace_support.ace_other,\ |
| 36349 |
.ace-jsoneditor .ace_support.ace_type {\ |
| 36350 |
color: #C52727\ |
| 36351 |
}\ |
| 36352 |
.ace-jsoneditor .ace_string {\ |
| 36353 |
color: green\ |
| 36354 |
}\ |
| 36355 |
.ace-jsoneditor .ace_comment {\ |
| 36356 |
color: #BCC8BA\ |
| 36357 |
}\ |
| 36358 |
.ace-jsoneditor .ace_entity.ace_name.ace_tag,\ |
| 36359 |
.ace-jsoneditor .ace_entity.ace_other.ace_attribute-name {\ |
| 36360 |
color: #606060\ |
| 36361 |
}\ |
| 36362 |
.ace-jsoneditor .ace_markup.ace_underline {\ |
| 36363 |
text-decoration: underline\ |
| 36364 |
}\ |
| 36365 |
.ace-jsoneditor .ace_indent-guide {\ |
| 36366 |
background: url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==\") right repeat-y\ |
| 36367 |
}"; |
| 36368 |
|
| 36369 |
var dom = acequire("../lib/dom"); |
| 36370 |
dom.importCssString(exports.cssText, exports.cssClass); |
| 36371 |
}); |
| 36372 |
|
| 36373 |
|
| 36374 |
/***/ } |
| 36375 |
/******/ ]) |
| 36376 |
}); |
| 36377 |
; |