@kestra-io/ui-libs 0.0.47 → 0.0.49

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kestra-io/ui-libs",
3
- "version": "v0.0.47",
3
+ "version": "v0.0.49",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src",
@@ -27,7 +27,6 @@
27
27
  "moment": "^2.30.1",
28
28
  "vue": "^3.4.0",
29
29
  "vue-material-design-icons": "^5.3.0",
30
- "vue3-popper": "^1.5.0",
31
30
  "vuex": "^4.1.0",
32
31
  "yaml": "^2.4.1"
33
32
  },
@@ -37,6 +36,7 @@
37
36
  "eslint": "^8.57.0",
38
37
  "eslint-plugin-vue": "^9.23.0",
39
38
  "sass": "^1.71.1",
39
+ "shiki": "^1.1.7",
40
40
  "vite": "^5.1.6",
41
41
  "vite-plugin-static-copy": "^1.0.1"
42
42
  }
@@ -19,7 +19,11 @@ import TaskIcon from "./misc/TaskIcon.vue";
19
19
  // buttons
20
20
  import AddTaskButton from "./buttons/AddTaskButton.vue";
21
21
 
22
+ // plugins
23
+ import SchemaToHtml from "./plugins/SchemaToHtml.vue";
24
+
22
25
  export {ClusterNode, DotNode, EdgeNode, TaskNode, TriggerNode, BasicNode, CollapsedClusterNode, DependenciesNode};
23
26
  export {Topology}
24
27
  export {ExecutionInformations, State, TaskIcon};
25
- export {AddTaskButton};
28
+ export {AddTaskButton};
29
+ export {SchemaToHtml};
@@ -9,7 +9,12 @@
9
9
  </span>
10
10
  </template>
11
11
  <script>
12
- import {Tooltip} from "bootstrap";
12
+ // conditional import is required for website not to crash due to
13
+ // bootstrap launching some init upon import that is incompatible with SSR
14
+ let bootstrap;
15
+ if (document) {
16
+ bootstrap = import("bootstrap");
17
+ }
13
18
 
14
19
  export default {
15
20
  props: {
@@ -22,18 +27,20 @@
22
27
  default: "top"
23
28
  },
24
29
  },
