-
Notifications
You must be signed in to change notification settings - Fork 16
/
iron-doc-api.js
185 lines (156 loc) · 6.43 KB
/
iron-doc-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at
http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
part of the polymer project is also subject to an additional IP rights grant
found at http://polymer.github.io/PATENTS.txt
*/
import '@polymer/polymer/polymer-legacy.js';
import './iron-doc-function.js';
import './iron-doc-hide-bar.js';
import './iron-doc-property.js';
import './iron-doc-viewer-styles.js';
import {Polymer} from '@polymer/polymer/lib/legacy/polymer-fn.js';
import {html} from '@polymer/polymer/lib/utils/html-tag.js';
import {IronDocViewerBehavior} from './iron-doc-viewer-behavior.js';
Polymer({
_template: html`
<style include="iron-doc-viewer-styles">
.checkbox {
margin-left: 16px;
cursor: pointer;
display: flex;
}
.checkbox input {
width: 18px;
height: 18px;
}
</style>
<section anchor-id$="[[fragmentPrefix]]properties" hidden$="[[!_anyVisible(descriptor.properties)]]">
<h2>
<a href$="#[[fragmentPrefix]]properties" class="deeplink">Properties</a>
</h2>
<template is="dom-repeat" items="[[_public(descriptor.properties)]]" sort="_compareDescriptors">
<iron-doc-property descriptor="[[item]]" anchor-id="[[fragmentPrefix]]property-[[item.name]]">
</iron-doc-property>
</template>
<template is="dom-if" if="[[_protectedCount(descriptor.properties)]]">
<template is="dom-if" if="[[_showProtectedProperties]]">
<template is="dom-repeat" items="[[_protected(descriptor.properties)]]" sort="_compareDescriptors">
<iron-doc-property descriptor="[[item]]" anchor-id="[[fragmentPrefix]]property-[[item.name]]">
</iron-doc-property>
</template>
</template>
<iron-doc-hide-bar visible="{{_showProtectedProperties}}">
[[_protectedCount(descriptor.properties)]] protected properties
</iron-doc-hide-bar>
</template>
</section>
<section id="methods" anchor-id$="[[fragmentPrefix]]methods" hidden$="[[!_hasMethods]]">
<h2>
<a href$="#[[fragmentPrefix]]methods" class="deeplink">Methods</a>
</h2>
<template is="dom-repeat" items="[[_public(descriptor.staticMethods)]]" sort="_compareDescriptors">
<iron-doc-function descriptor="[[item]]" static anchor-id="[[fragmentPrefix]]staticmethod-[[item.name]]">
</iron-doc-function>
</template>
<template is="dom-repeat" items="[[_public(descriptor.methods)]]" sort="_compareDescriptors">
<iron-doc-function descriptor="[[item]]" anchor-id="[[fragmentPrefix]]method-[[item.name]]">
</iron-doc-function>
</template>
<template is="dom-if" if="[[_protectedCount(descriptor.methods, _staticMethods)]]">
<template is="dom-if" if="[[_showProtectedMethods]]">
<template is="dom-repeat" items="[[_protected(descriptor.staticMethods)]]" sort="_compareDescriptors">
<iron-doc-function descriptor="[[item]]" static anchor-id="[[fragmentPrefix]]method-[[item.name]]">
</iron-doc-function>
</template>
<template is="dom-repeat" items="[[_protected(descriptor.methods)]]" sort="_compareDescriptors">
<iron-doc-function descriptor="[[item]]" anchor-id="[[fragmentPrefix]]method-[[item.name]]">
</iron-doc-function>
</template>
</template>
<iron-doc-hide-bar visible="{{_showProtectedMethods}}">
[[_protectedCount(descriptor.methods, _staticMethods)]]
protected methods
</iron-doc-hide-bar>
</template>
</section>
<section anchor-id$="[[fragmentPrefix]]events" hidden$="[[!_anyVisible(descriptor.events)]]">
<h2>
<a href$="#[[fragmentPrefix]]events" class="deeplink">Events</a>
</h2>
<template is="dom-repeat" items="[[_public(descriptor.events)]]" sort="_compareDescriptors">
<iron-doc-property descriptor="[[item]]" anchor-id="[[fragmentPrefix]]event-[[item.name]]">
</iron-doc-property>
</template>
<template is="dom-if" if="[[_protectedCount(descriptor.events)]]">
<template is="dom-if" if="[[_showProtectedEvents]]">
<template is="dom-repeat" items="[[_protected(descriptor.events)]]" sort="_compareDescriptors">
<iron-doc-property descriptor="[[item]]" anchor-id="[[fragmentPrefix]]event-[[item.name]]">
</iron-doc-property>
</template>
</template>
<iron-doc-hide-bar visible="{{_showProtectedEvents}}">
[[_protectedCount(descriptor.events)]] protected events
</iron-doc-hide-bar>
</template>
</section>
`,
is: 'iron-doc-api',
behaviors: [IronDocViewerBehavior],
properties: {
descriptor: Object,
_showProtectedProperties: Boolean,
_showProtectedMethods: Boolean,
_showProtectedEvents: Boolean,
_staticMethods: {computed: '_computeStaticMethods(descriptor)'},
_hasMethods: {computed: '_computeHasMethods(descriptor)'},
},
_anyVisible: function(items) {
for (var i = 0; i < (items || []).length; i++) {
var item = items[i];
if (!item.privacy || item.privacy === 'public' ||
item.privacy === 'protected') {
return true;
}
};
return false;
},
_public: function(items) {
var filtered = [];
for (var i = 0; i < (items || []).length; i++) {
var item = items[i];
if (!item.privacy || item.privacy === 'public') {
filtered.push(item);
}
}
return filtered;
},
_protected: function(items) {
var filtered = [];
for (var i = 0; i < (items || []).length; i++) {
var item = items[i];
if (item.privacy === 'protected') {
filtered.push(item);
}
}
return filtered;
},
_protectedCount: function(/** arguments */) {
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum += this._protected(arguments[i]).length
}
return sum;
},
_computeStaticMethods: function(descriptor) {
return descriptor.staticMethods || [];
},
_computeHasMethods: function(descriptor) {
return (descriptor.methods && descriptor.methods.length > 0) ||
(descriptor.staticMethods && descriptor.staticMethods.length > 0);
}
});