|
| 1 | +<template> |
| 2 | + <v-row dense> |
| 3 | + <v-col> |
| 4 | + <v-btn |
| 5 | + variant="text" |
| 6 | + class="text-none" |
| 7 | + :append-icon="show ? 'mdi-chevron-up' : 'mdi-chevron-down'" |
| 8 | + @click="show = !show" |
| 9 | + > |
| 10 | + {{ name }} |
| 11 | + </v-btn> |
| 12 | + </v-col> |
| 13 | + </v-row> |
| 14 | + <code-block |
| 15 | + v-if="show" |
| 16 | + language="yaml" |
| 17 | + class="pl-6" |
| 18 | + > |
| 19 | + <pre>{{ code }}</pre> |
| 20 | + </code-block> |
| 21 | +</template> |
| 22 | + |
| 23 | +<script setup> |
| 24 | +import { VBtn, VRow, VCol } from 'vuetify/components' |
| 25 | +import { computed, ref } from 'vue' |
| 26 | +import yaml from 'yaml' |
| 27 | +
|
| 28 | +const props = defineProps({ |
| 29 | + name: { |
| 30 | + type: String, |
| 31 | + required: true |
| 32 | + }, |
| 33 | + schema: { |
| 34 | + type: Object, |
| 35 | + required: true |
| 36 | + } |
| 37 | +}) |
| 38 | +
|
| 39 | +const show = ref(false) |
| 40 | +
|
| 41 | +const escapeRegExp = (/** @type {string} */str) => str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&') |
| 42 | +
|
| 43 | +const removeRegexps = ['type: object', 'additionalProperties: false'] |
| 44 | + .map(r => new RegExp(escapeRegExp(r) + '(\\s*)', 'g')) |
| 45 | +/** @type {[string, string][]} */ |
| 46 | +const refsStrings = [ |
| 47 | + ['$ref: https://json-layout.github.io/normalized-layout-keyword#/$defs/expression', 'Expression'], |
| 48 | + ['$ref: "#/$defs/expression"', 'Expression'], |
| 49 | + ['$ref: "#/$defs/state-node-options-base"', 'Options'], |
| 50 | + ['$ref: "#/$defs/cols-obj"', 'Responsive cols'], |
| 51 | + ['$ref: "#/$defs/state-node-props-lib"', 'Vuetify props'], |
| 52 | + ['$ref: "#/$defs/state-node-slots-lib"', 'Vuetify slots'], |
| 53 | + ['$ref: "#/$defs/slot"', 'Slot'], |
| 54 | + ['$ref: "#/$defs/children"', 'Children'], |
| 55 | + ['$ref: "#/$defs/child-ref"', 'Child reference'], |
| 56 | + ['$ref: "#/$defs/child-composite"', 'Child info'], |
| 57 | + ['$ref: "#/$defs/select-items"', 'Select items'], |
| 58 | + ['$ref: "#/$defs/get-items"', 'Get select items'] |
| 59 | +] |
| 60 | +/** @type {[RegExp, string][]} */ |
| 61 | +const replacementRegexps = refsStrings.map(r => ([new RegExp('(\\s*)' + escapeRegExp(r[0]), 'g'), ' ' + r[1]])) |
| 62 | +// removeRegexps.push(/^\s*$/g) |
| 63 | +// const emptyLinesRegexp = /^\s*$/g |
| 64 | +
|
| 65 | +const code = computed(() => { |
| 66 | + const schema = { ...props.schema.properties } |
| 67 | + delete schema.comp |
| 68 | + let code = yaml.stringify(schema) |
| 69 | + for (const r of removeRegexps) { |
| 70 | + code = code.replace(r, '') |
| 71 | + } |
| 72 | + for (const r of replacementRegexps) { |
| 73 | + code = code.replace(r[0], r[1]) |
| 74 | + } |
| 75 | + return code |
| 76 | +}) |
| 77 | +</script> |
0 commit comments