@atlassian/aui 9.12.6 → 10.0.0-M02
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aui/aui-css-deprecations.js +1 -1
- package/dist/aui/aui-css-deprecations.js.map +1 -1
- package/dist/aui/aui-prototyping-browserfocus.css +1 -1
- package/dist/aui/aui-prototyping-browserfocus.css.map +1 -1
- package/dist/aui/aui-prototyping-darkmode.css.map +1 -1
- package/dist/aui/aui-prototyping-design-tokens-api-full.js +1 -1
- package/dist/aui/aui-prototyping-design-tokens-api.js +1 -1
- package/dist/aui/aui-prototyping-design-tokens-base-themes-css.css +1 -1
- package/dist/aui/aui-prototyping-design-tokens-base-themes-css.js +1 -1
- package/dist/aui/aui-prototyping-design-tokens-base-themes.js +1 -1
- package/dist/aui/aui-prototyping.css +4 -4
- package/dist/aui/aui-prototyping.css.map +1 -1
- package/dist/aui/aui-prototyping.js +10 -10
- package/dist/aui/aui-prototyping.js.map +1 -1
- package/dist/aui/aui-prototyping.nodeps.css +4 -4
- package/dist/aui/aui-prototyping.nodeps.css.map +1 -1
- package/dist/aui/aui-prototyping.nodeps.js +10 -10
- package/dist/aui/aui-prototyping.nodeps.js.map +1 -1
- package/entry/internal/deprecation.js +1 -1
- package/package.json +6 -4
- package/src/js/aui/dialog.js +10 -2
- package/src/js/aui/internal/deprecation.ts +368 -0
- package/src/js/aui/internal/select/suggestions-model.js +72 -50
- package/src/js/aui/internal/select/suggestions-view.js +103 -58
- package/src/js/aui/layer-manager-global.js +2 -2
- package/src/less/aui-select2.less +1 -1
- package/src/less/forms-current.less +9 -11
- package/src/less/imports/aui-theme/core/colors.less +2 -2
- package/src/js/aui/internal/deprecation.js +0 -323
|
@@ -3,13 +3,17 @@ import { I18n } from '../../i18n';
|
|
|
3
3
|
import Alignment from '../alignment';
|
|
4
4
|
import layer from '../../layer';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} listId
|
|
8
|
+
* @param {number} index
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
6
11
|
function generateListItemID (listId, index) {
|
|
7
12
|
return listId + '-' + index;
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @param view SuggestionsView
|
|
16
|
+
* @param {SuggestionsViewType} view
|
|
13
17
|
*/
|
|
14
18
|
function enableAlignment (view) {
|
|
15
19
|
if (view.anchor && !view._auiAlignment) {
|
|
@@ -27,12 +31,18 @@ function enableAlignment (view) {
|
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @param {SuggestionsViewType} view
|
|
36
|
+
*/
|
|
30
37
|
function disableAlignment (view) {
|
|
31
38
|
if (view._auiAlignment) {
|
|
32
39
|
view._auiAlignment.disable();
|
|
33
40
|
}
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @param {SuggestionsViewType} view
|
|
45
|
+
*/
|
|
36
46
|
function destroyAlignment (view) {
|
|
37
47
|
if (view._auiAlignment) {
|
|
38
48
|
view._auiAlignment.destroy();
|
|
@@ -40,73 +50,108 @@ function destroyAlignment (view) {
|
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @param {SuggestionsViewType} view
|
|
55
|
+
*/
|
|
43
56
|
function matchWidth (view) {
|
|
44
57
|
$(view.el).css('min-width', $(view.anchor).outerWidth());
|
|
45
58
|
}
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
60
|
+
/**
|
|
61
|
+
* @param {HTMLElement} element
|
|
62
|
+
*/
|
|
52
63
|
function clearActive (element) {
|
|
53
64
|
$(element).find('.aui-select-active').removeClass('aui-select-active');
|
|
54
65
|
}
|
|
55
66
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// Do nothing if we have no new suggestions, otherwise append anything else we find.
|
|
62
|
-
if (suggestions.length) {
|
|
63
|
-
for (let i = 0; i < suggestions.length; i++) {
|
|
64
|
-
const suggestion = suggestions[i];
|
|
65
|
-
const currentIndex = i + currentLength;
|
|
66
|
-
const label = suggestion.getLabel();
|
|
67
|
-
const imageSrc = suggestion.get('img-src');
|
|
68
|
-
const image = imageSrc ? `<img src="${encodeURI(imageSrc)}"/>` : '';
|
|
69
|
-
const newValueText = suggestion.get('new-value') ? (` (<em>${I18n.getText('aui.select.new.value')}</em>)`) : '';
|
|
70
|
-
html += `<li role="option" class="aui-select-suggestion" aria-selected="${selected === currentIndex}" id="${generateListItemID(listId, currentIndex)}">${image}${label}${newValueText}</li>`;
|
|
71
|
-
}
|
|
67
|
+
/**
|
|
68
|
+
* @typedef {Object} Suggestion
|
|
69
|
+
* @property {function(): string} getLabel
|
|
70
|
+
* @property {function(string): string} get
|
|
71
|
+
*/
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @typedef {Object} SuggestionsViewType
|
|
75
|
+
* @property {HTMLElement} el
|
|
76
|
+
* @property {HTMLElement} anchor
|
|
77
|
+
* @property {Alignment} [_auiAlignment]
|
|
78
|
+
* @property {string} [currListId]
|
|
79
|
+
* @property {(suggestions: Suggestion[], currentLength: number, listId: string, selected: number) => SuggestionsViewType} render
|
|
80
|
+
* @property {(active: number) => void} setActive
|
|
81
|
+
* @property {() => HTMLElement|null} getActive
|
|
82
|
+
* @property {() => void} show
|
|
83
|
+
* @property {() => void} hide
|
|
84
|
+
* @property {() => void} destroy
|
|
85
|
+
* @property {() => boolean} isVisible
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @constructor
|
|
90
|
+
* @param {HTMLElement} element
|
|
91
|
+
* @param {HTMLElement} anchor
|
|
92
|
+
* @returns {SuggestionsViewType}
|
|
93
|
+
*/
|
|
94
|
+
function SuggestionsView(element, anchor) {
|
|
95
|
+
const view = {
|
|
96
|
+
el: element,
|
|
97
|
+
anchor: anchor,
|
|
98
|
+
|
|
99
|
+
render: function (suggestions, currentLength, listId, selected) {
|
|
100
|
+
this.currListId = listId;
|
|
101
|
+
let html = '';
|
|
102
|
+
|
|
103
|
+
// Do nothing if we have no new suggestions, otherwise append anything else we find.
|
|
104
|
+
if (suggestions.length) {
|
|
105
|
+
for (let i = 0; i < suggestions.length; i++) {
|
|
106
|
+
const suggestion = suggestions[i];
|
|
107
|
+
const currentIndex = i + currentLength;
|
|
108
|
+
const label = suggestion.getLabel();
|
|
109
|
+
const imageSrc = suggestion.get('img-src');
|
|
110
|
+
const image = imageSrc ? `<img src="${encodeURI(imageSrc)}"/>` : '';
|
|
111
|
+
const newValueText = suggestion.get('new-value') ? (` (<em>${I18n.getText('aui.select.new.value')}</em>)`) : '';
|
|
112
|
+
html += `<li role="option" class="aui-select-suggestion" aria-selected="${selected === currentIndex}" id="${generateListItemID(listId, currentIndex)}">${image}${label}${newValueText}</li>`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// If the old suggestions were empty, a <li> of 'No suggestions' will be appended, we need to remove it
|
|
116
|
+
if (currentLength) {
|
|
117
|
+
this.el.querySelector('ul').innerHTML += html;
|
|
118
|
+
} else {
|
|
119
|
+
this.el.querySelector('ul').innerHTML = html;
|
|
120
|
+
}
|
|
121
|
+
} else if (!currentLength) {
|
|
122
|
+
this.el.querySelector('ul').innerHTML = `<li role="option" class="aui-select-no-suggestions">${I18n.getText('aui.select.no.suggestions')}</li>`;
|
|
78
123
|
}
|
|
79
|
-
|
|
80
|
-
this
|
|
124
|
+
|
|
125
|
+
return this;
|
|
126
|
+
},
|
|
127
|
+
setActive: function (active) {
|
|
128
|
+
clearActive(this.el);
|
|
129
|
+
$(this.el).find('#' + generateListItemID(this.currListId, active)).addClass('aui-select-active');
|
|
130
|
+
},
|
|
131
|
+
getActive: function () {
|
|
132
|
+
return this.el.querySelector('.aui-select-active');
|
|
133
|
+
},
|
|
134
|
+
show: function () {
|
|
135
|
+
matchWidth(this);
|
|
136
|
+
layer(this.el).show();
|
|
137
|
+
enableAlignment(this);
|
|
138
|
+
},
|
|
139
|
+
hide: function () {
|
|
140
|
+
clearActive(this.el);
|
|
141
|
+
layer(this.el).hide();
|
|
142
|
+
disableAlignment(this);
|
|
143
|
+
},
|
|
144
|
+
destroy: function () {
|
|
145
|
+
this.hide();
|
|
146
|
+
destroyAlignment(this);
|
|
147
|
+
delete this.currListId;
|
|
148
|
+
},
|
|
149
|
+
isVisible: function () {
|
|
150
|
+
return $(this.el).is(':visible');
|
|
81
151
|
}
|
|
152
|
+
};
|
|
82
153
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
setActive: function (active) {
|
|
86
|
-
clearActive(this.el);
|
|
87
|
-
$(this.el).find('#' + generateListItemID(this.currListId, active)).addClass('aui-select-active');
|
|
88
|
-
},
|
|
89
|
-
getActive: function () {
|
|
90
|
-
return this.el.querySelector('.aui-select-active');
|
|
91
|
-
},
|
|
92
|
-
show: function () {
|
|
93
|
-
matchWidth(this);
|
|
94
|
-
layer(this.el).show();
|
|
95
|
-
enableAlignment(this);
|
|
96
|
-
},
|
|
97
|
-
hide: function () {
|
|
98
|
-
clearActive(this.el);
|
|
99
|
-
layer(this.el).hide();
|
|
100
|
-
disableAlignment(this);
|
|
101
|
-
},
|
|
102
|
-
destroy: function () {
|
|
103
|
-
this.hide();
|
|
104
|
-
destroyAlignment(this);
|
|
105
|
-
delete this.currListId;
|
|
106
|
-
},
|
|
107
|
-
isVisible: function () {
|
|
108
|
-
return $(this.el).is(':visible');
|
|
109
|
-
}
|
|
110
|
-
};
|
|
154
|
+
return view;
|
|
155
|
+
}
|
|
111
156
|
|
|
112
157
|
export default SuggestionsView;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default
|
|
1
|
+
import layer from './layer';
|
|
2
|
+
export default layer.Manager.global;
|
|
@@ -341,7 +341,7 @@
|
|
|
341
341
|
}
|
|
342
342
|
|
|
343
343
|
.select2-search-choice {
|
|
344
|
-
.aui-select2-container .select2-choices & {
|
|
344
|
+
.aui-select2-container.select2-container-multi .select2-choices & {
|
|
345
345
|
background: var(--aui-select2-chosen-bg-color);
|
|
346
346
|
border: 1px solid $background;
|
|
347
347
|
border-radius: @aui-select2-chosen-border-radius;
|
|
@@ -15,7 +15,8 @@ form.aui:not(.aui-legacy-forms) {
|
|
|
15
15
|
font-size: @aui-font-size-medium;
|
|
16
16
|
font-family: inherit;
|
|
17
17
|
|
|
18
|
-
&:hover
|
|
18
|
+
&:hover,
|
|
19
|
+
&.hover {
|
|
19
20
|
#aui-forms.aui-input-field-style(hover);
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -38,21 +39,24 @@ form.aui:not(.aui-legacy-forms) {
|
|
|
38
39
|
font-size: @aui-font-size-medium;
|
|
39
40
|
font-family: inherit;
|
|
40
41
|
|
|
41
|
-
&:hover
|
|
42
|
+
&:hover,
|
|
43
|
+
&.hover {
|
|
42
44
|
#aui-forms.aui-select2-input-field-style(hover);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
.select,
|
|
47
49
|
.multi-select {
|
|
48
|
-
&:hover
|
|
50
|
+
&:hover,
|
|
51
|
+
&.hover {
|
|
49
52
|
background-color: @aui-form-select-hover-bg-color;
|
|
50
|
-
border-color: @aui-form-select-
|
|
53
|
+
border-color: @aui-form-select-border-color;
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
.aui-select2-container {
|
|
55
|
-
& > ul:hover
|
|
58
|
+
& > ul:hover,
|
|
59
|
+
& > ul.hover {
|
|
56
60
|
#aui-forms.aui-select2-input-field-style(hover);
|
|
57
61
|
}
|
|
58
62
|
|
|
@@ -61,12 +65,6 @@ form.aui:not(.aui-legacy-forms) {
|
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
.multi-select {
|
|
65
|
-
&:hover > option {
|
|
66
|
-
#aui-forms.aui-select2-input-field-style(hover);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
68
|
.text,
|
|
71
69
|
.password,
|
|
72
70
|
.textarea,
|
|
@@ -883,7 +883,7 @@
|
|
|
883
883
|
--aui-form-disabled-field-text-color: var(--ds-text-disabled, @ak-color-N80);
|
|
884
884
|
--aui-form-disabled-field-label-color: var(--ds-text-disabled, @ak-color-N80);
|
|
885
885
|
--aui-form-field-border-color: var(--ds-border-input, @ak-color-N40);
|
|
886
|
-
--aui-form-field-hover-border-color: var(--ds-border-
|
|
886
|
+
--aui-form-field-hover-border-color: var(--ds-border-input, @ak-color-N40);
|
|
887
887
|
--aui-form-field-default-text-color: var(--ds-text, @ak-color-N800);
|
|
888
888
|
--aui-form-field-default-bg-color: var(--ds-background-input, @ak-color-N10);
|
|
889
889
|
--aui-form-field-hover-text-color: var(--ds-text);
|
|
@@ -891,7 +891,7 @@
|
|
|
891
891
|
--aui-form-field-focus-bg-color: var(--ds-background-input, @ak-color-N0);
|
|
892
892
|
--aui-form-select-bg-color: var(--ds-background-input, @ak-color-N30);
|
|
893
893
|
--aui-form-select-border-color: var(--ds-border-input, @ak-color-N30);
|
|
894
|
-
--aui-form-select-hover-bg-color: var(--ds-
|
|
894
|
+
--aui-form-select-hover-bg-color: var(--ds-background-input-hovered, @ak-color-N40);
|
|
895
895
|
--aui-form-checkbox-radio-active-bg-color: var(--ds-background-accent-blue-subtler, @ak-color-B50);
|
|
896
896
|
--aui-form-optgroup-text-color: var(--ds-text-subtlest, @ak-color-N100);
|
|
897
897
|
--aui-form-optgroup-bg-color: var(--ds-background-neutral, @ak-color-N20);
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import $ from '../jquery';
|
|
2
|
-
import globalize from './globalize';
|
|
3
|
-
|
|
4
|
-
var has = Object.prototype.hasOwnProperty;
|
|
5
|
-
var deprecationCalls = [];
|
|
6
|
-
|
|
7
|
-
function toSentenceCase (str) {
|
|
8
|
-
str += '';
|
|
9
|
-
|
|
10
|
-
if (!str) {
|
|
11
|
-
return '';
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return str.charAt(0).toUpperCase() + str.substring(1);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getDeprecatedLocation (printFrameOffset) {
|
|
18
|
-
var err = new Error();
|
|
19
|
-
var stack = err.stack || err.stacktrace;
|
|
20
|
-
var stackMessage = (stack && stack.replace(/^Error\n/, '')) || '';
|
|
21
|
-
|
|
22
|
-
if (stackMessage) {
|
|
23
|
-
stackMessage = stackMessage.split('\n');
|
|
24
|
-
return stackMessage[printFrameOffset + 2];
|
|
25
|
-
}
|
|
26
|
-
return stackMessage;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function logger () {
|
|
30
|
-
if (typeof console !== 'undefined' && console.warn) {
|
|
31
|
-
Function.prototype.apply.call(console.warn, console, arguments);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {Object} DeprecationOptions
|
|
37
|
-
* @property {string} sinceVersion the version this has been deprecated since
|
|
38
|
-
* @property {string} removeInVersion the version this will be removed in
|
|
39
|
-
* @property {string} [alternativeName] the name of an alternative to use
|
|
40
|
-
* @property {string} [extraInfo] extra information to be printed at the end of the deprecation log
|
|
41
|
-
* @property {string} [extraObject] an extra object that will be printed at the end
|
|
42
|
-
* @property {string} [displayName] a human-readable name to show in the deprecation message. If not provided, it is inferred from the function or object being deprecated.
|
|
43
|
-
* @property {string} [deprecationType] type of the deprecation to append to the start of the deprecation message. e.g. JS or CSS
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Return a function that logs a deprecation warning to the console the first time it is called from a certain location.
|
|
48
|
-
* It will also print the stack frame of the calling function.
|
|
49
|
-
*
|
|
50
|
-
* @param {string} displayName the name of the thing being deprecated
|
|
51
|
-
* @param {DeprecationOptions} options
|
|
52
|
-
* @return {Function} that logs the warning and stack frame of the calling function. Takes in an optional parameter for the offset of
|
|
53
|
-
* the stack frame to print, the default is 0. For example, 0 will log it for the line of the calling function,
|
|
54
|
-
* -1 will print the location the logger was called from
|
|
55
|
-
*/
|
|
56
|
-
function getShowDeprecationMessage (displayName, options) {
|
|
57
|
-
// This can be used internally to pas in a showmessage fn
|
|
58
|
-
if (typeof displayName === 'function') {
|
|
59
|
-
return displayName;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var called = false;
|
|
63
|
-
options = options || {};
|
|
64
|
-
|
|
65
|
-
return function (printFrameOffset) {
|
|
66
|
-
var deprecatedLocation = getDeprecatedLocation(printFrameOffset ? printFrameOffset : 1) || '';
|
|
67
|
-
// Only log once if the stack frame doesn't exist to avoid spamming the console/test output
|
|
68
|
-
if (!called || deprecationCalls.indexOf(deprecatedLocation) === -1) {
|
|
69
|
-
deprecationCalls.push(deprecatedLocation);
|
|
70
|
-
|
|
71
|
-
called = true;
|
|
72
|
-
|
|
73
|
-
var deprecationType = (options.deprecationType + ' ') || '';
|
|
74
|
-
|
|
75
|
-
var message = 'DEPRECATED ' + deprecationType + '- ' + toSentenceCase(displayName) +
|
|
76
|
-
' has been deprecated' + (options.sinceVersion ? ' since ' + options.sinceVersion : '') +
|
|
77
|
-
' and will be removed in ' + (options.removeInVersion || 'a future release') + '.';
|
|
78
|
-
|
|
79
|
-
if (options.alternativeName) {
|
|
80
|
-
message += ' Use ' + options.alternativeName + ' instead. ';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (options.extraInfo) {
|
|
84
|
-
message += ' ' + options.extraInfo;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (deprecatedLocation === '') {
|
|
88
|
-
deprecatedLocation = ' \n ' + 'No stack trace of the deprecated usage is available in your current browser.';
|
|
89
|
-
} else {
|
|
90
|
-
deprecatedLocation = ' \n ' + deprecatedLocation;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (options.extraObject) {
|
|
94
|
-
message += '\n';
|
|
95
|
-
logger(message, options.extraObject, deprecatedLocation);
|
|
96
|
-
} else {
|
|
97
|
-
logger(message, deprecatedLocation);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function logCssDeprecation (selectorMap, newNode) {
|
|
104
|
-
var displayName = selectorMap.options.displayName;
|
|
105
|
-
displayName = displayName ? ' (' + displayName + ')' : '';
|
|
106
|
-
|
|
107
|
-
var options = $.extend({
|
|
108
|
-
deprecationType: 'CSS',
|
|
109
|
-
extraObject: newNode
|
|
110
|
-
}, selectorMap.options);
|
|
111
|
-
|
|
112
|
-
getShowDeprecationMessage('\'' + selectorMap.selector + '\' pattern' + displayName, options)();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Returns a wrapped version of the function that logs a deprecation warning when the function is used.
|
|
117
|
-
* @param {Function} fn the fn to wrap
|
|
118
|
-
* @param {string} displayName the name of the fn to be displayed in the message
|
|
119
|
-
* @param {DeprecationOptions} options
|
|
120
|
-
* @return {Function} wrapping the original function
|
|
121
|
-
*/
|
|
122
|
-
function deprecateFunctionExpression(fn, displayName, options) {
|
|
123
|
-
options = options || {};
|
|
124
|
-
options.deprecationType = options.deprecationType || 'JS';
|
|
125
|
-
|
|
126
|
-
var showDeprecationMessage = getShowDeprecationMessage(displayName || fn.name || 'this function', options);
|
|
127
|
-
return function () {
|
|
128
|
-
showDeprecationMessage();
|
|
129
|
-
return fn.apply(this, arguments);
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Returns a wrapped version of the constructor that logs a deprecation warning when the constructor is instantiated.
|
|
135
|
-
* @param {Function} constructorFn the constructor function to wrap
|
|
136
|
-
* @param {string} displayName the name of the fn to be displayed in the message
|
|
137
|
-
* @param {DeprecationOptions} options
|
|
138
|
-
* @return {Function} wrapping the original function
|
|
139
|
-
*/
|
|
140
|
-
function deprecateConstructor(constructorFn, displayName, options) {
|
|
141
|
-
options = options || {};
|
|
142
|
-
options.deprecationType = options.deprecationType || 'JS';
|
|
143
|
-
|
|
144
|
-
var deprecatedConstructor = deprecateFunctionExpression(constructorFn, displayName, options);
|
|
145
|
-
deprecatedConstructor.prototype = constructorFn.prototype;
|
|
146
|
-
$.extend(deprecatedConstructor, constructorFn); //copy static methods across;
|
|
147
|
-
|
|
148
|
-
return deprecatedConstructor;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
var supportsProperties = false;
|
|
153
|
-
try {
|
|
154
|
-
if (Object.defineProperty) {
|
|
155
|
-
Object.defineProperty({}, 'blam', {get: function () {}, set: function () {}});
|
|
156
|
-
supportsProperties = true;
|
|
157
|
-
}
|
|
158
|
-
// eslint-disable-next-line no-unused-vars
|
|
159
|
-
} catch (e) {
|
|
160
|
-
/* IE8 doesn't support on non-DOM elements */
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Wraps a "value" object property in a deprecation warning in browsers supporting Object.defineProperty
|
|
165
|
-
* @param {Object} obj the object containing the property
|
|
166
|
-
* @param {string} prop the name of the property to deprecate
|
|
167
|
-
* @param {DeprecationOptions} options
|
|
168
|
-
*/
|
|
169
|
-
function deprecateValueProperty(obj, prop, options) {
|
|
170
|
-
if (supportsProperties) {
|
|
171
|
-
var oldVal = obj[prop];
|
|
172
|
-
options = options || {};
|
|
173
|
-
options.deprecationType = options.deprecationType || 'JS';
|
|
174
|
-
|
|
175
|
-
var displayNameOrShowMessageFn = options.displayName || prop;
|
|
176
|
-
var showDeprecationMessage = getShowDeprecationMessage(displayNameOrShowMessageFn, options);
|
|
177
|
-
Object.defineProperty(obj, prop, {
|
|
178
|
-
get: function () {
|
|
179
|
-
showDeprecationMessage();
|
|
180
|
-
return oldVal;
|
|
181
|
-
},
|
|
182
|
-
set: function (val) {
|
|
183
|
-
oldVal = val;
|
|
184
|
-
showDeprecationMessage();
|
|
185
|
-
return val;
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Wraps an object property in a deprecation warning, if possible. functions will always log warnings, but other
|
|
193
|
-
* types of properties will only log in browsers supporting Object.defineProperty
|
|
194
|
-
* @param {Object} obj the object containing the property
|
|
195
|
-
* @param {string} prop the name of the property to deprecate
|
|
196
|
-
* @param {DeprecationOptions} options
|
|
197
|
-
*/
|
|
198
|
-
function deprecateObjectProperty(obj, prop, options) {
|
|
199
|
-
if (typeof obj[prop] === 'function') {
|
|
200
|
-
options = options || {};
|
|
201
|
-
options.deprecationType = options.deprecationType || 'JS';
|
|
202
|
-
|
|
203
|
-
var displayNameOrShowMessageFn = options.displayName || prop;
|
|
204
|
-
obj[prop] = deprecateFunctionExpression(obj[prop], displayNameOrShowMessageFn, options);
|
|
205
|
-
} else {
|
|
206
|
-
deprecateValueProperty(obj, prop, options);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Wraps all an objects properties in a deprecation warning, if possible. functions will always log warnings, but other
|
|
212
|
-
* types of properties will only log in browsers supporting Object.defineProperty
|
|
213
|
-
* @param {Object} obj the object to be wrapped
|
|
214
|
-
* @param {string} objDisplayPrefix the object's prefix to be used in logs
|
|
215
|
-
* @param {DeprecationOptions} options
|
|
216
|
-
* @param {string} options.alternativeNamePrefix a prefix for the alternative property name. Used to generate alternativeName per property.
|
|
217
|
-
*/
|
|
218
|
-
function deprecateAllProperties(obj, objDisplayPrefix, options) {
|
|
219
|
-
options = options || {};
|
|
220
|
-
for (var attr in obj) {
|
|
221
|
-
if (has.call(obj, attr)) {
|
|
222
|
-
options.deprecationType = options.deprecationType || 'JS';
|
|
223
|
-
options.displayName = objDisplayPrefix + attr;
|
|
224
|
-
options.alternativeName = options.alternativeNamePrefix && (options.alternativeNamePrefix + attr);
|
|
225
|
-
deprecateObjectProperty(obj, attr, $.extend({}, options));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function matchesSelector(el, selector) {
|
|
231
|
-
return (el.matches || el.msMatchesSelector || el.webkitMatchesSelector || el.mozMatchesSelector || el.oMatchesSelector).call(el, selector);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function handleAddingSelector(options) {
|
|
235
|
-
return function (selector) {
|
|
236
|
-
var selectorMap = {
|
|
237
|
-
selector: selector,
|
|
238
|
-
options: options || {}
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
// Search if matches have already been added
|
|
242
|
-
var matches = document.querySelectorAll(selector);
|
|
243
|
-
for (var i = 0; i < matches.length; i++) {
|
|
244
|
-
logCssDeprecation(selectorMap, matches[i]);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
observeFutureChange(selectorMap);
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Return a function that logs a deprecation warning to the console the first time it is called from a certain location.
|
|
253
|
-
* It will also print the stack frame of the calling function.
|
|
254
|
-
*
|
|
255
|
-
* @param {string|Array} selectors a selector or list of selectors that match deprecated markup
|
|
256
|
-
* @param {DeprecationOptions} options
|
|
257
|
-
*/
|
|
258
|
-
function deprecateCSS(selectors, options) {
|
|
259
|
-
if (typeof selectors === 'string') {
|
|
260
|
-
selectors = [selectors];
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
selectors.forEach(handleAddingSelector(options));
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function testAndHandleDeprecation(newNode) {
|
|
267
|
-
return function (selectorMap) {
|
|
268
|
-
if (matchesSelector(newNode, selectorMap.selector)) {
|
|
269
|
-
logCssDeprecation(selectorMap, newNode);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const deprecatedSelectorMap = [];
|
|
275
|
-
let observer;
|
|
276
|
-
|
|
277
|
-
function observeFutureChange(selectorMap) {
|
|
278
|
-
deprecatedSelectorMap.push(selectorMap);
|
|
279
|
-
|
|
280
|
-
// Lazily instantiate a mutation observer because they're expensive.
|
|
281
|
-
if (!observer) {
|
|
282
|
-
observer = new MutationObserver(function (mutations) {
|
|
283
|
-
mutations.forEach(function (mutation) {
|
|
284
|
-
// TODO - should this also look at class changes, if possible?
|
|
285
|
-
var addedNodes = mutation.addedNodes;
|
|
286
|
-
|
|
287
|
-
for (var i = 0; i < addedNodes.length; i++) {
|
|
288
|
-
var newNode = addedNodes[i];
|
|
289
|
-
if (newNode.nodeType === 1) {
|
|
290
|
-
deprecatedSelectorMap.forEach(testAndHandleDeprecation(newNode));
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
var config = {
|
|
297
|
-
childList: true,
|
|
298
|
-
subtree: true
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
observer.observe(document, config);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
globalize('deprecate', {
|
|
306
|
-
fn: deprecateFunctionExpression,
|
|
307
|
-
construct: deprecateConstructor,
|
|
308
|
-
css: deprecateCSS,
|
|
309
|
-
prop: deprecateObjectProperty,
|
|
310
|
-
obj: deprecateAllProperties,
|
|
311
|
-
propertyDeprecationSupported: supportsProperties,
|
|
312
|
-
getMessageLogger: getShowDeprecationMessage
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
export {
|
|
316
|
-
deprecateFunctionExpression as fn,
|
|
317
|
-
deprecateConstructor as construct,
|
|
318
|
-
deprecateCSS as css,
|
|
319
|
-
deprecateObjectProperty as prop,
|
|
320
|
-
deprecateAllProperties as obj,
|
|
321
|
-
supportsProperties as propertyDeprecationSupported,
|
|
322
|
-
getShowDeprecationMessage as getMessageLogger
|
|
323
|
-
};
|