1 | ;
|
2 | /*-----------------------------------------------------------------------------
|
3 | | Copyright (c) 2014-2017, PhosphorJS Contributors
|
4 | |
|
5 | | Distributed under the terms of the BSD 3-Clause License.
|
6 | |
|
7 | | The full license is in the file LICENSE, distributed with this software.
|
8 | |----------------------------------------------------------------------------*/
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | /**
|
11 | * An object which stores MIME data for general application use.
|
12 | *
|
13 | * #### Notes
|
14 | * This class does not attempt to enforce "correctness" of MIME types
|
15 | * and their associated data. Since this class is designed to transfer
|
16 | * arbitrary data and objects within the same application, it assumes
|
17 | * that the user provides correct and accurate data.
|
18 | */
|
19 | var MimeData = /** @class */ (function () {
|
20 | function MimeData() {
|
21 | this._types = [];
|
22 | this._values = [];
|
23 | }
|
24 | /**
|
25 | * Get an array of the MIME types contained within the dataset.
|
26 | *
|
27 | * @returns A new array of the MIME types, in order of insertion.
|
28 | */
|
29 | MimeData.prototype.types = function () {
|
30 | return this._types.slice();
|
31 | };
|
32 | /**
|
33 | * Test whether the dataset has an entry for the given type.
|
34 | *
|
35 | * @param mime - The MIME type of interest.
|
36 | *
|
37 | * @returns `true` if the dataset contains a value for the given
|
38 | * MIME type, `false` otherwise.
|
39 | */
|
40 | MimeData.prototype.hasData = function (mime) {
|
41 | return this._types.indexOf(mime) !== -1;
|
42 | };
|
43 | /**
|
44 | * Get the data value for the given MIME type.
|
45 | *
|
46 | * @param mime - The MIME type of interest.
|
47 | *
|
48 | * @returns The value for the given MIME type, or `undefined` if
|
49 | * the dataset does not contain a value for the type.
|
50 | */
|
51 | MimeData.prototype.getData = function (mime) {
|
52 | var i = this._types.indexOf(mime);
|
53 | return i !== -1 ? this._values[i] : undefined;
|
54 | };
|
55 | /**
|
56 | * Set the data value for the given MIME type.
|
57 | *
|
58 | * @param mime - The MIME type of interest.
|
59 | *
|
60 | * @param data - The data value for the given MIME type.
|
61 | *
|
62 | * #### Notes
|
63 | * This will overwrite any previous entry for the MIME type.
|
64 | */
|
65 | MimeData.prototype.setData = function (mime, data) {
|
66 | this.clearData(mime);
|
67 | this._types.push(mime);
|
68 | this._values.push(data);
|
69 | };
|
70 | /**
|
71 | * Remove the data entry for the given MIME type.
|
72 | *
|
73 | * @param mime - The MIME type of interest.
|
74 | *
|
75 | * #### Notes
|
76 | * This is a no-op if there is no entry for the given MIME type.
|
77 | */
|
78 | MimeData.prototype.clearData = function (mime) {
|
79 | var i = this._types.indexOf(mime);
|
80 | if (i !== -1) {
|
81 | this._types.splice(i, 1);
|
82 | this._values.splice(i, 1);
|
83 | }
|
84 | };
|
85 | /**
|
86 | * Remove all data entries from the dataset.
|
87 | */
|
88 | MimeData.prototype.clear = function () {
|
89 | this._types.length = 0;
|
90 | this._values.length = 0;
|
91 | };
|
92 | return MimeData;
|
93 | }());
|
94 | exports.MimeData = MimeData;
|