openapi-explorer 2.1.656 → 2.1.659
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/browser/openapi-explorer.min.js +2 -2
- package/dist/es/components/api-request.js +58 -140
- package/dist/es/components/api-response.js +9 -34
- package/dist/es/components/json-tree.js +4 -18
- package/dist/es/components/request-form-table.js +13 -36
- package/dist/es/components/schema-table.js +28 -42
- package/dist/es/components/schema-tree.js +31 -61
- package/dist/es/components/syntax-highlighter.js +7 -26
- package/dist/es/components/tag-input.js +2 -14
- package/dist/es/openapi-explorer-oauth-handler.js +0 -2
- package/dist/es/openapi-explorer.js +62 -174
- package/dist/es/react.js +4 -4
- package/dist/es/styles/input-styles.js +1 -1
- package/dist/es/styles/schema-styles.js +1 -1
- package/dist/es/templates/advance-search-template.js +1 -5
- package/dist/es/templates/callback-template.js +2 -2
- package/dist/es/templates/code-samples-template.js +1 -3
- package/dist/es/templates/components-template.js +41 -4
- package/dist/es/templates/endpoint-template.js +6 -17
- package/dist/es/templates/expanded-endpoint-template.js +4 -7
- package/dist/es/templates/focused-endpoint-template.js +0 -10
- package/dist/es/templates/mainBodyTemplate.js +3 -2
- package/dist/es/templates/navbar-template.js +9 -12
- package/dist/es/templates/overview-template.js +1 -1
- package/dist/es/templates/security-scheme-template.js +12 -73
- package/dist/es/templates/server-template.js +1 -8
- package/dist/es/utils/color-utils.js +2 -21
- package/dist/es/utils/common-utils.js +3 -20
- package/dist/es/utils/schema-utils.js +35 -132
- package/dist/es/utils/spec-parser.js +35 -120
- package/dist/es/utils/theme.js +3 -6
- package/dist/es/utils/xml/xml.js +1 -40
- package/dist/lib/components/api-request.js +58 -157
- package/dist/lib/components/api-response.js +9 -54
- package/dist/lib/components/json-tree.js +4 -27
- package/dist/lib/components/request-form-table.js +14 -42
- package/dist/lib/components/schema-table.js +28 -52
- package/dist/lib/components/schema-tree.js +31 -72
- package/dist/lib/components/syntax-highlighter.js +6 -49
- package/dist/lib/components/tag-input.js +2 -18
- package/dist/lib/languages/en.js +2 -3
- package/dist/lib/languages/fr.js +2 -3
- package/dist/lib/languages/index.js +0 -6
- package/dist/lib/openapi-explorer-oauth-handler.js +0 -6
- package/dist/lib/openapi-explorer.js +61 -197
- package/dist/lib/react.js +4 -5
- package/dist/lib/styles/advanced-search-styles.js +1 -5
- package/dist/lib/styles/api-request-styles.js +1 -5
- package/dist/lib/styles/border-styles.js +1 -5
- package/dist/lib/styles/endpoint-styles.js +1 -5
- package/dist/lib/styles/flex-styles.js +1 -5
- package/dist/lib/styles/font-styles.js +1 -5
- package/dist/lib/styles/info-styles.js +1 -5
- package/dist/lib/styles/input-styles.js +1 -5
- package/dist/lib/styles/key-frame-styles.js +1 -5
- package/dist/lib/styles/nav-styles.js +1 -5
- package/dist/lib/styles/prism-styles.js +1 -5
- package/dist/lib/styles/schema-styles.js +1 -5
- package/dist/lib/styles/tab-styles.js +1 -5
- package/dist/lib/styles/table-styles.js +1 -5
- package/dist/lib/styles/tag-input-styles.js +1 -5
- package/dist/lib/templates/advance-search-template.js +0 -6
- package/dist/lib/templates/callback-template.js +1 -3
- package/dist/lib/templates/code-samples-template.js +0 -4
- package/dist/lib/templates/components-template.js +43 -9
- package/dist/lib/templates/endpoint-template.js +6 -29
- package/dist/lib/templates/expanded-endpoint-template.js +3 -17
- package/dist/lib/templates/focused-endpoint-template.js +0 -19
- package/dist/lib/templates/mainBodyTemplate.js +2 -13
- package/dist/lib/templates/navbar-template.js +9 -20
- package/dist/lib/templates/overview-template.js +0 -5
- package/dist/lib/templates/security-scheme-template.js +12 -79
- package/dist/lib/templates/server-template.js +1 -12
- package/dist/lib/utils/color-utils.js +4 -25
- package/dist/lib/utils/common-utils.js +3 -33
- package/dist/lib/utils/schema-utils.js +33 -141
- package/dist/lib/utils/spec-parser.js +35 -128
- package/dist/lib/utils/theme.js +3 -16
- package/dist/lib/utils/xml/xml.js +1 -42
- package/package.json +2 -2
@@ -2,24 +2,15 @@
|
|
2
2
|
|
3
3
|
exports.__esModule = true;
|
4
4
|
exports.default = void 0;
|
5
|
-
|
6
5
|
var _lit = require("lit");
|
7
|
-
|
8
6
|
var _marked = require("marked");
|
9
|
-
|
10
7
|
var _unsafeHtml = require("lit/directives/unsafe-html.js");
|
11
|
-
|
12
8
|
var _fontStyles = _interopRequireDefault(require("../styles/font-styles.js"));
|
13
|
-
|
14
9
|
var _schemaStyles = _interopRequireDefault(require("../styles/schema-styles.js"));
|
15
|
-
|
16
10
|
var _keyFrameStyles = _interopRequireDefault(require("../styles/key-frame-styles.js"));
|
17
|
-
|
18
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
-
|
20
12
|
const tablePadding = 16;
|
21
13
|
const firstColumnInitialPadding = tablePadding * 2;
|
22
|
-
|
23
14
|
class SchemaTable extends _lit.LitElement {
|
24
15
|
static get properties() {
|
25
16
|
return {
|
@@ -40,69 +31,63 @@ class SchemaTable extends _lit.LitElement {
|
|
40
31
|
}
|
41
32
|
};
|
42
33
|
}
|
43
|
-
|
44
34
|
connectedCallback() {
|
45
35
|
super.connectedCallback();
|
46
|
-
|
47
36
|
if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) {
|
48
37
|
this.schemaExpandLevel = 99999;
|
49
38
|
}
|
50
|
-
|
51
39
|
if (!this.schemaHideReadOnly || !'true false'.includes(this.schemaHideReadOnly)) {
|
52
40
|
this.schemaHideReadOnly = 'true';
|
53
41
|
}
|
54
|
-
|
55
42
|
if (!this.schemaHideWriteOnly || !'true false'.includes(this.schemaHideWriteOnly)) {
|
56
43
|
this.schemaHideWriteOnly = 'true';
|
57
44
|
}
|
58
45
|
}
|
46
|
+
|
59
47
|
/**
|
60
48
|
* @param {Map<string, object>} changedProperties Changed Properties
|
61
49
|
*/
|
62
|
-
|
63
|
-
|
64
50
|
update(changedProperties) {
|
65
51
|
if (changedProperties.has('data')) {
|
66
52
|
this.interactive = false;
|
67
53
|
}
|
68
|
-
|
69
54
|
super.update(changedProperties);
|
70
55
|
}
|
71
|
-
|
72
56
|
updated() {
|
73
57
|
this.interactive = true; // Note: interactive is not a reactive property
|
74
58
|
}
|
75
|
-
|
76
59
|
static finalizeStyles() {
|
77
60
|
return [_fontStyles.default, _keyFrameStyles.default, _schemaStyles.default, (0, _lit.css)`.table{font-size:var(--font-size-small);text-align:left;line-height:calc(var(--font-size-small) + 6px)}.table .tr{width:calc(100% - 5px);padding:0 0 0 5px;border-bottom:1px dotted var(--light-border-color)}.table .td{padding:4px 0}.table .key{width:240px}.requiredStar::after{content:'*';color:var(--red);font-size:larger}.key.deprecated .key-label{text-decoration:line-through}.table .key-type{white-space:normal;width:150px}.key-type{display:flex}.key-type>.attributes{margin:.0625rem 0 0 .25rem}.obj-toggle{display:inline-flex;margin-left:-.8rem;margin-right:.8rem;color:var(--primary-color);cursor:pointer;font-size:calc(var(--font-size-small) + 4px);font-family:var(--font-mono);background-clip:border-box}.tr+.object-body{overflow:hidden}.table:not(.interactive) .object-body{animation-duration:0s!important}.tr:not(.collapsed)+.object-body{animation:linear .2s expand-height}.tr.collapsed+.object-body{animation:linear .2s collapse-height;max-height:0}.obj-toggle{transition:transform .1s ease}.tr.collapsed .obj-toggle{transform:rotate(-90deg)}`];
|
78
61
|
}
|
79
|
-
/* eslint-disable indent */
|
80
|
-
|
81
62
|
|
63
|
+
/* eslint-disable indent */
|
82
64
|
render() {
|
83
|
-
|
65
|
+
var _this$data, _this$data2;
|
66
|
+
const displayLine = [(_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data['::title'], (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2['::description']].filter(d => d).join(' - ');
|
67
|
+
return (0, _lit.html)` ${displayLine ? (0, _lit.html)`<span class="m-markdown" style="padding-bottom:8px"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(displayLine))}</span>` : ''} <div class="table ${this.interactive ? 'interactive' : ''}"> <div style="border:1px solid var(--light-border-color)"> <div style="display:flex;background-color:var(--bg2);padding:8px 4px;border-bottom:1px solid var(--light-border-color)"> <div class="key" style="font-family:var(--font-regular);font-weight:700;color:var(--fg);padding-left:${firstColumnInitialPadding}px"> Field </div> <div class="key-type" style="font-family:var(--font-regular);font-weight:700;color:var(--fg)"> Type </div> <div class="key-descr" style="font-family:var(--font-regular);font-weight:700;color:var(--fg)"> Description </div> </div> ${this.data ? (0, _lit.html)`${this.generateTree(this.data['::type'] === 'array' ? this.data['::props'] : this.data, this.data['::type'])}` : ''} </div> </div> `;
|
68
|
+
}
|
69
|
+
scrollToSchemaComponentByName(componentName) {
|
70
|
+
this.dispatchEvent(new CustomEvent('scrollToSchemaComponentByName', {
|
71
|
+
bubbles: true,
|
72
|
+
composed: true,
|
73
|
+
detail: componentName
|
74
|
+
}));
|
84
75
|
}
|
85
|
-
|
86
76
|
generateTree(data, dataType = 'object', key = '', title = '', description = '', schemaLevel = 0, indentLevel = 0) {
|
87
77
|
var _keyLabel;
|
88
|
-
|
89
78
|
const newSchemaLevel = data['::type'] && data['::type'].startsWith('xxx-of') ? schemaLevel : schemaLevel + 1;
|
90
|
-
const newIndentLevel = dataType === 'xxx-of-option' || data['::type'] === 'xxx-of-option' || key.startsWith('::OPTION') ? indentLevel : indentLevel + 1;
|
91
|
-
|
79
|
+
const newIndentLevel = dataType === 'xxx-of-option' || data['::type'] === 'xxx-of-option' || key.startsWith('::OPTION') ? indentLevel : indentLevel + 1;
|
80
|
+
// 16px space indentation at each level, start the first one at 32px to align with the field hr key row object
|
92
81
|
const leftPadding = Math.max(firstColumnInitialPadding, tablePadding * newIndentLevel);
|
93
|
-
|
94
82
|
if (!data) {
|
95
83
|
return (0, _lit.html)`<div class="null" style="display:inline">null</div>`;
|
96
84
|
}
|
97
|
-
|
98
85
|
if (Object.keys(data).length === 0) {
|
99
86
|
return (0, _lit.html)`<span class="td key object" style="padding-left:${leftPadding}px">${key}</span>`;
|
100
87
|
}
|
101
|
-
|
102
88
|
let keyLabel = '';
|
103
89
|
let keyDescr = '';
|
104
90
|
let isOneOfLabel = false;
|
105
|
-
|
106
91
|
if (key.startsWith('::ONE~OF') || key.startsWith('::ANY~OF')) {
|
107
92
|
keyLabel = key.replace('::', '').replace('~', ' ');
|
108
93
|
isOneOfLabel = true;
|
@@ -113,43 +98,41 @@ class SchemaTable extends _lit.LitElement {
|
|
113
98
|
} else {
|
114
99
|
keyLabel = key;
|
115
100
|
}
|
116
|
-
|
117
101
|
let detailObjType = '';
|
118
|
-
|
102
|
+
let displaySchemaLink = false;
|
119
103
|
if ((data['::type'] || '').includes('xxx-of')) {
|
120
104
|
detailObjType = '';
|
121
|
-
} else if (data['::type'] === 'object') {
|
122
|
-
if (dataType === 'array') {
|
123
|
-
detailObjType = `[${keyLabel.replace(/(s|Collection|List)[*]?$/i, '')}]`; // Array of Object
|
124
|
-
} else {
|
125
|
-
detailObjType = 'object'; // Object
|
126
|
-
}
|
127
105
|
} else if (data['::type'] === 'array') {
|
128
106
|
if (dataType === 'array') {
|
129
107
|
detailObjType = 'array of array'; // Array of array
|
130
108
|
} else {
|
131
109
|
detailObjType = 'array';
|
132
110
|
}
|
111
|
+
} else if (data['::type']) {
|
112
|
+
displaySchemaLink = data['::link'];
|
113
|
+
if (dataType === 'array') {
|
114
|
+
detailObjType = data['::link'] || keyLabel.replace(/(s|Collection|List)[*]?$/i, ''); // Array of Object
|
115
|
+
} else {
|
116
|
+
detailObjType = data['::link'] || data['::type'];
|
117
|
+
}
|
133
118
|
}
|
134
|
-
|
135
119
|
if (typeof data === 'object') {
|
136
120
|
var _data$Metadata, _data$Metadata$constr;
|
137
|
-
|
138
121
|
const flags = data['::flags'] || {};
|
139
|
-
|
140
122
|
if (flags['🆁'] && this.schemaHideReadOnly === 'true') {
|
141
123
|
return undefined;
|
142
124
|
}
|
143
|
-
|
144
125
|
if (flags['🆆'] && this.schemaHideWriteOnly === 'true') {
|
145
126
|
return undefined;
|
146
127
|
}
|
147
|
-
|
148
128
|
const displayLine = [title && `**${title}${description ? ':' : ''}**`, description].filter(v => v).join(' ');
|
149
|
-
return (0, _lit.html)` ${newSchemaLevel >= 0 && key ? (0, _lit.html)` <div class="tr ${newSchemaLevel <= this.schemaExpandLevel ? '' : 'collapsed'} ${data['::type']}" data-obj="${keyLabel}"> <div class="td no-select key ${data['::deprecated'] ? 'deprecated' : ''}" style="padding-left:${leftPadding}px;cursor:pointer" @click="${e => this.toggleObjectExpand(e, keyLabel)}"> <div style="display:flex;align-items:center"> ${keyLabel || keyDescr ? (0, _lit.html)`<div class="obj-toggle" data-obj="${keyLabel}">▾</div>` : ''} ${data['::type'] === 'xxx-of-option' || data['::type'] === 'xxx-of-array' || key.startsWith('::OPTION') ? (0, _lit.html)`<span class="xxx-of-key" style="margin-left:-6px">${keyLabel}</span><span class="${isOneOfLabel ? 'xxx-of-key' : 'xxx-of-descr'}">${keyDescr}</span>` : keyLabel.endsWith('*') ? (0, _lit.html)`<span class="key-label requiredStar" style="display:inline-block;margin-left:-6px" title="Required"> ${keyLabel.substring(0, keyLabel.length - 1)}</span>` : (0, _lit.html)`<span class="key-label" style="display:inline-block;margin-left:-6px">${keyLabel === '::props' ? '' : keyLabel}</span>`} </div> </div> <div class="td key-type"> <div>${(data['::type'] || '').includes('xxx-of') ? '' : detailObjType}</div
|
150
|
-
|
151
|
-
|
129
|
+
return (0, _lit.html)` ${newSchemaLevel >= 0 && key ? (0, _lit.html)` <div class="tr ${newSchemaLevel <= this.schemaExpandLevel ? '' : 'collapsed'} ${data['::type']}" data-obj="${keyLabel}"> <div class="td no-select key ${data['::deprecated'] ? 'deprecated' : ''}" style="padding-left:${leftPadding}px;cursor:pointer" @click="${e => this.toggleObjectExpand(e, keyLabel)}"> <div style="display:flex;align-items:center"> ${keyLabel || keyDescr ? (0, _lit.html)`<div class="obj-toggle" data-obj="${keyLabel}">▾</div>` : ''} ${data['::type'] === 'xxx-of-option' || data['::type'] === 'xxx-of-array' || key.startsWith('::OPTION') ? (0, _lit.html)`<span class="xxx-of-key" style="margin-left:-6px">${keyLabel}</span><span class="${isOneOfLabel ? 'xxx-of-key' : 'xxx-of-descr'}">${keyDescr}</span>` : keyLabel.endsWith('*') ? (0, _lit.html)`<span class="key-label requiredStar" style="display:inline-block;margin-left:-6px" title="Required"> ${keyLabel.substring(0, keyLabel.length - 1)}</span>` : (0, _lit.html)`<span class="key-label" style="display:inline-block;margin-left:-6px">${keyLabel === '::props' ? '' : keyLabel}</span>`} </div> </div> <div class="td key-type"> ${displaySchemaLink ? (0, _lit.html)`<div class="schema-link" style="overflow:hidden;text-overflow:ellipsis" @click="${() => this.scrollToSchemaComponentByName(displaySchemaLink)}"> ${dataType === 'array' ? '[' : ''}<span style="color:var(--primary)">${detailObjType}</span>${dataType === 'array' ? ']' : ''} </div>` : (0, _lit.html)`<div>${(data['::type'] || '').includes('xxx-of') ? '' : detailObjType}</div>`} <div class="attributes" title="${flags['🆁'] && 'Read only attribute' || flags['🆆'] && 'Write only attribute' || ''}">${flags['🆁'] || flags['🆆'] || ''}</div> </div> <div class="td key-descr"> <span class="m-markdown-small">${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(displayLine))}</span> ${(_data$Metadata = data['::metadata']) !== null && _data$Metadata !== void 0 && (_data$Metadata$constr = _data$Metadata.constraints) !== null && _data$Metadata$constr !== void 0 && _data$Metadata$constr.length ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Constraints: </span>${data['::metadata'].constraints.join(', ')}</div><br>` : ''} </div> </div>` : (0, _lit.html)` ${data['::type'] === 'array' && dataType === 'array' ? (0, _lit.html)`<div class="tr"> <div class="td"> ${dataType} </div> </div>` : ''} `} <div class="object-body"> ${Array.isArray(data) && data[0] ? (0, _lit.html)`${this.generateTree(data[0], 'xxx-of-option', '::ARRAY~OF', data[0]['::title'], data[0]['::description'], newSchemaLevel, newIndentLevel)}` : (0, _lit.html)` ${Object.keys(data).map(dataKey => {
|
130
|
+
var _data$dataKey;
|
131
|
+
return !['::metadata', '::title', '::description', '::type', '::link', '::props', '::deprecated', '::array-type', '::dataTypeLabel', '::flags'].includes(dataKey) || (_data$dataKey = data[dataKey]) !== null && _data$dataKey !== void 0 && _data$dataKey['::type'] && !data[dataKey]['::type'].includes('xxx-of') ? (0, _lit.html)`${this.generateTree(data[dataKey]['::type'] === 'array' ? data[dataKey]['::props'] : data[dataKey], data[dataKey]['::type'], dataKey, data[dataKey]['::title'], data[dataKey]['::description'], newSchemaLevel, newIndentLevel)}` : '';
|
132
|
+
})}`} <div> </div></div>`;
|
133
|
+
}
|
152
134
|
|
135
|
+
// For Primitive Data types
|
153
136
|
const {
|
154
137
|
type,
|
155
138
|
cssType,
|
@@ -164,29 +147,22 @@ class SchemaTable extends _lit.LitElement {
|
|
164
147
|
schemaTitle,
|
165
148
|
deprecated
|
166
149
|
} = JSON.parse(data);
|
167
|
-
|
168
150
|
if (readOrWriteOnly === '🆁' && this.schemaHideReadOnly === 'true') {
|
169
151
|
return undefined;
|
170
152
|
}
|
171
|
-
|
172
153
|
if (readOrWriteOnly === '🆆' && this.schemaHideWriteOnly === 'true') {
|
173
154
|
return undefined;
|
174
155
|
}
|
175
|
-
|
176
156
|
return (0, _lit.html)` <div class="tr"> <div class="td key ${deprecated ? 'deprecated' : ''}" style="padding-left:${leftPadding}px"> ${(_keyLabel = keyLabel) !== null && _keyLabel !== void 0 && _keyLabel.endsWith('*') ? (0, _lit.html)`<span class="key-label requiredStar" title="Required">${keyLabel.substring(0, keyLabel.length - 1)}</span>` : key.startsWith('::OPTION') ? (0, _lit.html)`<span class="xxx-of-key">${keyLabel}</span><span class="xxx-of-descr">${keyDescr}</span>` : (0, _lit.html)`${keyLabel ? (0, _lit.html)`<span class="key-label"> ${keyLabel}</span>` : (0, _lit.html)`<span class="xxx-of-descr">${schemaTitle}</span>`}`} </div> <div class="td key-type"> <div>${dataType === 'array' ? '[' : ''}<span class="${cssType}">${format || type}</span>${dataType === 'array' ? ']' : ''}</div> <div class="attributes ${cssType}" style="font-family:var(--font-mono)" title="${readOrWriteOnly === '🆁' && 'Read only attribute' || readOrWriteOnly === '🆆' && 'Write only attribute' || ''}">${readOrWriteOnly}</div> </div> <div class="td key-descr"> <span class="m-markdown-small" style="vertical-align:middle"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(`${`${schemaTitle || title ? `**${schemaTitle || title}${schemaDescription || description ? ':' : ''}**` : ''} ${schemaDescription || description}` || ''}`))} </span> ${constraints.length ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Constraints: </span>${constraints.join(', ')}</div><br>` : ''} ${defaultValue ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Default: </span>${defaultValue}</div><br>` : ''} ${allowedValues ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Allowed: </span>${allowedValues}</div><br>` : ''} ${pattern ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Pattern: </span>${pattern}</div><br>` : ''} ${example ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Example: </span>${example}</div><br>` : ''} </div> </div> `;
|
177
157
|
}
|
178
158
|
/* eslint-enable indent */
|
179
159
|
|
180
|
-
|
181
160
|
toggleObjectExpand(e) {
|
182
161
|
const rowEl = e.target.closest('.tr');
|
183
162
|
rowEl.classList.toggle('collapsed');
|
184
163
|
}
|
185
|
-
|
186
164
|
}
|
187
|
-
|
188
165
|
exports.default = SchemaTable;
|
189
|
-
|
190
166
|
if (!customElements.get('openapi-explorer')) {
|
191
167
|
customElements.define('schema-table', SchemaTable);
|
192
168
|
}
|
@@ -2,25 +2,15 @@
|
|
2
2
|
|
3
3
|
exports.__esModule = true;
|
4
4
|
exports.default = void 0;
|
5
|
-
|
6
5
|
var _lit = require("lit");
|
7
|
-
|
8
6
|
var _marked = require("marked");
|
9
|
-
|
10
7
|
var _unsafeHtml = require("lit/directives/unsafe-html.js");
|
11
|
-
|
12
8
|
var _index = require("../languages/index.js");
|
13
|
-
|
14
9
|
var _fontStyles = _interopRequireDefault(require("../styles/font-styles.js"));
|
15
|
-
|
16
10
|
var _schemaStyles = _interopRequireDefault(require("../styles/schema-styles.js"));
|
17
|
-
|
18
11
|
var _borderStyles = _interopRequireDefault(require("../styles/border-styles.js"));
|
19
|
-
|
20
12
|
var _keyFrameStyles = _interopRequireDefault(require("../styles/key-frame-styles.js"));
|
21
|
-
|
22
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
|
-
|
24
14
|
class SchemaTree extends _lit.LitElement {
|
25
15
|
static get properties() {
|
26
16
|
return {
|
@@ -44,68 +34,55 @@ class SchemaTree extends _lit.LitElement {
|
|
44
34
|
}
|
45
35
|
};
|
46
36
|
}
|
47
|
-
|
48
37
|
connectedCallback() {
|
49
38
|
super.connectedCallback();
|
50
|
-
|
51
39
|
if (!this.schemaExpandLevel || this.schemaExpandLevel < 1) {
|
52
40
|
this.schemaExpandLevel = 99999;
|
53
41
|
}
|
54
|
-
|
55
42
|
this.schemaDescriptionExpanded = true;
|
56
|
-
|
57
43
|
if (!this.schemaHideReadOnly || !'true false'.includes(this.schemaHideReadOnly)) {
|
58
44
|
this.schemaHideReadOnly = 'true';
|
59
45
|
}
|
60
|
-
|
61
46
|
if (!this.schemaHideWriteOnly || !'true false'.includes(this.schemaHideWriteOnly)) {
|
62
47
|
this.schemaHideWriteOnly = 'true';
|
63
48
|
}
|
64
49
|
}
|
50
|
+
|
65
51
|
/**
|
66
52
|
* @param {Map<string, object>} changedProperties Changed Properties
|
67
53
|
*/
|
68
|
-
|
69
|
-
|
70
54
|
update(changedProperties) {
|
71
55
|
if (changedProperties.has('data')) {
|
72
56
|
this.interactive = false;
|
73
57
|
}
|
74
|
-
|
75
58
|
super.update(changedProperties);
|
76
59
|
}
|
77
|
-
|
78
60
|
updated() {
|
79
61
|
this.interactive = true; // Note: interactive is not a reactive property
|
80
62
|
}
|
81
|
-
|
82
63
|
static finalizeStyles() {
|
83
64
|
return [_fontStyles.default, _schemaStyles.default, _borderStyles.default, _keyFrameStyles.default, (0, _lit.css)`.tree{min-height:30px;background:var(--bg2);padding:12px;font-size:var(--font-size-small);text-align:left;line-height:calc(var(--font-size-small) + 6px)}.tree .key{max-width:300px}.requiredStar::after{content:'*';color:var(--red);font-size:larger}.key.deprecated .key-label{text-decoration:line-through}.open-bracket{display:inline-block;padding:0 20px 0 0;cursor:pointer;border:1px solid transparent;border-radius:3px}.collapsed .open-bracket{padding-right:0}.td.key>.open-bracket:first-child{margin-left:-2px}.open-bracket:hover{color:var(--primary-color);background-color:var(--hover-color);border:1px solid var(--border-color)}.close-bracket{display:inline-block;font-family:var(--font-mono)}.inside-bracket-wrapper{overflow:hidden}.tree:not(.interactive) .inside-bracket-wrapper{animation-duration:0s!important}.tr:not(.collapsed)+.inside-bracket-wrapper{animation:linear .2s expand-height}.tr.collapsed+.inside-bracket-wrapper{animation:linear .2s collapse-height;max-height:0}.inside-bracket.array,.inside-bracket.object{border-left:1px dotted var(--border-color)}.inside-bracket.xxx-of.option{border-left:1px solid transparent}`];
|
84
65
|
}
|
85
|
-
/* eslint-disable indent */
|
86
|
-
|
87
66
|
|
67
|
+
/* eslint-disable indent */
|
88
68
|
render() {
|
89
|
-
|
69
|
+
var _this$data, _this$data2;
|
70
|
+
const displayLine = [(_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data['::title'], (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2['::description']].filter(d => d).join(' - ');
|
71
|
+
return (0, _lit.html)` <div class="tree ${this.interactive ? 'interactive' : ''}"> <div class="toolbar"> ${displayLine ? (0, _lit.html)`<span class="m-markdown" style="margin-block-start:0"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(displayLine))}</span>` : (0, _lit.html)`<div> </div>`} <div class="toolbar-item" @click="${() => this.toggleSchemaDescription()}"> ${this.schemaDescriptionExpanded ? (0, _index.getI18nText)('schemas.collapse-desc') : (0, _index.getI18nText)('schemas.expand-desc')} </div> </div> ${this.data ? (0, _lit.html)`${this.generateTree(this.data['::type'] === 'array' ? this.data['::props'] : this.data, this.data['::type'], this.data['::array-type'] || '')}` : (0, _lit.html)`<span class="mono-font" style="color:var(--red)"> ${(0, _index.getI18nText)('schemas.schema-missing')} </span>`} </div> `;
|
90
72
|
}
|
91
|
-
|
92
73
|
toggleSchemaDescription() {
|
93
74
|
this.schemaDescriptionExpanded = !this.schemaDescriptionExpanded;
|
94
75
|
this.requestUpdate();
|
95
76
|
}
|
96
|
-
|
97
77
|
generateTree(data, dataType = 'object', arrayType = '', flags = {}, key = '', title = '', description = '', schemaLevel = 0, indentLevel = 0) {
|
98
78
|
if (!data) {
|
99
|
-
return (0, _lit.html)`<div class="null" style="display:inline"> <span class="key-label xxx-of-key"> ${key.replace('::OPTION~', '')}</span> ${dataType === 'array'
|
79
|
+
return (0, _lit.html)`<div class="null" style="display:inline"> <span class="key-label xxx-of-key"> ${key.replace('::OPTION~', '')}</span> ${dataType === 'array' && (0, _lit.html)`<span class="mono-font"> [ ] </span>` || dataType === 'object' && (0, _lit.html)`<span class="mono-font"> { } </span>` || (0, _lit.html)`<span class="mono-font"> ${dataType} </span>`} </div>`;
|
100
80
|
}
|
101
|
-
|
102
81
|
if (Object.keys(data).length === 0) {
|
103
82
|
return (0, _lit.html)`<span class="key object">${key}:{ }</span>`;
|
104
83
|
}
|
105
|
-
|
106
84
|
let keyLabel = '';
|
107
85
|
let keyDescr = '';
|
108
|
-
|
109
86
|
if (key.startsWith('::ONE~OF') || key.startsWith('::ANY~OF')) {
|
110
87
|
keyLabel = key.replace('::', '').replace('~', ' ');
|
111
88
|
} else if (key.startsWith('::OPTION')) {
|
@@ -115,43 +92,21 @@ class SchemaTree extends _lit.LitElement {
|
|
115
92
|
} else {
|
116
93
|
keyLabel = key;
|
117
94
|
}
|
118
|
-
|
119
|
-
|
120
|
-
|
95
|
+
const leftPadding = 16;
|
96
|
+
// Min-width used for model keys: `td key `
|
121
97
|
const minFieldColWidth = 300 - indentLevel * leftPadding;
|
122
98
|
let openBracket = '';
|
123
99
|
let closeBracket = '';
|
124
100
|
const newSchemaLevel = data['::type'] && data['::type'].startsWith('xxx-of') ? schemaLevel : schemaLevel + 1;
|
125
101
|
const newIndentLevel = dataType === 'xxx-of-option' || data['::type'] === 'xxx-of-option' ? indentLevel : indentLevel + 1;
|
126
|
-
|
127
|
-
if (data['::type'] === 'object') {
|
128
|
-
if (dataType === 'array') {
|
129
|
-
if (schemaLevel < this.schemaExpandLevel) {
|
130
|
-
openBracket = (0, _lit.html)`<span class="open-bracket array-of-object" @click="${this.toggleObjectExpand}">[{</span>`;
|
131
|
-
} else {
|
132
|
-
openBracket = (0, _lit.html)`<span class="open-bracket array-of-object" @click="${this.toggleObjectExpand}">[{...}]</span>`;
|
133
|
-
}
|
134
|
-
|
135
|
-
closeBracket = '}]';
|
136
|
-
} else {
|
137
|
-
if (schemaLevel < this.schemaExpandLevel) {
|
138
|
-
openBracket = (0, _lit.html)`<span class="open-bracket object" @click="${this.toggleObjectExpand}">{</span>`;
|
139
|
-
} else {
|
140
|
-
openBracket = (0, _lit.html)`<span class="open-bracket object" @click="${this.toggleObjectExpand}">{...}</span>`;
|
141
|
-
}
|
142
|
-
|
143
|
-
closeBracket = '}';
|
144
|
-
}
|
145
|
-
} else if (data['::type'] === 'array') {
|
102
|
+
if (data['::type'] === 'array') {
|
146
103
|
if (dataType === 'array') {
|
147
104
|
const arrType = arrayType !== 'object' ? arrayType : '';
|
148
|
-
|
149
105
|
if (schemaLevel < this.schemaExpandLevel) {
|
150
106
|
openBracket = (0, _lit.html)`<span class="open-bracket array-of-array" data-array-type="${arrType}" @click="${this.toggleObjectExpand}">[[ ${arrType} </span>`;
|
151
107
|
} else {
|
152
108
|
openBracket = (0, _lit.html)`<span class="open-bracket array-of-array" data-array-type="${arrType}" @click="${this.toggleObjectExpand}">[[...]]</span>`;
|
153
109
|
}
|
154
|
-
|
155
110
|
closeBracket = ']]';
|
156
111
|
} else {
|
157
112
|
if (schemaLevel < this.schemaExpandLevel) {
|
@@ -159,7 +114,6 @@ class SchemaTree extends _lit.LitElement {
|
|
159
114
|
} else {
|
160
115
|
openBracket = (0, _lit.html)`<span class="open-bracket array" @click="${this.toggleObjectExpand}">[...]</span>`;
|
161
116
|
}
|
162
|
-
|
163
117
|
closeBracket = ']';
|
164
118
|
}
|
165
119
|
} else if (data['::type'] === 'xxx-of' && dataType === 'array') {
|
@@ -168,26 +122,40 @@ class SchemaTree extends _lit.LitElement {
|
|
168
122
|
} else {
|
169
123
|
openBracket = (0, _lit.html)`<span class="open-bracket array" @click="${this.toggleObjectExpand}">[...]</span>`;
|
170
124
|
}
|
171
|
-
|
172
125
|
closeBracket = ']';
|
126
|
+
} else if (data['::type']) {
|
127
|
+
if (dataType === 'array') {
|
128
|
+
if (schemaLevel < this.schemaExpandLevel) {
|
129
|
+
openBracket = (0, _lit.html)`<span class="open-bracket array-of-object" @click="${this.toggleObjectExpand}">[{</span>`;
|
130
|
+
} else {
|
131
|
+
openBracket = (0, _lit.html)`<span class="open-bracket array-of-object" @click="${this.toggleObjectExpand}">[{...}]</span>`;
|
132
|
+
}
|
133
|
+
closeBracket = '}]';
|
134
|
+
} else {
|
135
|
+
if (schemaLevel < this.schemaExpandLevel) {
|
136
|
+
openBracket = (0, _lit.html)`<span class="open-bracket object" @click="${this.toggleObjectExpand}">{</span>`;
|
137
|
+
} else {
|
138
|
+
openBracket = (0, _lit.html)`<span class="open-bracket object" @click="${this.toggleObjectExpand}">{...}</span>`;
|
139
|
+
}
|
140
|
+
closeBracket = '}';
|
141
|
+
}
|
173
142
|
}
|
174
|
-
|
175
143
|
if (typeof data === 'object') {
|
176
144
|
var _data$Metadata, _data$Metadata$constr;
|
177
|
-
|
178
145
|
if (flags['🆁'] && this.schemaHideReadOnly === 'true') {
|
179
146
|
return undefined;
|
180
147
|
}
|
181
|
-
|
182
148
|
if (flags['🆆'] && this.schemaHideWriteOnly === 'true') {
|
183
149
|
return undefined;
|
184
150
|
}
|
185
|
-
|
186
151
|
const displayLine = [flags['🆁'] || flags['🆆'], title && `**${title}${description ? ':' : ''}**`, description].filter(v => v).join(' ');
|
187
|
-
return (0, _lit.html)` <div class="tr ${schemaLevel < this.schemaExpandLevel || data['::type'] && data['::type'].startsWith('xxx-of') ? '' : 'collapsed'} ${data['::type'] || 'no-type-info'}"> <div class="td key ${data['::deprecated'] ? 'deprecated' : ''}" style="min-width:${minFieldColWidth}px"> ${data['::type'] === 'xxx-of-option' || data['::type'] === 'xxx-of-array' || key.startsWith('::OPTION') ? (0, _lit.html)`<span class="key-label xxx-of-key">${keyLabel}</span><span class="xxx-of-descr">${keyDescr}</span>` : keyLabel === '::props' || keyLabel === '::ARRAY~OF' ? '' : schemaLevel > 0 ? (0, _lit.html)`<span class="key-label"> ${keyLabel.replace(/\*$/, '')}${keyLabel.endsWith('*') ? (0, _lit.html)`<span class="requiredStar" title="Required"></span>` : ''}: </span>` : ''} ${openBracket} </div> <div class="td key-descr"> <span class="m-markdown-small" style="vertical-align:middle" title="${flags['🆁'] && 'Read only attribute' || flags['🆆'] && 'Write only attribute' || ''}"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(displayLine))} </span> ${this.schemaDescriptionExpanded ? (0, _lit.html)` ${(_data$Metadata = data['::metadata']) !== null && _data$Metadata !== void 0 && (_data$Metadata$constr = _data$Metadata.constraints) !== null && _data$Metadata$constr !== void 0 && _data$Metadata$constr.length ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Constraints: </span>${data['::metadata'].constraints.join(', ')}</div><br>` : ''}` : ''} </div> </div> <div class="inside-bracket-wrapper"> <div class="inside-bracket ${data['::type'] || 'no-type-info'}" style="padding-left:${data['::type'] === 'xxx-of-option' || data['::type'] === 'xxx-of-array' ? 0 : leftPadding}px"> ${Array.isArray(data) && data[0] ? (0, _lit.html)`${this.generateTree(data[0], 'xxx-of-option', '', data[0]['::flags'] || {}, '::ARRAY~OF', data[0]['::title'], data[0]['::description'], newSchemaLevel, newIndentLevel)}` : (0, _lit.html)` ${Object.keys(data).map(dataKey =>
|
188
|
-
|
189
|
-
|
152
|
+
return (0, _lit.html)` <div class="tr ${schemaLevel < this.schemaExpandLevel || data['::type'] && data['::type'].startsWith('xxx-of') ? '' : 'collapsed'} ${data['::type'] || 'no-type-info'}"> <div class="td key ${data['::deprecated'] ? 'deprecated' : ''}" style="min-width:${minFieldColWidth}px"> ${data['::type'] === 'xxx-of-option' || data['::type'] === 'xxx-of-array' || key.startsWith('::OPTION') ? (0, _lit.html)`<span class="key-label xxx-of-key">${keyLabel}</span><span class="xxx-of-descr">${keyDescr}</span>` : keyLabel === '::props' || keyLabel === '::ARRAY~OF' ? '' : schemaLevel > 0 ? (0, _lit.html)`<span class="key-label"> ${keyLabel.replace(/\*$/, '')}${keyLabel.endsWith('*') ? (0, _lit.html)`<span class="requiredStar" title="Required"></span>` : ''}: </span>` : ''} ${openBracket} </div> <div class="td key-descr"> <span class="m-markdown-small" style="vertical-align:middle" title="${flags['🆁'] && 'Read only attribute' || flags['🆆'] && 'Write only attribute' || ''}"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(displayLine))} </span> ${this.schemaDescriptionExpanded ? (0, _lit.html)` ${(_data$Metadata = data['::metadata']) !== null && _data$Metadata !== void 0 && (_data$Metadata$constr = _data$Metadata.constraints) !== null && _data$Metadata$constr !== void 0 && _data$Metadata$constr.length ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Constraints: </span>${data['::metadata'].constraints.join(', ')}</div><br>` : ''}` : ''} </div> </div> <div class="inside-bracket-wrapper"> <div class="inside-bracket ${data['::type'] || 'no-type-info'}" style="padding-left:${data['::type'] === 'xxx-of-option' || data['::type'] === 'xxx-of-array' ? 0 : leftPadding}px"> ${Array.isArray(data) && data[0] ? (0, _lit.html)`${this.generateTree(data[0], 'xxx-of-option', '', data[0]['::flags'] || {}, '::ARRAY~OF', data[0]['::title'], data[0]['::description'], newSchemaLevel, newIndentLevel)}` : (0, _lit.html)` ${Object.keys(data).map(dataKey => {
|
153
|
+
var _data$dataKey;
|
154
|
+
return !['::metadata', '::title', '::description', '::type', '::link', '::props', '::deprecated', '::array-type', '::dataTypeLabel', '::flags'].includes(dataKey) || (_data$dataKey = data[dataKey]) !== null && _data$dataKey !== void 0 && _data$dataKey['::type'] && !data[dataKey]['::type'].includes('xxx-of') ? (0, _lit.html)`${this.generateTree(data[dataKey]['::type'] === 'array' ? data[dataKey]['::props'] : data[dataKey], data[dataKey]['::type'], data[dataKey]['::array-type'] || '', data[dataKey]['::flags'], dataKey, data[dataKey]['::title'], data[dataKey]['::description'], newSchemaLevel, newIndentLevel)}` : '';
|
155
|
+
})}`} </div> ${data['::type'] && data['::type'].includes('xxx-of') ? '' : (0, _lit.html)`<div class="close-bracket"> ${closeBracket} </div>`} </div> `;
|
156
|
+
}
|
190
157
|
|
158
|
+
// For Primitive Data types
|
191
159
|
const {
|
192
160
|
type,
|
193
161
|
cssType,
|
@@ -202,39 +170,30 @@ class SchemaTree extends _lit.LitElement {
|
|
202
170
|
schemaTitle,
|
203
171
|
deprecated
|
204
172
|
} = JSON.parse(data);
|
205
|
-
|
206
173
|
if (readOrWriteOnly === '🆁' && this.schemaHideReadOnly === 'true') {
|
207
174
|
return undefined;
|
208
175
|
}
|
209
|
-
|
210
176
|
if (readOrWriteOnly === '🆆' && this.schemaHideWriteOnly === 'true') {
|
211
177
|
return undefined;
|
212
178
|
}
|
213
|
-
|
214
179
|
const titleString = schemaTitle || title;
|
215
180
|
const descriptionString = schemaDescription || description;
|
216
181
|
return (0, _lit.html)` <div class="tr"> <div class="td key ${deprecated ? 'deprecated' : ''}" style="min-width:${minFieldColWidth}px"> ${keyLabel.endsWith('*') ? (0, _lit.html)`<span class="key-label requiredStar" title="Required">${keyLabel.substring(0, keyLabel.length - 1)}</span>:` : key.startsWith('::OPTION') ? (0, _lit.html)`<span class="key-label xxx-of-key">${keyLabel}</span><span class="xxx-of-descr">${keyDescr}</span>` : schemaLevel > 0 ? (0, _lit.html)`<span class="key-label">${keyLabel}:</span>` : ''} <span>${dataType === 'array' ? '[' : ''}<span class="${cssType}">${format || type}</span>${dataType === 'array' ? ']' : ''}</span> </div> <div class="td key-descr"> <span class="m-markdown-small" style="vertical-align:middle" title="${readOrWriteOnly === '🆁' && 'Read only attribute' || readOrWriteOnly === '🆆' && 'Write only attribute' || ''}"> ${(0, _unsafeHtml.unsafeHTML)((0, _marked.marked)(`${readOrWriteOnly && `${readOrWriteOnly} ` || ''}${`${titleString ? `**${titleString}${descriptionString ? ':' : ''}**` : ''} ${descriptionString}` || ''}`))} </span> ${this.schemaDescriptionExpanded ? (0, _lit.html)` ${constraints.length ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Constraints: </span>${constraints.join(', ')}</div><br>` : ''} ${defaultValue ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Default: </span>${defaultValue}</div><br>` : ''} ${allowedValues ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Allowed: </span>${allowedValues}</div><br>` : ''} ${pattern ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Pattern: </span>${pattern}</div><br>` : ''} ${example ? (0, _lit.html)`<div style="display:inline-block;line-break:anywhere;margin-right:8px"><span class="bold-text">Example: </span>${example}</div><br>` : ''}` : ''} </div> </div> `;
|
217
182
|
}
|
218
183
|
/* eslint-enable indent */
|
219
184
|
|
220
|
-
|
221
185
|
toggleObjectExpand(e) {
|
222
186
|
const rowEl = e.target.closest('.tr');
|
223
187
|
rowEl.classList.toggle('collapsed');
|
224
|
-
|
225
188
|
if (rowEl.classList.contains('collapsed')) {
|
226
189
|
e.target.innerHTML = e.target.classList.contains('array-of-object') ? '[{...}]' : e.target.classList.contains('array-of-array') ? '[[...]]' : e.target.classList.contains('array') ? '[...]' : '{...}';
|
227
190
|
} else {
|
228
191
|
e.target.innerHTML = e.target.classList.contains('array-of-object') ? '[{' : e.target.classList.contains('array-of-array') ? '[[' : e.target.classList.contains('object') ? '{' : '[';
|
229
192
|
}
|
230
|
-
|
231
193
|
this.requestUpdate();
|
232
194
|
}
|
233
|
-
|
234
195
|
}
|
235
|
-
|
236
196
|
exports.default = SchemaTree;
|
237
|
-
|
238
197
|
if (!customElements.get('openapi-explorer')) {
|
239
198
|
customElements.define('schema-tree', SchemaTree);
|
240
199
|
}
|
@@ -1,53 +1,29 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
3
|
var _lit = require("lit");
|
4
|
-
|
5
4
|
var _unsafeHtml = require("lit/directives/unsafe-html.js");
|
6
|
-
|
7
5
|
var _marked = require("marked");
|
8
|
-
|
9
6
|
var _prismjs = _interopRequireDefault(require("prismjs"));
|
10
|
-
|
11
7
|
require("./json-tree.js");
|
12
|
-
|
13
8
|
require("prismjs/components/prism-markup-templating.js");
|
14
|
-
|
15
9
|
require("prismjs/components/prism-css.js");
|
16
|
-
|
17
10
|
require("prismjs/components/prism-yaml.js");
|
18
|
-
|
19
11
|
require("prismjs/components/prism-go.js");
|
20
|
-
|
21
12
|
require("prismjs/components/prism-ruby.js");
|
22
|
-
|
23
13
|
require("prismjs/components/prism-java.js");
|
24
|
-
|
25
14
|
require("prismjs/components/prism-json.js");
|
26
|
-
|
27
15
|
require("prismjs/components/prism-bash.js");
|
28
|
-
|
29
16
|
require("prismjs/components/prism-python.js");
|
30
|
-
|
31
17
|
require("prismjs/components/prism-http.js");
|
32
|
-
|
33
18
|
require("prismjs/components/prism-csharp.js");
|
34
|
-
|
35
19
|
require("prismjs/components/prism-rust.js");
|
36
|
-
|
37
20
|
require("prismjs/components/prism-php.js");
|
38
|
-
|
39
21
|
var _prismStyles = _interopRequireDefault(require("../styles/prism-styles.js"));
|
40
|
-
|
41
22
|
var _fontStyles = _interopRequireDefault(require("../styles/font-styles.js"));
|
42
|
-
|
43
23
|
var _inputStyles = _interopRequireDefault(require("../styles/input-styles.js"));
|
44
|
-
|
45
24
|
var _index = require("../languages/index.js");
|
46
|
-
|
47
25
|
var _commonUtils = require("../utils/common-utils.js");
|
48
|
-
|
49
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
50
|
-
|
51
27
|
/**
|
52
28
|
* Mapping mime-type => prism language
|
53
29
|
*/
|
@@ -58,10 +34,10 @@ const LANGUAGES = [{
|
|
58
34
|
pattern: /xml/,
|
59
35
|
language: 'html'
|
60
36
|
}];
|
37
|
+
|
61
38
|
/**
|
62
39
|
* Syntax Highlighter component.
|
63
40
|
*/
|
64
|
-
|
65
41
|
class SyntaxHighlighter extends _lit.LitElement {
|
66
42
|
static get properties() {
|
67
43
|
return {
|
@@ -78,96 +54,77 @@ class SyntaxHighlighter extends _lit.LitElement {
|
|
78
54
|
}
|
79
55
|
};
|
80
56
|
}
|
81
|
-
|
82
57
|
static finalizeStyles() {
|
83
58
|
return [_prismStyles.default, _fontStyles.default, _inputStyles.default, (0, _lit.css)`:host{font-weight:400}div{position:relative;display:flex;flex-direction:column}.toolbar-copy-btn{position:absolute;top:0;right:0;margin-right:8px}.toolbar-copy-btn+pre{white-space:pre;max-height:400px;overflow:auto;display:flex;padding-right:70px}`];
|
84
59
|
}
|
60
|
+
|
85
61
|
/**
|
86
62
|
* Returns the prism language to use based on language/content type
|
87
63
|
* @returns {string} The language to use
|
88
64
|
*/
|
89
|
-
|
90
|
-
|
91
65
|
detectLanguage() {
|
92
66
|
if (this.language) {
|
93
67
|
var _this$language;
|
94
|
-
|
95
68
|
return (_this$language = this.language) === null || _this$language === void 0 ? void 0 : _this$language.toLowerCase();
|
96
69
|
}
|
97
|
-
|
98
70
|
if (this.mimeType) {
|
99
71
|
var _this$mimeType, _LANGUAGES$find;
|
100
|
-
|
101
72
|
const lcMimeType = (_this$mimeType = this.mimeType) === null || _this$mimeType === void 0 ? void 0 : _this$mimeType.toLowerCase();
|
102
73
|
return (_LANGUAGES$find = LANGUAGES.find(def => def.pattern.test(lcMimeType))) === null || _LANGUAGES$find === void 0 ? void 0 : _LANGUAGES$find.language;
|
103
74
|
}
|
104
|
-
|
105
75
|
return null;
|
106
76
|
}
|
107
|
-
|
108
77
|
render() {
|
109
78
|
return this.renderCopyWrapper(this.renderHighlight());
|
110
79
|
}
|
80
|
+
|
111
81
|
/**
|
112
82
|
* Render the highlighted content.
|
113
83
|
* @returns Highlighter
|
114
84
|
*/
|
115
|
-
|
116
|
-
|
117
85
|
renderHighlight() {
|
118
86
|
var _this$content;
|
119
|
-
|
120
87
|
const lang = this.detectLanguage();
|
121
88
|
const grammar = _prismjs.default.languages[lang];
|
122
|
-
|
123
89
|
if (typeof this.content !== 'string') {
|
124
90
|
return (0, _lit.html)`<json-tree .data="${this.content}">`;
|
125
91
|
}
|
126
|
-
|
127
92
|
const stringContent = ((_this$content = this.content) === null || _this$content === void 0 ? void 0 : _this$content.toString()) || '';
|
128
93
|
const increasedSpaceContent = lang !== 'python' && lang !== 'yaml' && lang !== 'toml' ? stringContent.split('\n').map(line => line.replace(/^\s{2}/g, ' ')).join('\n') : stringContent;
|
129
94
|
return grammar ? (0, _lit.html)`<pre><code>${(0, _unsafeHtml.unsafeHTML)(_prismjs.default.highlight(increasedSpaceContent, grammar, lang))}</code></pre>` : (0, _lit.html)`<pre>${increasedSpaceContent}</pre>`;
|
130
95
|
}
|
96
|
+
|
131
97
|
/**
|
132
98
|
* Render a copy-to-clipboard button.
|
133
99
|
* @param {*} content Content
|
134
100
|
* @returns Content
|
135
101
|
*/
|
136
|
-
|
137
|
-
|
138
102
|
renderCopyWrapper(content) {
|
139
103
|
return (0, _lit.html)`<div> <button class="m-btn outline-primary toolbar-copy-btn" @click="${this.copyToClipboard}" part="btn btn-fill btn-copy">${(0, _index.getI18nText)('operations.copy')}</button> ${content} </div>`;
|
140
104
|
}
|
105
|
+
|
141
106
|
/**
|
142
107
|
* Copy to clipboard.
|
143
108
|
* @param {Event} e Event
|
144
109
|
*/
|
145
|
-
|
146
|
-
|
147
110
|
copyToClipboard(e) {
|
148
111
|
var _this$content2;
|
149
|
-
|
150
112
|
const data = this.detectLanguage() === 'json' && typeof this.content !== 'string' ? JSON.stringify(this.content, null, 2) : (_this$content2 = this.content) === null || _this$content2 === void 0 ? void 0 : _this$content2.toString();
|
151
113
|
(0, _commonUtils.copyToClipboard)(data, e);
|
152
114
|
}
|
153
|
-
|
154
115
|
}
|
116
|
+
|
155
117
|
/*
|
156
118
|
* Configure marked globally.
|
157
119
|
*/
|
158
|
-
|
159
|
-
|
160
120
|
_marked.marked.setOptions({
|
161
121
|
highlight(code, lang) {
|
162
122
|
if (_prismjs.default.languages[lang]) {
|
163
123
|
return _prismjs.default.highlight(code, _prismjs.default.languages[lang], lang);
|
164
124
|
}
|
165
|
-
|
166
125
|
return code;
|
167
126
|
}
|
168
|
-
|
169
127
|
});
|
170
|
-
|
171
128
|
if (!customElements.get('openapi-explorer')) {
|
172
129
|
customElements.define('syntax-highlighter', SyntaxHighlighter);
|
173
130
|
}
|