@quazardous/qdadm 2.50.1 → 2.51.0
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/styles/qdadm.css +1 -1
- package/package.json +2 -1
- package/src/components/edit/FormActions.vue +33 -9
- package/src/components/edit/FormPage.vue +8 -0
- package/src/components/editors/JsonStructuredField.vue +36 -219
- package/src/components/editors/PermissionEditor.vue +62 -204
- package/src/components/editors/permissionSuggestions.ts +139 -0
- package/src/components/editors/structured/JsonRawFace.vue +37 -0
- package/src/components/editors/structured/StructuredField.vue +214 -0
- package/src/components/editors/structured/YamlRawFace.vue +70 -0
- package/src/components/editors/structured/faces.ts +35 -0
- package/src/components/editors/structured/registerJson.ts +5 -0
- package/src/components/editors/structured/registerYaml.ts +5 -0
- package/src/components/index.ts +8 -2
- package/src/composables/confirmDelete.ts +6 -3
- package/src/composables/useEntityItemFormPage.ts +15 -5
- package/src/composables/useEntityItemFormPage.types.ts +7 -1
- package/src/editors/index.ts +4 -14
- package/src/editors/json.ts +19 -0
- package/src/editors/yaml.ts +6 -1
- package/src/i18n/defaults/core.en.generated.ts +17 -0
- package/src/i18n/defaults/core.en.yml +17 -0
- package/src/i18n/defaults/core.fr.generated.ts +17 -0
- package/src/i18n/defaults/core.fr.yml +17 -0
- package/src/styles/_forms.scss +2 -1
- package/src/styles/_responsive.scss +2 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What PermissionEditor suggests while a permission is typed (#5333)
|
|
3
|
+
*
|
|
4
|
+
* Keys are `namespace:action`, the namespace of any depth (`auth:impersonate`,
|
|
5
|
+
* `entity:books:read`, `logs:errors:read`). Wildcards follow PermissionMatcher:
|
|
6
|
+
* `*` is one segment, `**` any number of them, anywhere in the pattern.
|
|
7
|
+
*
|
|
8
|
+
* - `` → the first segments, `**` (all) and `**:` (an action everywhere)
|
|
9
|
+
* - `entity:` → its next segments, and its wildcards: `entity:**`,
|
|
10
|
+
* `entity:*` (its direct permissions), `entity:*:read`, `entity:**:read`
|
|
11
|
+
* - anything with a `*` → the wildcards starting with it
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export interface Permission {
|
|
15
|
+
key: string
|
|
16
|
+
namespace: string
|
|
17
|
+
action: string
|
|
18
|
+
label: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PermissionRegistry {
|
|
22
|
+
getAll(): Permission[]
|
|
23
|
+
get(key: string): Permission | undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface Suggestion {
|
|
27
|
+
label: string
|
|
28
|
+
value: string
|
|
29
|
+
type: 'namespace' | 'permission' | 'wildcard' | 'wildcard-action'
|
|
30
|
+
description: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The texts of the suggestions, from the catalogue */
|
|
34
|
+
export interface SuggestionTexts {
|
|
35
|
+
all: () => string
|
|
36
|
+
actionEverywhere: (action: string) => string
|
|
37
|
+
anActionEverywhere: () => string
|
|
38
|
+
allUnder: (prefix: string) => string
|
|
39
|
+
directUnder: (prefix: string) => string
|
|
40
|
+
actionUnder: (action: string, prefix: string) => string
|
|
41
|
+
subItems: (count: number) => string
|
|
42
|
+
label: (key: string) => string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A registry from a plain list of keys: namespace and action cut at the last `:` */
|
|
46
|
+
export function permissionRegistryFromList(keys: string[], label: (key: string) => string = (k) => k): PermissionRegistry {
|
|
47
|
+
const list: Permission[] = [...new Set(keys.filter((k) => typeof k === 'string' && k !== ''))].map((key) => {
|
|
48
|
+
const at = key.lastIndexOf(':')
|
|
49
|
+
return { key, namespace: at > 0 ? key.slice(0, at) : '', action: at >= 0 ? key.slice(at + 1) : key, label: label(key) }
|
|
50
|
+
})
|
|
51
|
+
const byKey = new Map(list.map((p) => [p.key, p]))
|
|
52
|
+
return { getAll: () => list, get: (key) => byKey.get(key) }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Every wildcard the keys make sense of, with what it covers */
|
|
56
|
+
export function wildcardCandidates(keys: string[], texts: SuggestionTexts): Suggestion[] {
|
|
57
|
+
const out = new Map<string, Suggestion>()
|
|
58
|
+
const add = (value: string, type: Suggestion['type'], description: string) => {
|
|
59
|
+
if (!out.has(value)) out.set(value, { label: value, value, type, description })
|
|
60
|
+
}
|
|
61
|
+
const split = keys.map((k) => k.split(':'))
|
|
62
|
+
const actions = [...new Set(split.map((parts) => parts[parts.length - 1]!))].sort()
|
|
63
|
+
|
|
64
|
+
add('**', 'wildcard', texts.all())
|
|
65
|
+
for (const action of actions) add(`**:${action}`, 'wildcard-action', texts.actionEverywhere(action))
|
|
66
|
+
|
|
67
|
+
// Two-part keys: `*:read` covers them all
|
|
68
|
+
if (split.some((parts) => parts.length === 2)) {
|
|
69
|
+
for (const action of [...new Set(split.filter((p) => p.length === 2).map((p) => p[1]!))].sort()) {
|
|
70
|
+
add(`*:${action}`, 'wildcard-action', texts.actionUnder(action, '*'))
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Each namespace prefix and what lies under it
|
|
75
|
+
const prefixes = new Set<string>()
|
|
76
|
+
for (const parts of split) for (let i = 1; i < parts.length; i++) prefixes.add(parts.slice(0, i).join(':'))
|
|
77
|
+
for (const prefix of [...prefixes].sort()) {
|
|
78
|
+
const depth = prefix.split(':').length
|
|
79
|
+
const under = split.filter((parts) => parts.length > depth && parts.slice(0, depth).join(':') === prefix)
|
|
80
|
+
add(`${prefix}:**`, 'wildcard', texts.allUnder(prefix))
|
|
81
|
+
if (under.some((parts) => parts.length === depth + 1)) add(`${prefix}:*`, 'wildcard', texts.directUnder(prefix))
|
|
82
|
+
for (const parts of under) {
|
|
83
|
+
const action = parts[parts.length - 1]!
|
|
84
|
+
if (parts.length === depth + 2) add(`${prefix}:*:${action}`, 'wildcard-action', texts.actionUnder(action, prefix))
|
|
85
|
+
if (parts.length > depth + 2) add(`${prefix}:**:${action}`, 'wildcard-action', texts.actionUnder(action, prefix))
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return [...out.values()]
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The suggestions for what is typed, at most `limit` */
|
|
92
|
+
export function suggestPermissions(query: string, keys: string[], texts: SuggestionTexts, limit = 20): Suggestion[] {
|
|
93
|
+
const lower = query.toLowerCase()
|
|
94
|
+
const wildcards = () => wildcardCandidates(keys, texts)
|
|
95
|
+
|
|
96
|
+
// A wildcard being typed: the wildcards it starts
|
|
97
|
+
if (query.includes('*')) {
|
|
98
|
+
const results = wildcards().filter((s) => s.value.toLowerCase().startsWith(lower))
|
|
99
|
+
if (query === '**' || query.startsWith('**:')) return results.slice(0, limit)
|
|
100
|
+
return results.sort((a, b) => a.value.length - b.value.length || a.value.localeCompare(b.value)).slice(0, limit)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const results: Suggestion[] = []
|
|
104
|
+
const prefixes = new Set<string>()
|
|
105
|
+
for (const key of keys) {
|
|
106
|
+
const parts = key.split(':')
|
|
107
|
+
for (let i = 1; i <= parts.length; i++) prefixes.add(parts.slice(0, i).join(':'))
|
|
108
|
+
}
|
|
109
|
+
const isKey = (p: string) => keys.includes(p)
|
|
110
|
+
const count = (p: string) => [...prefixes].filter((x) => x.startsWith(`${p}:`)).length
|
|
111
|
+
|
|
112
|
+
for (const prefix of [...prefixes].sort()) {
|
|
113
|
+
if (!prefix.toLowerCase().startsWith(lower) || prefix.toLowerCase() === lower) continue
|
|
114
|
+
// Complete up to the next `:` past what is typed
|
|
115
|
+
const next = prefix.indexOf(':', query.length)
|
|
116
|
+
const value = next > -1 ? prefix.slice(0, next + 1) : isKey(prefix) ? prefix : `${prefix}:`
|
|
117
|
+
if (results.some((r) => r.value === value)) continue
|
|
118
|
+
const namespace = value.endsWith(':')
|
|
119
|
+
results.push({
|
|
120
|
+
label: value,
|
|
121
|
+
value,
|
|
122
|
+
type: namespace ? 'namespace' : 'permission',
|
|
123
|
+
description: namespace ? texts.subItems(count(value.slice(0, -1))) : texts.label(value),
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
results.sort((a, b) => (a.type === b.type ? a.label.localeCompare(b.label) : a.type === 'namespace' ? -1 : 1))
|
|
127
|
+
|
|
128
|
+
// The wildcards of this level: `**` at the start, `entity:**`… after a namespace
|
|
129
|
+
let levelWildcards: Suggestion[] = []
|
|
130
|
+
if (query === '') {
|
|
131
|
+
levelWildcards = [
|
|
132
|
+
{ label: '**', value: '**', type: 'wildcard', description: texts.all() },
|
|
133
|
+
{ label: '**:', value: '**:', type: 'namespace', description: texts.anActionEverywhere() },
|
|
134
|
+
]
|
|
135
|
+
} else if (query.endsWith(':')) {
|
|
136
|
+
levelWildcards = wildcards().filter((s) => s.value.startsWith(query) && s.value.slice(query.length).startsWith('*'))
|
|
137
|
+
}
|
|
138
|
+
return [...levelWildcards, ...results].slice(0, limit)
|
|
139
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The JSON face of StructuredField (#5333), on VanillaJsonEditor.
|
|
4
|
+
* Registered by '@quazardous/qdadm/editors/json'.
|
|
5
|
+
*/
|
|
6
|
+
import VanillaJsonEditor from '../VanillaJsonEditor.vue'
|
|
7
|
+
|
|
8
|
+
withDefaults(
|
|
9
|
+
defineProps<{
|
|
10
|
+
modelValue?: unknown
|
|
11
|
+
height?: string
|
|
12
|
+
options?: { mode?: 'tree' | 'text' | 'table' }
|
|
13
|
+
}>(),
|
|
14
|
+
{ height: '400px', options: () => ({}) }
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
const emit = defineEmits<{
|
|
18
|
+
'update:modelValue': [value: unknown]
|
|
19
|
+
invalid: [invalid: boolean]
|
|
20
|
+
}>()
|
|
21
|
+
|
|
22
|
+
function onUpdate(value: unknown): void {
|
|
23
|
+
// The editor reports only valid JSON here
|
|
24
|
+
emit('invalid', false)
|
|
25
|
+
emit('update:modelValue', value)
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<VanillaJsonEditor
|
|
31
|
+
:modelValue="modelValue as never"
|
|
32
|
+
:mode="(options.mode ?? 'text') as never"
|
|
33
|
+
:height="height"
|
|
34
|
+
@update:modelValue="onUpdate"
|
|
35
|
+
@error="emit('invalid', true)"
|
|
36
|
+
/>
|
|
37
|
+
</template>
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* StructuredField - a value edited through a structured face or as raw text (#5333)
|
|
4
|
+
*
|
|
5
|
+
* The default slot is the structured face (a form, chips, a picker); a toggle
|
|
6
|
+
* opens the raw face of the same value, in JSON or YAML. Both bind the same
|
|
7
|
+
* v-model.
|
|
8
|
+
*
|
|
9
|
+
* <StructuredField v-model="scopes" format="yaml">
|
|
10
|
+
* <PermissionEditor v-model="scopes" :permissions="all" />
|
|
11
|
+
* </StructuredField>
|
|
12
|
+
*
|
|
13
|
+
* The raw faces are registered by the entries of their optional peers:
|
|
14
|
+
* import '@quazardous/qdadm/editors/json' or '@quazardous/qdadm/editors/yaml'
|
|
15
|
+
* once in the app.
|
|
16
|
+
*
|
|
17
|
+
* Props:
|
|
18
|
+
* - modelValue: the value
|
|
19
|
+
* - rawValue / update:rawValue: a separate binding for the raw face, when its shape differs
|
|
20
|
+
* - format: 'json' (default) or 'yaml'
|
|
21
|
+
* - mode / update:mode: 'structured' or 'raw', controlled
|
|
22
|
+
* - defaultMode: the first face (default 'structured')
|
|
23
|
+
* - rawHeight: the raw editor's height (default 400px)
|
|
24
|
+
* - rawOptions: the format's own options (JSON: { mode: 'text' | 'tree' | 'table' })
|
|
25
|
+
* - label, showToggle
|
|
26
|
+
* - guardInvalid: stay on the raw face while its text is invalid (default true)
|
|
27
|
+
* - invalidMessage: the message then shown (default from the catalogue)
|
|
28
|
+
*
|
|
29
|
+
* Events: update:modelValue, update:rawValue, update:mode, invalid (true / false)
|
|
30
|
+
*/
|
|
31
|
+
import { ref, computed, watch } from 'vue'
|
|
32
|
+
import SelectButton from 'primevue/selectbutton'
|
|
33
|
+
import QdMessage from '../../base/QdMessage.vue'
|
|
34
|
+
import { useI18n } from '../../../i18n/useI18n'
|
|
35
|
+
import { getStructuredFace, type StructuredFormat } from './faces'
|
|
36
|
+
|
|
37
|
+
export type StructuredViewMode = 'structured' | 'raw'
|
|
38
|
+
|
|
39
|
+
interface Props {
|
|
40
|
+
modelValue?: unknown
|
|
41
|
+
rawValue?: unknown
|
|
42
|
+
format?: StructuredFormat
|
|
43
|
+
mode?: StructuredViewMode | null
|
|
44
|
+
defaultMode?: StructuredViewMode
|
|
45
|
+
rawHeight?: string
|
|
46
|
+
rawOptions?: Record<string, unknown>
|
|
47
|
+
label?: string | null
|
|
48
|
+
showToggle?: boolean
|
|
49
|
+
guardInvalid?: boolean
|
|
50
|
+
invalidMessage?: string | null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
54
|
+
modelValue: () => ({}),
|
|
55
|
+
rawValue: undefined,
|
|
56
|
+
format: 'json',
|
|
57
|
+
mode: null,
|
|
58
|
+
defaultMode: 'structured',
|
|
59
|
+
rawHeight: '400px',
|
|
60
|
+
rawOptions: () => ({}),
|
|
61
|
+
label: null,
|
|
62
|
+
showToggle: true,
|
|
63
|
+
guardInvalid: true,
|
|
64
|
+
invalidMessage: null,
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const emit = defineEmits<{
|
|
68
|
+
'update:modelValue': [value: unknown]
|
|
69
|
+
'update:rawValue': [value: unknown]
|
|
70
|
+
'update:mode': [value: StructuredViewMode]
|
|
71
|
+
invalid: [invalid: boolean]
|
|
72
|
+
}>()
|
|
73
|
+
|
|
74
|
+
const { tOr } = useI18n()
|
|
75
|
+
|
|
76
|
+
const face = computed(() => getStructuredFace(props.format))
|
|
77
|
+
const internalMode = ref<StructuredViewMode>(props.defaultMode)
|
|
78
|
+
const invalid = ref(false)
|
|
79
|
+
|
|
80
|
+
const viewMode = computed<StructuredViewMode>({
|
|
81
|
+
get: () => props.mode ?? internalMode.value,
|
|
82
|
+
set: (next) => {
|
|
83
|
+
// Leaving the raw face with an invalid text would drop what the user typed
|
|
84
|
+
if (props.guardInvalid && invalid.value && viewMode.value === 'raw' && next === 'structured') return
|
|
85
|
+
if (props.mode !== null) emit('update:mode', next)
|
|
86
|
+
else internalMode.value = next
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
watch(
|
|
91
|
+
() => props.mode,
|
|
92
|
+
(next) => {
|
|
93
|
+
if (next) internalMode.value = next
|
|
94
|
+
}
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
const formatLabel = computed(() => (props.format === 'yaml' ? 'YAML' : 'JSON'))
|
|
98
|
+
const options = computed(() => [
|
|
99
|
+
{ label: tOr('core.structuredField.structured', 'Structured'), value: 'structured' as const, icon: 'pi pi-list' },
|
|
100
|
+
{ label: formatLabel.value, value: 'raw' as const, icon: 'pi pi-code' },
|
|
101
|
+
])
|
|
102
|
+
const message = computed(
|
|
103
|
+
() => props.invalidMessage ?? tOr('core.structuredField.invalid', 'Invalid {format}: fix it before switching views', { format: formatLabel.value })
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
const separateRaw = computed(() => props.rawValue !== undefined)
|
|
107
|
+
const rawModel = computed(() => (separateRaw.value ? props.rawValue : props.modelValue))
|
|
108
|
+
|
|
109
|
+
function onRaw(value: unknown): void {
|
|
110
|
+
if (separateRaw.value) emit('update:rawValue', value)
|
|
111
|
+
else emit('update:modelValue', value)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function onInvalid(next: boolean): void {
|
|
115
|
+
if (invalid.value === next) return
|
|
116
|
+
invalid.value = next
|
|
117
|
+
emit('invalid', next)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
defineExpose({ viewMode, invalid })
|
|
121
|
+
</script>
|
|
122
|
+
|
|
123
|
+
<template>
|
|
124
|
+
<div class="structured-field" :data-format="format">
|
|
125
|
+
<div v-if="showToggle || label" class="field-header">
|
|
126
|
+
<label v-if="label" class="field-label">{{ label }}</label>
|
|
127
|
+
<SelectButton
|
|
128
|
+
v-if="showToggle"
|
|
129
|
+
v-model="viewMode"
|
|
130
|
+
:options="options"
|
|
131
|
+
optionLabel="label"
|
|
132
|
+
optionValue="value"
|
|
133
|
+
:allowEmpty="false"
|
|
134
|
+
class="mode-toggle"
|
|
135
|
+
>
|
|
136
|
+
<template #option="{ option }">
|
|
137
|
+
<i :class="option.icon"></i>
|
|
138
|
+
<span class="toggle-label">{{ option.label }}</span>
|
|
139
|
+
</template>
|
|
140
|
+
</SelectButton>
|
|
141
|
+
</div>
|
|
142
|
+
|
|
143
|
+
<div v-if="viewMode === 'raw'" class="raw-view">
|
|
144
|
+
<QdMessage v-if="guardInvalid && invalid" severity="error" :closable="false" class="raw-error">
|
|
145
|
+
{{ message }}
|
|
146
|
+
</QdMessage>
|
|
147
|
+
<component
|
|
148
|
+
:is="face"
|
|
149
|
+
v-if="face"
|
|
150
|
+
:modelValue="rawModel"
|
|
151
|
+
:height="rawHeight"
|
|
152
|
+
:options="rawOptions"
|
|
153
|
+
@update:modelValue="onRaw"
|
|
154
|
+
@invalid="onInvalid"
|
|
155
|
+
/>
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<div v-else class="structured-view">
|
|
159
|
+
<slot></slot>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
</template>
|
|
163
|
+
|
|
164
|
+
<style scoped>
|
|
165
|
+
.structured-field {
|
|
166
|
+
width: 100%;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.field-header {
|
|
170
|
+
display: flex;
|
|
171
|
+
justify-content: space-between;
|
|
172
|
+
align-items: center;
|
|
173
|
+
margin-bottom: 0.75rem;
|
|
174
|
+
flex-wrap: wrap;
|
|
175
|
+
gap: 0.5rem;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.field-label {
|
|
179
|
+
font-weight: 600;
|
|
180
|
+
font-size: 0.95rem;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.mode-toggle {
|
|
184
|
+
flex-shrink: 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.mode-toggle :deep(.p-button) {
|
|
188
|
+
padding: 0.35rem 0.6rem;
|
|
189
|
+
font-size: 0.8rem;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.mode-toggle :deep(.p-button i) {
|
|
193
|
+
font-size: 0.75rem;
|
|
194
|
+
margin-right: 0.25rem;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.toggle-label {
|
|
198
|
+
display: none;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@media (min-width: 640px) {
|
|
202
|
+
.toggle-label {
|
|
203
|
+
display: inline;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.raw-view {
|
|
208
|
+
margin-top: 0.25rem;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.raw-error {
|
|
212
|
+
margin-bottom: 0.5rem;
|
|
213
|
+
}
|
|
214
|
+
</style>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The YAML face of StructuredField (#5333), on VanillaYamlEditor's text view.
|
|
4
|
+
* Registered by '@quazardous/qdadm/editors/yaml'.
|
|
5
|
+
*
|
|
6
|
+
* The value is written as YAML when it changes from outside, and read back
|
|
7
|
+
* from each valid text: comments typed in the text do not survive a trip
|
|
8
|
+
* through the structured face, which knows only the value.
|
|
9
|
+
*/
|
|
10
|
+
import { ref, watch } from 'vue'
|
|
11
|
+
import { parseYaml } from '@quazardous/vanilla-yamleditor'
|
|
12
|
+
import VanillaYamlEditor from '../yaml/VanillaYamlEditor.vue'
|
|
13
|
+
|
|
14
|
+
const props = withDefaults(
|
|
15
|
+
defineProps<{
|
|
16
|
+
modelValue?: unknown
|
|
17
|
+
height?: string
|
|
18
|
+
options?: Record<string, unknown>
|
|
19
|
+
}>(),
|
|
20
|
+
{ height: '400px', options: () => ({}) }
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
const emit = defineEmits<{
|
|
24
|
+
'update:modelValue': [value: unknown]
|
|
25
|
+
invalid: [invalid: boolean]
|
|
26
|
+
}>()
|
|
27
|
+
|
|
28
|
+
/** A value as YAML text, through the peer's own YAML document */
|
|
29
|
+
function toYaml(value: unknown): string {
|
|
30
|
+
if (value === null || value === undefined) return ''
|
|
31
|
+
const { doc } = parseYaml('')
|
|
32
|
+
doc.contents = doc.createNode(value) as typeof doc.contents
|
|
33
|
+
return String(doc)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const text = ref(toYaml(props.modelValue))
|
|
37
|
+
// The value this face last sent up, so its echo does not rewrite the text
|
|
38
|
+
let sent: unknown = Symbol('none')
|
|
39
|
+
|
|
40
|
+
watch(
|
|
41
|
+
() => props.modelValue,
|
|
42
|
+
(value) => {
|
|
43
|
+
if (value === sent) return
|
|
44
|
+
text.value = toYaml(value)
|
|
45
|
+
},
|
|
46
|
+
{ deep: true }
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
function onText(next: string): void {
|
|
50
|
+
text.value = next
|
|
51
|
+
const parsed = parseYaml(next)
|
|
52
|
+
if (parsed.errors.length) {
|
|
53
|
+
emit('invalid', true)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
emit('invalid', false)
|
|
57
|
+
sent = parsed.value ?? null
|
|
58
|
+
emit('update:modelValue', sent)
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<VanillaYamlEditor
|
|
64
|
+
:modelValue="text"
|
|
65
|
+
:modes="['text']"
|
|
66
|
+
:modeSwitch="false"
|
|
67
|
+
:height="height"
|
|
68
|
+
@update:modelValue="onText"
|
|
69
|
+
/>
|
|
70
|
+
</template>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The raw faces of StructuredField (#5333): JSON or YAML, each behind the
|
|
3
|
+
* entry of its optional peer.
|
|
4
|
+
*
|
|
5
|
+
* StructuredField imports no editor: importing `@quazardous/qdadm/editors/json`
|
|
6
|
+
* registers the JSON face, `@quazardous/qdadm/editors/yaml` the YAML one. A
|
|
7
|
+
* format asked for without its entry is said once, with the import to add.
|
|
8
|
+
*/
|
|
9
|
+
import { markRaw, type Component } from 'vue'
|
|
10
|
+
|
|
11
|
+
export type StructuredFormat = 'json' | 'yaml'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A raw face is a component that edits the value as text:
|
|
15
|
+
* - props: `modelValue` (the value), `height`, `options` (the format's own, e.g. JSON `mode`)
|
|
16
|
+
* - emits: `update:modelValue` with each valid value, `invalid` with true / false
|
|
17
|
+
*/
|
|
18
|
+
const faces = new Map<StructuredFormat, Component>()
|
|
19
|
+
const warned = new Set<StructuredFormat>()
|
|
20
|
+
|
|
21
|
+
export function registerStructuredFace(format: StructuredFormat, component: Component): void {
|
|
22
|
+
faces.set(format, markRaw(component))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getStructuredFace(format: StructuredFormat): Component | null {
|
|
26
|
+
const face = faces.get(format)
|
|
27
|
+
if (!face && !warned.has(format)) {
|
|
28
|
+
warned.add(format)
|
|
29
|
+
console.warn(
|
|
30
|
+
`[qdadm] StructuredField: no ${format.toUpperCase()} face. Import '@quazardous/qdadm/editors/${format}' once in the app ` +
|
|
31
|
+
`(it needs ${format === 'json' ? 'vanilla-jsoneditor' : '@quazardous/vanilla-yamleditor'}).`
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
return face ?? null
|
|
35
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -54,13 +54,19 @@ export { default as KeyValueEditor } from './editors/KeyValueEditor.vue'
|
|
|
54
54
|
export { default as LanguageEditor } from './editors/LanguageEditor.vue'
|
|
55
55
|
export { default as ScopeEditor } from './editors/ScopeEditor.vue'
|
|
56
56
|
export { default as PermissionEditor } from './editors/PermissionEditor.vue'
|
|
57
|
+
export { permissionRegistryFromList, type PermissionRegistry, type Permission as RegistryPermission } from './editors/permissionSuggestions'
|
|
57
58
|
export { default as RoleGrantsEditor } from './editors/RoleGrantsEditor.vue'
|
|
58
59
|
export { default as JsonEditorFoldable } from './editors/JsonEditorFoldable.vue'
|
|
59
60
|
export { default as JsonViewer } from './editors/JsonViewer.vue'
|
|
60
61
|
|
|
62
|
+
// A value through a structured face or as raw JSON / YAML (#5333). Its raw
|
|
63
|
+
// faces come with '@quazardous/qdadm/editors/json' and '.../editors/yaml'.
|
|
64
|
+
export { default as StructuredField } from './editors/structured/StructuredField.vue'
|
|
65
|
+
export { registerStructuredFace, type StructuredFormat } from './editors/structured/faces'
|
|
66
|
+
|
|
61
67
|
// NOTE: VanillaJsonEditor and JsonStructuredField require vanilla-jsoneditor
|
|
62
|
-
// Import from '@quazardous/qdadm/editors' instead:
|
|
63
|
-
// import { VanillaJsonEditor, JsonStructuredField } from '@quazardous/qdadm/editors'
|
|
68
|
+
// Import from '@quazardous/qdadm/editors/json' instead:
|
|
69
|
+
// import { VanillaJsonEditor, JsonStructuredField } from '@quazardous/qdadm/editors/json'
|
|
64
70
|
|
|
65
71
|
// Dialogs
|
|
66
72
|
export { default as SimpleDialog } from './dialogs/SimpleDialog.vue'
|
|
@@ -9,6 +9,9 @@ export interface DeleteConfirmation {
|
|
|
9
9
|
message: string
|
|
10
10
|
header: string
|
|
11
11
|
accept: () => void
|
|
12
|
+
/** The accept button, when the action has its own word ("Revoke"); default Delete (#5333) */
|
|
13
|
+
acceptLabel?: string
|
|
14
|
+
acceptIcon?: string
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
/** The part of PrimeVue's confirm service a delete confirmation uses. */
|
|
@@ -35,14 +38,14 @@ export type TranslateOr = (key: string, fallback: string) => string
|
|
|
35
38
|
* The buttons say what they do, in the app's language (#5323): Delete / Cancel
|
|
36
39
|
* from the catalogue, not PrimeVue's own Yes / No.
|
|
37
40
|
*/
|
|
38
|
-
export function requireDeleteConfirmation(confirm: ConfirmRequire, tOr: TranslateOr, { message, header, accept }: DeleteConfirmation): void {
|
|
41
|
+
export function requireDeleteConfirmation(confirm: ConfirmRequire, tOr: TranslateOr, { message, header, accept, acceptLabel, acceptIcon }: DeleteConfirmation): void {
|
|
39
42
|
confirm.require({
|
|
40
43
|
message,
|
|
41
44
|
header,
|
|
42
45
|
icon: 'pi pi-exclamation-triangle',
|
|
43
46
|
acceptClass: 'p-button-danger',
|
|
44
|
-
acceptLabel: tOr('core.actions.delete', 'Delete'),
|
|
45
|
-
acceptIcon: 'pi pi-trash',
|
|
47
|
+
acceptLabel: acceptLabel ?? tOr('core.actions.delete', 'Delete'),
|
|
48
|
+
acceptIcon: acceptIcon ?? 'pi pi-trash',
|
|
46
49
|
rejectLabel: tOr('core.actions.cancel', 'Cancel'),
|
|
47
50
|
rejectClass: 'p-button-secondary p-button-text',
|
|
48
51
|
closeOnEscape: true,
|
|
@@ -478,12 +478,21 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
|
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
+
// The delete action's own words, when addDeleteAction() gives them (#5333)
|
|
482
|
+
let deleteWording: AddDeleteActionOptions = {}
|
|
483
|
+
|
|
481
484
|
function confirmDelete(): void {
|
|
482
|
-
const label = manager.getEntityLabel(data.value) || entityId.value
|
|
485
|
+
const label = String(manager.getEntityLabel(data.value) || entityId.value)
|
|
486
|
+
const { confirmMessage, confirmHeader, label: actionLabel, icon } = deleteWording
|
|
483
487
|
requireDeleteConfirmation(confirm, tOr, {
|
|
484
|
-
message:
|
|
485
|
-
|
|
488
|
+
message:
|
|
489
|
+
typeof confirmMessage === 'function'
|
|
490
|
+
? confirmMessage(data.value as Record<string, unknown>, label)
|
|
491
|
+
: confirmMessage ?? tOr('core.messages.confirmDeleteItem', 'Delete {entity} "{label}"?', { entity: entityName, label }),
|
|
492
|
+
header: confirmHeader ?? tOr('core.messages.confirmDeleteTitle', 'Confirm Delete'),
|
|
486
493
|
accept: remove,
|
|
494
|
+
...(actionLabel ? { acceptLabel: actionLabel } : {}),
|
|
495
|
+
...(icon ? { acceptIcon: icon } : {}),
|
|
487
496
|
})
|
|
488
497
|
}
|
|
489
498
|
|
|
@@ -811,12 +820,13 @@ export function useEntityItemFormPage<T extends Record<string, unknown> = Record
|
|
|
811
820
|
}
|
|
812
821
|
|
|
813
822
|
function addDeleteAction(options: AddDeleteActionOptions = {}): void {
|
|
814
|
-
const { label } = options
|
|
823
|
+
const { label, icon } = options
|
|
815
824
|
const deleteLabel = () => tOr('core.actions.delete', 'Delete')
|
|
825
|
+
deleteWording = options
|
|
816
826
|
|
|
817
827
|
addAction('delete', {
|
|
818
828
|
...(label ? { label } : { label: deleteLabel(), _label: deleteLabel }),
|
|
819
|
-
icon: 'pi pi-trash',
|
|
829
|
+
icon: icon ?? 'pi pi-trash',
|
|
820
830
|
severity: 'danger',
|
|
821
831
|
onClick: confirmDelete,
|
|
822
832
|
visible: () => isEdit.value && manager.canDelete(data.value),
|
|
@@ -257,8 +257,14 @@ export interface AddSaveActionOptions {
|
|
|
257
257
|
* Options for addDeleteAction
|
|
258
258
|
*/
|
|
259
259
|
export interface AddDeleteActionOptions {
|
|
260
|
-
/** Custom label (default: 'Delete') */
|
|
260
|
+
/** Custom label (default: 'Delete'); the confirmation's accept button says it too (#5333) */
|
|
261
261
|
label?: string
|
|
262
|
+
/** Custom icon (default: 'pi pi-trash') */
|
|
263
|
+
icon?: string
|
|
264
|
+
/** The confirmation's title (default: 'Confirm Delete' from the catalogue) */
|
|
265
|
+
confirmHeader?: string
|
|
266
|
+
/** The confirmation's question: a string, or built from the record and its label (#5333) */
|
|
267
|
+
confirmMessage?: string | ((item: Record<string, unknown>, label: string) => string)
|
|
262
268
|
}
|
|
263
269
|
|
|
264
270
|
/**
|
package/src/editors/index.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* qdadm/editors -
|
|
2
|
+
* qdadm/editors - the JSON editors, as '@quazardous/qdadm/editors/json'
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* import { VanillaJsonEditor, JsonStructuredField } from '@quazardous/qdadm/editors'
|
|
4
|
+
* Kept so existing imports work; new code imports
|
|
5
|
+
* '@quazardous/qdadm/editors/json' (and '@quazardous/qdadm/editors/yaml').
|
|
9
6
|
*/
|
|
10
|
-
|
|
11
|
-
export { default as VanillaJsonEditor } from '../components/editors/VanillaJsonEditor.vue'
|
|
12
|
-
export { default as JsonStructuredField } from '../components/editors/JsonStructuredField.vue'
|
|
13
|
-
|
|
14
|
-
// Re-export the mode enum so consumers who want it don't need to depend on
|
|
15
|
-
// vanilla-jsoneditor directly (#1253). String literals ('tree' | 'text' |
|
|
16
|
-
// 'table') are accepted by VanillaJsonEditor's `mode` prop anyway.
|
|
17
|
-
export { Mode } from 'vanilla-jsoneditor'
|
|
7
|
+
export * from './json'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* qdadm/editors/json - JSON editors on vanilla-jsoneditor (an optional peer)
|
|
3
|
+
*
|
|
4
|
+
* Import from '@quazardous/qdadm/editors/json' only if you install
|
|
5
|
+
* vanilla-jsoneditor: it stays out of the main bundle. Importing it also
|
|
6
|
+
* registers the JSON face of StructuredField (#5333).
|
|
7
|
+
*
|
|
8
|
+
* import { VanillaJsonEditor, JsonStructuredField } from '@quazardous/qdadm/editors/json'
|
|
9
|
+
*/
|
|
10
|
+
import '../components/editors/structured/registerJson'
|
|
11
|
+
|
|
12
|
+
export { default as VanillaJsonEditor } from '../components/editors/VanillaJsonEditor.vue'
|
|
13
|
+
export { default as JsonStructuredField } from '../components/editors/JsonStructuredField.vue'
|
|
14
|
+
export { default as StructuredField } from '../components/editors/structured/StructuredField.vue'
|
|
15
|
+
|
|
16
|
+
// Re-export the mode enum so consumers who want it don't need to depend on
|
|
17
|
+
// vanilla-jsoneditor directly (#1253). String literals ('tree' | 'text' |
|
|
18
|
+
// 'table') are accepted by VanillaJsonEditor's `mode` prop anyway.
|
|
19
|
+
export { Mode } from 'vanilla-jsoneditor'
|