@kestra-io/ui-libs 0.0.46 → 0.0.48

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