25
- mounted() {
26
- new Tooltip(this.$refs.tooltip, {
27
- trigger: "hover",
28
- html: true,
29
- placement: this.placement,
30
- title: this.$refs.tooltipContent.innerHTML,
31
- customClass: "tooltip-custom"
32
- })
30
+ async mounted() {
31
+ if (document) {
32
+ new (await bootstrap).Tooltip(this.$refs.tooltip, {
33
+ trigger: "hover",
34
+ html: true,
35
+ placement: this.placement,
36
+ title: this.$refs.tooltipContent.innerHTML,
37
+ customClass: "tooltip-custom"
38
+ })
39
+ }
33
40
  },
34
- beforeUnmount() {
41
+ async beforeUnmount() {
35
42
  if (this.$refs.tooltip) {
36
- const tooltip = Tooltip.getInstance(this.$refs.tooltip);
43
+ const tooltip = (await bootstrap).Tooltip.getInstance(this.$refs.tooltip);
37
44
  if (tooltip) {
38
45
  tooltip.dispose();
39
46
  }
@@ -0,0 +1,168 @@
1
+ <template>
2
+ <div class="code-block mb-3" @mouseover="hoverCode" @mouseleave="isHoveringCode = false">
3
+ <div class="language" v-if="language">
4
+ {{ language }}
5
+ </div>
6
+ <template v-if="isHoveringCode">
7
+ <button ref="copyButton" class="copy">
8
+ <component
9
+ :is="copyIcon"
10
+ @click="copyToClipboard"
11
+ />
12
+ </button>
13
+ <div ref="copyTooltip" v-if="!!copyIconResetTimer" id="copied-tooltip" role="tooltip">
14
+ Copied!
15
+ <div id="arrow" data-popper-arrow />
16
+ </div>
17
+ </template>
18
+ <div v-html="codeData" />
19
+ </div>
20
+ </template>
21
+
22
+ <script>
23
+ import {createPopper} from "@popperjs/core";
24
+ import {codeToHtml} from "shiki";
25
+ import ContentCopy from "vue-material-design-icons/ContentCopy.vue";
26
+ import Check from "vue-material-design-icons/Check.vue";
27
+ import {defineComponent, nextTick, shallowRef} from "vue";
28
+
29
+ export default defineComponent({
30
+ props: {
31
+ code: {
32
+ type: String,
33
+ default: ""
34
+ },
35
+ language: {
36
+ type: String,
37
+ default: null
38
+ },
39
+ filename: {
40
+ type: String,
41
+ default: null
42
+ },
43
+ highlights: {
44
+ type: Array,
45
+ default: () => []
46
+ },
47
+ meta: {
48
+ type: String,
49
+ default: null
50
+ }
51
+ },
52
+ data() {
53
+ return {
54
+ icons: shallowRef({
55
+ ContentCopy: shallowRef(ContentCopy),
56
+ Check: shallowRef(Check)
57
+ }),
58
+ copyIcon: undefined,
59
+ copyIconResetTimer: undefined,
60
+ isHoveringCode: false,
61
+ codeData: null,
62
+ }
63
+ },
64
+ async created() {
65
+ this.copyIcon = this.icons.ContentCopy;
66
+ this.codeData = await codeToHtml(this.code, {
67
+ lang: this.language,
68
+ theme: "github-dark",
69
+ });
70
+ },
71
+ methods: {
72
+ hoverCode(){
73
+ this.isHoveringCode = true;
74
+ if(this.copyIconResetTimer) {
75
+ nextTick(() => {
76
+ createPopper(this.$refs.copyButton, this.$refs.copyTooltip, {
77
+ placement: "left",
78
+ });
79
+ });
80
+ }
81
+ },
82
+ copyToClipboard() {
83
+ clearTimeout(this.copyIconResetTimer);
84
+
85
+ navigator.clipboard.writeText(this.code.trimEnd())
86
+
87
+ this.copyIcon = this.icons.Check;
88
+
89
+ this.copyIconResetTimer = setTimeout(() => {
90
+ this.copyIcon = this.icons.ContentCopy;
91
+ this.copyIconResetTimer = undefined;
92
+ }, 2000)
93
+ },
94
+ },
95
+ });
96
+ </script>
97
+
98
+ <style lang="scss" scoped>
99
+ .code-block {
100
+ background-color: #161617;
101
+ border: 1px solid #252526;
102
+ padding: 1.25rem 1.5rem;
103
+ border-radius: var(--bs-border-radius-lg);
104
+ color: var(--bs-white);
105
+ position: relative;
106
+
107
+ .language {
108
+ position: absolute;
109
+ right: 0.35rem;
110
+ top: 0.25rem;
111
+ color: var(--bs-gray-600);
112
+ font-size: 0.75rem;
113
+ }
114
+
115
+ :deep(pre) {
116
+ margin-bottom: 0;
117
+ }
118
+
119
+ :deep(.github-dark) {
120
+ background-color: transparent !important;
121
+ code {
122
+ display: flex;
123
+ flex-direction: column;
124
+ }
125
+ }
126
+
127
+ .copy {
128
+ position: absolute;
129
+ right: 0;
130
+ bottom: 0.1rem;
131
+ color: #7081b9;
132
+ border: none;
133
+ background: none;
134
+ }
135
+
136
+ #copied-tooltip {
137
+ border-radius: .25rem;
138
+ background: #8997bd;
139
+ padding: 4px 8px;
140
+ font-size: 0.75rem;
141
+ margin-right: 0.2rem !important;
142
+
143
+ #arrow,
144
+ #arrow::before {
145
+ position: absolute;
146
+ width: 8px;
147
+ height: 8px;
148
+ background: inherit;
149
+ }
150
+
151
+ #arrow {
152
+ visibility: hidden;
153
+ right: -4px;
154
+ }
155
+
156
+ #arrow::before {
157
+ visibility: visible;
158
+ content: '';
159
+ transform: rotate(45deg);
160
+ }
161
+ }
162
+ }
163
+
164
+ :deep(pre code .line) {
165
+ display: block;
166
+ min-height: 1rem;
167
+ }
168
+ </style>
@@ -0,0 +1,334 @@
1
+ <template>
2
+ <div class="bd-markdown">
3
+ <div class="doc-alert alert alert-warning" role="alert" v-if="page.deprecated">
4
+ <p>⚠ Deprecated</p>
5
+ </div>
6
+
7
+ <SchemaToCode language="yaml" :code="`type: &quot;${getPageName()}&quot;`" />
8
+ <p v-if="page.title">
9
+ <span style="font-size:1.5em;" v-html="replaceText(page.title)" />
10
+ </p>
11
+ <slot v-if="page.description" :content="page.description" name="markdown" />
12
+ <h2 id="examples" v-if="page.body.children['examples']">
13
+ <a href="#examples">Examples</a>
14
+ </h2>
15
+ <template
16
+ v-for="(example, index) in page?.body?.children?.['examples'] ?? []"
17
+ :key="index"
18
+ >
19
+ <slot v-if="example.title" :content="example.title" name="markdown" />
20
+ <SchemaToCode :language="example.lang" :code="generateExampleCode(example)" v-if="example.code" />
21
+ </template>
22
+ <template v-for="(pageBlock, key) in page?.body?.children ?? []" :key="key">
23
+ <template v-if="key !== 'examples'">
24
+ <h2 :id="key">
25
+ <a :href="`#${key}`">{{ capitalizeFirstLetter(key) }}</a>
26
+ </h2>
27
+ <template v-if="key !== 'definitions'">
28
+ <template v-for="(property, propertyKey) in sortSchemaByRequired(pageBlock)" :key="propertyKey">
29
+ <h3 :id="property.name || propertyKey">
30
+ <a :href="`#${property.name || propertyKey}`">
31
+ <code>{{ property.name || propertyKey }}</code>
32
+ </a>
33
+ </h3>
34
+ <div
35
+ class="doc-alert alert alert-warning"
36
+ role="alert"
37
+ v-if="property['$deprecated']"
38
+ >
39
+ <p>⚠ Deprecated</p>
40
+ </div>
41
+ <ul>
42
+ <li>
43
+ <strong>Type: </strong>
44
+ <mark
45
+ class="type-mark type-mark-default"
46
+ v-if="property.type || property['$ref']"
47
+ >
48
+ {{ property.type || property['$ref']?.split('.').reverse()[0] }}
49
+ </mark>
50
+ <ul v-else-if="property.anyOf">
51
+ <li v-for="(anyOf, index) in property.anyOf" :key="index">
52
+ <mark class="type-mark type-mark-default">{{ anyOf.type }}</mark>
53
+ </li>
54
+ </ul>
55
+ </li>
56
+ <li v-if="property.items">
57
+ <strong>SubType: </strong>
58
+ <a
59
+ aria-current="page"
60
+ v-if="property.items['$ref']"
61
+ :href="generateTaskHref(property.items['$ref'])"
62
+ class="router-link-active router-link-exact-active"
63
+ >
64
+ <mark class="type-mark type-mark-default">
65
+ {{ property.items['$ref']?.split('.').reverse()[0] ||
66
+ property.items.type ||'String' }}
67
+ </mark>
68
+ </a>
69
+ <mark v-else class="type-mark type-mark-default">
70
+ {{ property.items['$ref']?.split('.').reverse()[0] ||
71
+ property.items.type ||'String' }}
72
+ </mark>
73
+ </li>
74
+ <li v-if="property['$dynamic'] !== undefined">
75
+ <strong>Dynamic: </strong>{{
76
+ property['$dynamic'] === true ? "✔️" :
77
+ (property['$dynamic'] === false ? "❌" : "❓") }}
78
+ </li>
79
+ <li v-if="property['$required'] !== undefined">
80
+ <strong>Required: </strong> {{
81
+ property['$required'] === true ? "✔️" :
82
+ (property['$required'] === false ? "❌" : "❓") }}
83
+ </li>
84
+ <li v-if="property.default !== undefined">
85
+ <strong>Default: </strong>
86
+ <code>{{ property.default }}</code>
87
+ </li>
88
+ <li v-if="property.format">
89
+ <strong>Format: </strong>
90
+ <code> {{ property.format }} </code>
91
+ </li>
92
+ <li v-if="property.minItems">
93
+ <strong>Min items: </strong>
94
+ <code> {{ property.minItems }} </code>
95
+ </li>
96
+ <li v-if="property.minLength">
97
+ <strong>Min length: </strong>
98
+ <code>{{ property.minLength }}</code>
99
+ </li>
100
+ <li v-if="property.enum">
101
+ <strong>Possible Values:</strong>
102
+ <ul>
103
+ <li v-for="(possibleValue, index) in property.enum" :key="index">
104
+ <code data-v-c4861ad0="" class="">{{ possibleValue }}</code>
105
+ </li>
106
+ </ul>
107
+ </li>
108
+ </ul>
109
+
110
+ <slot v-if="property.title" :content="property.title" name="markdown" />
111
+ <blockquote class="blockquote">
112
+ <slot v-if="property.description" :content="property.description" name="markdown" />
113
+ </blockquote>
114
+ </template>
115
+ </template>
116
+ <template v-else-if="pageBlock">
117
+ <template
118
+ v-for="(item, childrenBlockKey) in pageBlock"
119
+ :key="childrenBlockKey"
120
+ >
121
+ <h3 :id="childrenBlockKey">
122
+ <a :href="`#${childrenBlockKey}`">
123
+ <code>{{ childrenBlockKey }}</code>
124
+ </a>
125
+ </h3>
126
+ <h4
127
+ id="properties-1"
128
+ v-if="item.properties"
129
+ >
130
+ <a href="#properties-1">Properties</a>
131
+ </h4>
132
+ <template
133
+ v-for="(definition, propertyKey) in item.properties ?? []"
134
+ :key="propertyKey"
135
+ >
136
+ <h5 :id="definition.name || propertyKey">
137
+ <a :href="`#${definition.name || propertyKey}`">
138
+ <code>{{ definition.name || propertyKey }}</code>
139
+ </a>
140
+ </h5>
141
+ <ul>
142
+ <li>
143
+ <strong>Type: </strong>
144
+ <mark class="type-mark type-mark-default">
145
+ {{ definition.type ||
146
+ definition['$ref']?.split('.').reverse()[0] }}
147
+ </mark>
148
+ </li>
149
+ <li v-if="definition.items">
150
+ <strong>SubType: </strong>
151
+ <a
152
+ aria-current="page"
153
+ v-if="definition.items['$ref']"
154
+ :href="generateTaskHref(definition.items['$ref'])"
155
+ class="router-link-active router-link-exact-active"
156
+ >
157
+ <mark class="type-mark type-mark-default">
158
+ {{ definition.items?.type || 'Task' }}
159
+ </mark>
160
+ </a>
161
+ <mark v-else class="type-mark type-mark-default">
162
+ {{ definition.items?.type || 'Task' }}
163
+ </mark>
164
+ </li>
165
+ <li v-if="definition['$dynamic'] !== undefined">
166
+ <strong>Dynamic: </strong>
167
+ {{ definition['$dynamic'] === true ? "✔️" :
168
+ (definition['$dynamic'] === false ? "❌" : "❓") }}
169
+ </li>
170
+ <li v-if="definition['$required'] !== undefined">
171
+ <strong>Required: </strong>
172
+ {{
173
+ definition['$required'] === true ? "✔️" :
174
+ (definition['$required'] === false ? "❌" : "❓") }}
175
+ </li>
176
+ <li v-if="definition.default !== undefined">
177
+ <strong>Default: </strong>
178
+ <code>{{ definition.default }}</code>
179
+ </li>
180
+ <li v-if="definition.format">
181
+ <strong>Format: </strong>
182
+ <code>{{ definition.format }}</code>
183
+ </li>
184
+ <li v-if="definition.minItems">
185
+ <strong>Min items: </strong>
186
+ <code>{{ definition.minItems }}</code>
187
+ </li>
188
+ </ul>
189
+ <p>
190
+ <strong v-html="replaceText(definition.title)" />
191
+ </p>
192
+ <blockquote class="blockquote">
193
+ <p v-html="replaceText(definition.description)" />
194
+ </blockquote>
195
+ </template>
196
+ </template>
197
+ </template>
198
+ </template>
199
+ </template>
200
+ </div>
201
+ </template>
202
+
203
+ <script setup>
204
+ import SchemaToCode from "./SchemaToCode.vue";
205
+ import {computed} from "vue";
206
+
207
+ const props = defineProps({
208
+ page: {
209
+ type: Object,
210
+ required: true,
211
+ },
212
+ getPageName: {
213
+ type: Function,
214
+ required: true,
215
+ }
216
+ });
217
+
218
+
219
+ function capitalizeFirstLetter(str) {
220
+ return str.charAt(0).toUpperCase() + str.slice(1);
221
+ }
222
+
223
+ const replaceText = (str) => {
224
+ str = str?.split("```")[0]?.replace(/`([^`]*)`/g, "<code>$1</code>");
225
+ str = str?.replace(
226
+ /\[(.*?)\]\((.*?)\)/g,
227
+ (match, text, url) => {
228
+ if (text && url ) {
229
+ return `<a href="${url}" rel="nofollow" target="_blank">${text}</a>`;
230
+ } else {
231
+ return match;
232
+ }
233
+ }
234
+ );
235
+ return str?.split("```")[0];
236
+ };
237
+
238
+ const generateTaskHref = (href) => {
239
+ if (href) {
240
+ const taskHref = href?.split("/");
241
+ return `#${taskHref[taskHref?.length - 1].toLowerCase()}`;
242
+ }
243
+ };
244
+ computed(() => {
245
+ const textBlocks = props.page?.description.split("\n\n");
246
+ let content = "";
247
+ textBlocks.forEach((text) => {
248
+ const newText = replaceText(text);
249
+ const descriptionParts = newText?.split(/:\s?\n/);
250
+
251
+ if (descriptionParts) {
252
+ const alertParts = descriptionParts[0].split(/::alert{type="warning"}\n/);
253
+ const alertContent = (alertParts.length > 1)
254
+ ?
255
+ `<div class="doc-alert alert alert-warning" role="alert">
256
+ <p>${replaceText(alertParts[1]?.split(":")[0])}</p>
257
+ </div>`
258
+ :
259
+ `<p>${descriptionParts[0]}:</p>`;
260
+
261
+ const listContent = descriptionParts[1]
262
+ ?
263
+ `<ul>${generateList(descriptionParts[1])}</ul>`
264
+ :
265
+ "";
266
+
267
+ content += alertContent + listContent;
268
+ } else {
269
+ content += `<p>${newText}</p>`;
270
+ }
271
+ });
272
+
273
+ return content;
274
+ });
275
+ const sortSchemaByRequired = (schema) => {
276
+ const requiredKeys = [];
277
+ const nonRequiredKeys = [];
278
+
279
+ for (const key in schema) {
280
+ if (schema[key].$required) {
281
+ requiredKeys.push(key);
282
+ } else {
283
+ nonRequiredKeys.push(key);
284
+ }
285
+ }
286
+
287
+ const sortedKeys = [...requiredKeys, ...nonRequiredKeys];
288
+
289
+ const sortedSchema = {};
290
+ sortedKeys.forEach(key => {
291
+ sortedSchema[key] = schema[key];
292
+ });
293
+
294
+ return sortedSchema;
295
+ }
296
+
297
+ const generateList = (descriptionPart) => {
298
+ let optionList = "";
299
+ descriptionPart?.split(/[-*]/).forEach((item) => {
300
+ if (item.trim()) {
301
+ optionList += `
302
+ <li>${replaceText(item)}</li>
303
+ `
304
+ }
305
+ });
306
+
307
+ return optionList;
308
+ }
309
+
310
+ const generateExampleCode = (example) => {
311
+ if (!example?.full) {
312
+ const firstCode = `id: "${props.getPageName()?.split(".").reverse()[0]?.toLowerCase()}"\ntype: "${props.getPageName()}"\n`;
313
+ return firstCode.concat(example.code)
314
+ }
315
+
316
+ return example.code;
317
+ }
318
+ </script>
319
+
320
+ <style lang="scss" scoped>
321
+ :deep(.bd-markdown) {
322
+ p {
323
+ strong {
324
+ code{
325
+ background: #161617;
326
+ border: 1px solid #252526;
327
+ border-radius: var(--bs-border-radius);
328
+ color: #b9b9ba;
329
+ padding: 0 .25rem;
330
+ }
331
+ }
332
+ }
333
+ }
334
+ </style>