@crombolo/schema 0.65.1 → 0.66.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/package.json +3 -3
- package/src/config-references.ts +1 -0
- package/src/describe.ts +6 -0
- package/src/edit.ts +8 -10
- package/src/editors.gen.ts +756 -0
- package/src/editors.ts +79 -0
- package/src/generate-delivery.ts +5 -0
- package/src/generate.ts +17 -0
- package/src/index.ts +1 -0
- package/src/presets.ts +353 -53
- package/src/site-edit.ts +10 -0
package/src/editors.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The editors the back office offers (story 357), from the table
|
|
3
|
+
* `bun run editors:table` generates from its manifests: each editor's UI, the
|
|
4
|
+
* settings each has, and what the data type editor fills in for a new data type.
|
|
5
|
+
*/
|
|
6
|
+
import { EDITOR_SCHEMAS, EDITOR_UIS } from './editors.gen.ts'
|
|
7
|
+
|
|
8
|
+
export { EDITOR_SCHEMAS, EDITOR_UIS }
|
|
9
|
+
|
|
10
|
+
export interface EditorSchemaEntry {
|
|
11
|
+
name: string
|
|
12
|
+
defaultUi: string | null
|
|
13
|
+
/** Each setting's alias, and the editor UI that edits it. */
|
|
14
|
+
settings: Readonly<Record<string, string>>
|
|
15
|
+
defaultData: Readonly<Record<string, unknown>>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface EditorUiEntry {
|
|
19
|
+
label: string
|
|
20
|
+
schema: string
|
|
21
|
+
settings: Readonly<Record<string, string>>
|
|
22
|
+
defaultData: Readonly<Record<string, unknown>>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Every setting the data type editor shows for this editor and UI. */
|
|
26
|
+
export function editorSettings(editor: string, ui: string | undefined): Set<string> {
|
|
27
|
+
return new Set([
|
|
28
|
+
...Object.keys(EDITOR_SCHEMAS[editor]?.settings ?? {}),
|
|
29
|
+
...Object.keys((ui && EDITOR_UIS[ui]?.settings) || {}),
|
|
30
|
+
])
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The values the data type editor gives a new data type of this editor and UI: the UI's over the schema's. */
|
|
34
|
+
export function editorDefaults(editor: string, ui: string | undefined): Record<string, unknown> {
|
|
35
|
+
const shown = editorSettings(editor, ui)
|
|
36
|
+
const data = { ...EDITOR_SCHEMAS[editor]?.defaultData, ...(ui && EDITOR_UIS[ui]?.defaultData) }
|
|
37
|
+
return structuredClone(Object.fromEntries(Object.entries(data).filter(([key]) => shown.has(key))))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const distance = (a: string, b: string): number => {
|
|
41
|
+
const row = Array.from({ length: b.length + 1 }, (_, i) => i)
|
|
42
|
+
for (let i = 1; i <= a.length; i++) {
|
|
43
|
+
let previous = row[0] as number
|
|
44
|
+
row[0] = i
|
|
45
|
+
for (let j = 1; j <= b.length; j++) {
|
|
46
|
+
const held = row[j] as number
|
|
47
|
+
row[j] = Math.min(
|
|
48
|
+
(row[j] as number) + 1,
|
|
49
|
+
(row[j - 1] as number) + 1,
|
|
50
|
+
previous + (a[i - 1] === b[j - 1] ? 0 : 1),
|
|
51
|
+
)
|
|
52
|
+
previous = held
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return row[b.length] as number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The names among `names` closest to `wanted`, closest first, in their order where as close. */
|
|
59
|
+
export function closestNames(wanted: string, names: readonly string[], most = 3): string[] {
|
|
60
|
+
const plain = (name: string) =>
|
|
61
|
+
name
|
|
62
|
+
.toLowerCase()
|
|
63
|
+
.replace(/^(umbraco|umb)\.(propertyeditorui\.)?/, '')
|
|
64
|
+
.replace(/[^a-z0-9]/g, '')
|
|
65
|
+
const target = plain(wanted)
|
|
66
|
+
return [...names]
|
|
67
|
+
.map((name) => {
|
|
68
|
+
const other = plain(name)
|
|
69
|
+
return {
|
|
70
|
+
name,
|
|
71
|
+
score: other.includes(target)
|
|
72
|
+
? 0
|
|
73
|
+
: Math.min(distance(target, other), distance(target, other.slice(0, target.length))),
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
.sort((a, b) => a.score - b.score)
|
|
77
|
+
.slice(0, most)
|
|
78
|
+
.map((item) => item.name)
|
|
79
|
+
}
|
package/src/generate-delivery.ts
CHANGED
|
@@ -118,6 +118,11 @@ export function generateDeliveryTypes(set: SchemaSet, options: DeliveryTypesOpti
|
|
|
118
118
|
case 'Umbraco.TextBox':
|
|
119
119
|
case 'Umbraco.TextArea':
|
|
120
120
|
case 'Umbraco.EmailAddress':
|
|
121
|
+
// As HTML (story 357).
|
|
122
|
+
case 'Umbraco.MarkdownEditor':
|
|
123
|
+
case 'Umbraco.Plain.String':
|
|
124
|
+
case 'Umbraco.ColorPicker.EyeDropper':
|
|
125
|
+
case 'Umbraco.RadioButtonList':
|
|
121
126
|
return 'string'
|
|
122
127
|
}
|
|
123
128
|
switch (storageTypeFor(editor)) {
|
package/src/generate.ts
CHANGED
|
@@ -110,7 +110,23 @@ function tsTypeFor(set: SchemaSet, dataTypeAlias: string): string {
|
|
|
110
110
|
case 'Umbraco.MultipleTextstring':
|
|
111
111
|
return 'string[]'
|
|
112
112
|
case 'Umbraco.UploadField':
|
|
113
|
+
case 'Umbraco.MarkdownEditor':
|
|
114
|
+
case 'Umbraco.Plain.String':
|
|
115
|
+
case 'Umbraco.EmailAddress':
|
|
116
|
+
case 'Umbraco.ColorPicker.EyeDropper':
|
|
117
|
+
case 'Umbraco.RadioButtonList':
|
|
118
|
+
// A member's `umb://member/…` reference: members are not looked up on a page.
|
|
119
|
+
case 'Umbraco.MemberPicker':
|
|
113
120
|
return 'string'
|
|
121
|
+
case 'Umbraco.Decimal':
|
|
122
|
+
return 'number'
|
|
123
|
+
// Both ends, the same when the slider picks no range.
|
|
124
|
+
case 'Umbraco.Slider':
|
|
125
|
+
return '{ from: number; to: number }'
|
|
126
|
+
case 'Umbraco.ColorPicker':
|
|
127
|
+
return '{ value: string; label: string } | null'
|
|
128
|
+
case 'Umbraco.ImageCropper':
|
|
129
|
+
return 'ImageCropperValue'
|
|
114
130
|
case 'Umbraco.BlockList': {
|
|
115
131
|
const { content, settings } = blockElements(set, config, blocks)
|
|
116
132
|
return `BlockListValue<BlockItem & { content: ${elementUnion(content)}; settings: ${settings.length ? `${elementUnion(settings)} | null` : 'PublishedElement | null'} }>`
|
|
@@ -165,6 +181,7 @@ export function generateTypes(set: SchemaSet): string {
|
|
|
165
181
|
'BlockGridItem',
|
|
166
182
|
'BlockItem',
|
|
167
183
|
'BlockListValue',
|
|
184
|
+
'ImageCropperValue',
|
|
168
185
|
'Link',
|
|
169
186
|
'MediaWithCrops',
|
|
170
187
|
'PublishedContent',
|
package/src/index.ts
CHANGED
package/src/presets.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Data types by preset (story 161): `types new data-type <alias> --editor
|
|
3
|
-
* <preset>` names
|
|
4
|
-
*
|
|
3
|
+
* <preset>` names an editor and its main options as flags, and gets the data
|
|
4
|
+
* type file the back office would have written, with types named by alias. Every
|
|
5
|
+
* editor the back office offers has one (story 357), and starts from the values
|
|
6
|
+
* its data type editor fills in.
|
|
5
7
|
*/
|
|
6
8
|
import { RICH_TEXT_CONFIG } from '@crombolo/data'
|
|
9
|
+
import { closestNames, EDITOR_SCHEMAS, EDITOR_UIS, editorDefaults } from './editors.ts'
|
|
7
10
|
import type { SchemaBlock, SchemaDataType } from './model.ts'
|
|
8
11
|
import { nameFor } from './scaffold.ts'
|
|
9
12
|
|
|
@@ -22,15 +25,31 @@ export interface PresetOptions {
|
|
|
22
25
|
allow?: string[]
|
|
23
26
|
block?: string[]
|
|
24
27
|
columns?: number
|
|
28
|
+
of?: string
|
|
29
|
+
group?: string
|
|
30
|
+
color?: string[]
|
|
31
|
+
alpha?: boolean
|
|
32
|
+
palette?: boolean
|
|
33
|
+
range?: boolean
|
|
34
|
+
extension?: string[]
|
|
35
|
+
crop?: string[]
|
|
36
|
+
preview?: boolean
|
|
37
|
+
language?: string
|
|
38
|
+
valueType?: string
|
|
25
39
|
}
|
|
26
40
|
|
|
27
41
|
type Option = keyof PresetOptions
|
|
28
42
|
|
|
29
|
-
|
|
43
|
+
type Built = { config: Record<string, unknown>; blocks?: SchemaBlock[] }
|
|
44
|
+
|
|
45
|
+
export interface Preset {
|
|
30
46
|
editor: string
|
|
31
47
|
editorUi: string
|
|
32
48
|
takes: readonly Option[]
|
|
33
|
-
|
|
49
|
+
/** Options that take whole numbers only. */
|
|
50
|
+
whole?: readonly Option[]
|
|
51
|
+
/** The config and blocks its options give, or why they cannot be given. */
|
|
52
|
+
build: (o: PresetOptions) => Built | string
|
|
34
53
|
}
|
|
35
54
|
|
|
36
55
|
const defined = (record: Record<string, unknown>): Record<string, unknown> =>
|
|
@@ -41,100 +60,339 @@ const limit = (o: PresetOptions) =>
|
|
|
41
60
|
|
|
42
61
|
const blocks = (o: PresetOptions) => o.block?.map((element) => ({ element }))
|
|
43
62
|
|
|
63
|
+
const ui = (name: string) => `Umb.PropertyEditorUi.${name}`
|
|
64
|
+
|
|
65
|
+
const plain = (build: (o: PresetOptions) => Record<string, unknown> = () => ({})) => ({
|
|
66
|
+
build: (o: PresetOptions) => ({ config: build(o) }),
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const START_NODE_TYPES: Readonly<Record<string, string>> = {
|
|
70
|
+
pages: 'content',
|
|
71
|
+
media: 'media',
|
|
72
|
+
members: 'member',
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const CODE_LANGUAGES = [
|
|
76
|
+
'csharp',
|
|
77
|
+
'css',
|
|
78
|
+
'html',
|
|
79
|
+
'javascript',
|
|
80
|
+
'json',
|
|
81
|
+
'markdown',
|
|
82
|
+
'razor',
|
|
83
|
+
'typescript',
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
const LABEL_VALUE_TYPES: Readonly<Record<string, string>> = {
|
|
87
|
+
string: 'STRING',
|
|
88
|
+
'long-string': 'TEXT',
|
|
89
|
+
decimal: 'DECIMAL',
|
|
90
|
+
integer: 'INT',
|
|
91
|
+
'big-integer': 'BIGINT',
|
|
92
|
+
date: 'DATETIME',
|
|
93
|
+
time: 'TIME',
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i
|
|
97
|
+
|
|
98
|
+
/** `#1b264f=Primary` as a swatch; its label is its value when none is given. */
|
|
99
|
+
function swatches(colors: readonly string[]): Array<{ value: string; label: string }> | string {
|
|
100
|
+
const out: Array<{ value: string; label: string }> = []
|
|
101
|
+
for (const color of colors) {
|
|
102
|
+
const [hex = '', ...rest] = color.split('=')
|
|
103
|
+
if (!HEX.test(hex.trim()))
|
|
104
|
+
return `--color wants a hex colour, as #1b264f or #1b264f=Primary, not "${color}"`
|
|
105
|
+
const value = `#${hex.trim().replace(/^#/, '').toLowerCase()}`
|
|
106
|
+
out.push({ value, label: rest.join('=').trim() || value })
|
|
107
|
+
}
|
|
108
|
+
return out
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** `thumb:200x100` as a crop. */
|
|
112
|
+
function crops(given: readonly string[]) {
|
|
113
|
+
const out: Array<{ label: string; alias: string; width: number; height: number }> = []
|
|
114
|
+
for (const crop of given) {
|
|
115
|
+
const match = /^([A-Za-z][\w-]*):(\d+)x(\d+)$/.exec(crop.trim())
|
|
116
|
+
if (!match) return `--crop wants <alias>:<width>x<height>, as thumb:200x100, not "${crop}"`
|
|
117
|
+
const [, alias = '', width, height] = match
|
|
118
|
+
out.push({ label: nameFor(alias), alias, width: Number(width), height: Number(height) })
|
|
119
|
+
}
|
|
120
|
+
return out
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const oneOf = (flag: string, value: string, choices: readonly string[]) =>
|
|
124
|
+
`${flag} is one of ${choices.join(', ')}, not "${value}"`
|
|
125
|
+
|
|
44
126
|
export const DATA_TYPE_PRESETS: Readonly<Record<string, Preset>> = {
|
|
45
127
|
textstring: {
|
|
46
128
|
editor: 'Umbraco.TextBox',
|
|
47
|
-
editorUi: '
|
|
129
|
+
editorUi: ui('TextBox'),
|
|
48
130
|
takes: ['maxChars'],
|
|
49
|
-
|
|
131
|
+
whole: ['maxChars'],
|
|
132
|
+
...plain((o) => defined({ maxChars: o.maxChars })),
|
|
50
133
|
},
|
|
51
134
|
textarea: {
|
|
52
135
|
editor: 'Umbraco.TextArea',
|
|
53
|
-
editorUi: '
|
|
136
|
+
editorUi: ui('TextArea'),
|
|
54
137
|
takes: ['rows', 'maxChars'],
|
|
55
|
-
|
|
138
|
+
whole: ['rows', 'maxChars'],
|
|
139
|
+
...plain((o) => defined({ rows: o.rows, maxChars: o.maxChars })),
|
|
56
140
|
},
|
|
57
141
|
'rich-text': {
|
|
58
142
|
editor: 'Umbraco.RichText',
|
|
59
|
-
editorUi: '
|
|
143
|
+
editorUi: ui('Tiptap'),
|
|
60
144
|
takes: ['block'],
|
|
61
145
|
build: (o) => ({ config: structuredClone(RICH_TEXT_CONFIG), blocks: blocks(o) }),
|
|
62
146
|
},
|
|
147
|
+
markdown: {
|
|
148
|
+
editor: 'Umbraco.MarkdownEditor',
|
|
149
|
+
editorUi: ui('MarkdownEditor'),
|
|
150
|
+
takes: ['preview'],
|
|
151
|
+
...plain((o) => defined({ preview: o.preview })),
|
|
152
|
+
},
|
|
153
|
+
code: {
|
|
154
|
+
editor: 'Umbraco.Plain.String',
|
|
155
|
+
editorUi: ui('CodeEditor'),
|
|
156
|
+
takes: ['language'],
|
|
157
|
+
build: (o) =>
|
|
158
|
+
o.language !== undefined && !CODE_LANGUAGES.includes(o.language)
|
|
159
|
+
? oneOf('--language', o.language, CODE_LANGUAGES)
|
|
160
|
+
: { config: defined({ language: o.language }) },
|
|
161
|
+
},
|
|
162
|
+
email: { editor: 'Umbraco.EmailAddress', editorUi: ui('EmailAddress'), takes: [], ...plain() },
|
|
63
163
|
number: {
|
|
64
164
|
editor: 'Umbraco.Integer',
|
|
65
|
-
editorUi: '
|
|
165
|
+
editorUi: ui('Integer'),
|
|
166
|
+
takes: ['min', 'max', 'step'],
|
|
167
|
+
whole: ['min', 'max', 'step'],
|
|
168
|
+
...plain((o) => defined({ min: o.min, max: o.max, step: o.step })),
|
|
169
|
+
},
|
|
170
|
+
decimal: {
|
|
171
|
+
editor: 'Umbraco.Decimal',
|
|
172
|
+
editorUi: ui('Decimal'),
|
|
66
173
|
takes: ['min', 'max', 'step'],
|
|
67
|
-
|
|
174
|
+
...plain((o) => defined({ min: o.min, max: o.max, step: o.step })),
|
|
175
|
+
},
|
|
176
|
+
slider: {
|
|
177
|
+
editor: 'Umbraco.Slider',
|
|
178
|
+
editorUi: ui('Slider'),
|
|
179
|
+
takes: ['min', 'max', 'step', 'range'],
|
|
180
|
+
...plain((o) => defined({ minVal: o.min, maxVal: o.max, step: o.step, enableRange: o.range })),
|
|
68
181
|
},
|
|
69
182
|
toggle: {
|
|
70
183
|
editor: 'Umbraco.TrueFalse',
|
|
71
|
-
editorUi: '
|
|
184
|
+
editorUi: ui('Toggle'),
|
|
72
185
|
takes: ['defaultOn', 'label'],
|
|
73
|
-
|
|
74
|
-
|
|
186
|
+
...plain((o) =>
|
|
187
|
+
defined({
|
|
75
188
|
default: o.defaultOn ? true : undefined,
|
|
76
189
|
showLabels: o.label ? true : undefined,
|
|
77
190
|
labelOn: o.label,
|
|
78
191
|
}),
|
|
79
|
-
|
|
192
|
+
),
|
|
80
193
|
},
|
|
81
194
|
date: {
|
|
82
195
|
editor: 'Umbraco.DateTime',
|
|
83
|
-
editorUi: '
|
|
196
|
+
editorUi: ui('DatePicker'),
|
|
84
197
|
takes: ['withTime'],
|
|
85
|
-
|
|
198
|
+
...plain((o) => ({ format: o.withTime ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD' })),
|
|
199
|
+
},
|
|
200
|
+
'date-with-zone': {
|
|
201
|
+
editor: 'Umbraco.DateTimeWithTimeZone',
|
|
202
|
+
editorUi: ui('DateTimeWithTimeZonePicker'),
|
|
203
|
+
takes: [],
|
|
204
|
+
...plain(),
|
|
205
|
+
},
|
|
206
|
+
'date-only': {
|
|
207
|
+
editor: 'Umbraco.DateOnly',
|
|
208
|
+
editorUi: ui('DateOnlyPicker'),
|
|
209
|
+
takes: [],
|
|
210
|
+
...plain(),
|
|
211
|
+
},
|
|
212
|
+
'time-only': {
|
|
213
|
+
editor: 'Umbraco.TimeOnly',
|
|
214
|
+
editorUi: ui('TimeOnlyPicker'),
|
|
215
|
+
takes: [],
|
|
216
|
+
...plain(),
|
|
217
|
+
},
|
|
218
|
+
'date-time': {
|
|
219
|
+
editor: 'Umbraco.DateTimeUnspecified',
|
|
220
|
+
editorUi: ui('DateTimePicker'),
|
|
221
|
+
takes: [],
|
|
222
|
+
...plain(),
|
|
86
223
|
},
|
|
87
224
|
dropdown: {
|
|
88
225
|
editor: 'Umbraco.DropDown.Flexible',
|
|
89
|
-
editorUi: '
|
|
226
|
+
editorUi: ui('Dropdown'),
|
|
90
227
|
takes: ['option', 'multiple'],
|
|
91
|
-
|
|
228
|
+
...plain((o) => ({ multiple: o.multiple === true, items: o.option ?? [] })),
|
|
229
|
+
},
|
|
230
|
+
'checkbox-list': {
|
|
231
|
+
editor: 'Umbraco.CheckBoxList',
|
|
232
|
+
editorUi: ui('CheckBoxList'),
|
|
233
|
+
takes: ['option'],
|
|
234
|
+
...plain((o) => defined({ items: o.option })),
|
|
235
|
+
},
|
|
236
|
+
'radio-list': {
|
|
237
|
+
editor: 'Umbraco.RadioButtonList',
|
|
238
|
+
editorUi: ui('RadioButtonList'),
|
|
239
|
+
takes: ['option'],
|
|
240
|
+
...plain((o) => defined({ items: o.option })),
|
|
241
|
+
},
|
|
242
|
+
tags: {
|
|
243
|
+
editor: 'Umbraco.Tags',
|
|
244
|
+
editorUi: ui('Tags'),
|
|
245
|
+
takes: ['group'],
|
|
246
|
+
...plain((o) => defined({ group: o.group })),
|
|
247
|
+
},
|
|
248
|
+
'multiple-text': {
|
|
249
|
+
editor: 'Umbraco.MultipleTextstring',
|
|
250
|
+
editorUi: ui('MultipleTextString'),
|
|
251
|
+
takes: ['min', 'max'],
|
|
252
|
+
whole: ['min', 'max'],
|
|
253
|
+
...plain((o) => defined({ min: o.min, max: o.max })),
|
|
254
|
+
},
|
|
255
|
+
'color-picker': {
|
|
256
|
+
editor: 'Umbraco.ColorPicker',
|
|
257
|
+
editorUi: ui('ColorPicker'),
|
|
258
|
+
takes: ['color'],
|
|
259
|
+
build: (o) => {
|
|
260
|
+
if (!o.color) return { config: {} }
|
|
261
|
+
const items = swatches(o.color)
|
|
262
|
+
if (typeof items === 'string') return items
|
|
263
|
+
const labelled = o.color.some((color) => color.includes('='))
|
|
264
|
+
return { config: { items, ...(labelled ? { useLabel: true } : {}) } }
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
'eye-dropper': {
|
|
268
|
+
editor: 'Umbraco.ColorPicker.EyeDropper',
|
|
269
|
+
editorUi: ui('EyeDropper'),
|
|
270
|
+
takes: ['alpha', 'palette'],
|
|
271
|
+
...plain((o) => defined({ showAlpha: o.alpha, showPalette: o.palette })),
|
|
92
272
|
},
|
|
93
273
|
'content-picker': {
|
|
94
274
|
editor: 'Umbraco.MultiNodeTreePicker',
|
|
95
|
-
editorUi: '
|
|
275
|
+
editorUi: ui('ContentPicker'),
|
|
276
|
+
takes: ['allow', 'of'],
|
|
277
|
+
build: (o) => {
|
|
278
|
+
const type = START_NODE_TYPES[o.of ?? 'pages']
|
|
279
|
+
if (!type) return oneOf('--of', String(o.of), Object.keys(START_NODE_TYPES))
|
|
280
|
+
return { config: defined({ startNode: { type }, filter: o.allow }) }
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
'document-picker': {
|
|
284
|
+
editor: 'Umbraco.ContentPicker',
|
|
285
|
+
editorUi: ui('DocumentPicker'),
|
|
96
286
|
takes: ['allow'],
|
|
97
|
-
|
|
98
|
-
config: defined({ startNode: { type: 'content' }, filter: o.allow }),
|
|
99
|
-
}),
|
|
287
|
+
...plain((o) => defined({ allowedContentTypes: o.allow })),
|
|
100
288
|
},
|
|
101
289
|
'media-picker': {
|
|
102
290
|
editor: 'Umbraco.MediaPicker3',
|
|
103
|
-
editorUi: '
|
|
291
|
+
editorUi: ui('MediaPicker'),
|
|
104
292
|
takes: ['allow', 'multiple', 'min', 'max'],
|
|
105
|
-
|
|
106
|
-
|
|
293
|
+
whole: ['min', 'max'],
|
|
294
|
+
...plain((o) =>
|
|
295
|
+
defined({
|
|
107
296
|
filter: o.allow,
|
|
108
297
|
multiple: o.multiple === true,
|
|
109
298
|
validationLimit: limit(o) ?? (o.multiple ? undefined : { min: 0, max: 1 }),
|
|
110
299
|
}),
|
|
111
|
-
|
|
300
|
+
),
|
|
301
|
+
},
|
|
302
|
+
'member-picker': {
|
|
303
|
+
editor: 'Umbraco.MemberPicker',
|
|
304
|
+
editorUi: ui('MemberPicker'),
|
|
305
|
+
takes: [],
|
|
306
|
+
...plain(),
|
|
307
|
+
},
|
|
308
|
+
'member-group-picker': {
|
|
309
|
+
editor: 'Umbraco.MemberGroupPicker',
|
|
310
|
+
editorUi: ui('MemberGroupPicker'),
|
|
311
|
+
takes: [],
|
|
312
|
+
...plain(),
|
|
313
|
+
},
|
|
314
|
+
'user-picker': {
|
|
315
|
+
editor: 'Umbraco.UserPicker',
|
|
316
|
+
editorUi: ui('UserPicker'),
|
|
317
|
+
takes: [],
|
|
318
|
+
...plain(),
|
|
319
|
+
},
|
|
320
|
+
// Its settings name the source the site's code adds, so they are given with --set.
|
|
321
|
+
'entity-data-picker': {
|
|
322
|
+
editor: 'Umbraco.EntityDataPicker',
|
|
323
|
+
editorUi: ui('EntityDataPicker'),
|
|
324
|
+
takes: [],
|
|
325
|
+
...plain(),
|
|
326
|
+
},
|
|
327
|
+
'multi-url-picker': {
|
|
328
|
+
editor: 'Umbraco.MultiUrlPicker',
|
|
329
|
+
editorUi: ui('MultiUrlPicker'),
|
|
330
|
+
takes: ['min', 'max'],
|
|
331
|
+
whole: ['min', 'max'],
|
|
332
|
+
...plain((o) => defined({ minNumber: o.min, maxNumber: o.max })),
|
|
112
333
|
},
|
|
113
334
|
'element-picker': {
|
|
114
335
|
editor: 'Umbraco.ElementPicker',
|
|
115
|
-
editorUi: '
|
|
336
|
+
editorUi: ui('ElementPicker'),
|
|
116
337
|
takes: ['allow'],
|
|
117
|
-
|
|
338
|
+
...plain((o) => defined({ allowedContentTypes: o.allow })),
|
|
339
|
+
},
|
|
340
|
+
upload: {
|
|
341
|
+
editor: 'Umbraco.UploadField',
|
|
342
|
+
editorUi: ui('UploadField'),
|
|
343
|
+
takes: ['extension'],
|
|
344
|
+
...plain((o) =>
|
|
345
|
+
defined({ fileExtensions: o.extension?.map((ext) => ext.trim().replace(/^\./, '')) }),
|
|
346
|
+
),
|
|
347
|
+
},
|
|
348
|
+
'image-cropper': {
|
|
349
|
+
editor: 'Umbraco.ImageCropper',
|
|
350
|
+
editorUi: ui('ImageCropper'),
|
|
351
|
+
takes: ['crop'],
|
|
352
|
+
build: (o) => {
|
|
353
|
+
if (!o.crop) return { config: {} }
|
|
354
|
+
const list = crops(o.crop)
|
|
355
|
+
return typeof list === 'string' ? list : { config: { crops: list } }
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
label: {
|
|
359
|
+
editor: 'Umbraco.Label',
|
|
360
|
+
editorUi: ui('Label'),
|
|
361
|
+
takes: ['valueType'],
|
|
362
|
+
build: (o) => {
|
|
363
|
+
const type = LABEL_VALUE_TYPES[o.valueType ?? 'string']
|
|
364
|
+
if (!type) return oneOf('--value-type', String(o.valueType), Object.keys(LABEL_VALUE_TYPES))
|
|
365
|
+
return { config: { umbracoDataValueType: type } }
|
|
366
|
+
},
|
|
118
367
|
},
|
|
119
368
|
'block-list': {
|
|
120
369
|
editor: 'Umbraco.BlockList',
|
|
121
|
-
editorUi: '
|
|
370
|
+
editorUi: ui('BlockList'),
|
|
122
371
|
takes: ['block', 'min', 'max'],
|
|
372
|
+
whole: ['min', 'max'],
|
|
123
373
|
build: (o) => ({ config: defined({ validationLimit: limit(o) }), blocks: blocks(o) }),
|
|
124
374
|
},
|
|
125
375
|
// One block: a page's one hero or call to action (story 345).
|
|
126
376
|
'single-block': {
|
|
127
377
|
editor: 'Umbraco.SingleBlock',
|
|
128
|
-
editorUi: '
|
|
378
|
+
editorUi: ui('BlockSingle'),
|
|
129
379
|
takes: ['block'],
|
|
130
380
|
build: (o) => ({ config: {}, blocks: blocks(o) }),
|
|
131
381
|
},
|
|
132
382
|
'block-grid': {
|
|
133
383
|
editor: 'Umbraco.BlockGrid',
|
|
134
|
-
editorUi: '
|
|
384
|
+
editorUi: ui('BlockGrid'),
|
|
135
385
|
takes: ['block', 'columns'],
|
|
386
|
+
whole: ['columns'],
|
|
136
387
|
build: (o) => ({ config: { gridColumns: o.columns ?? 12 }, blocks: blocks(o) }),
|
|
137
388
|
},
|
|
389
|
+
// What a content or media type shows its children in (`--list-view-type`).
|
|
390
|
+
'list-view': {
|
|
391
|
+
editor: 'Umbraco.ListView',
|
|
392
|
+
editorUi: ui('Collection'),
|
|
393
|
+
takes: [],
|
|
394
|
+
...plain(),
|
|
395
|
+
},
|
|
138
396
|
}
|
|
139
397
|
|
|
140
398
|
/** `maxChars` → `--max-chars`, for naming a flag in a refusal. */
|
|
@@ -146,42 +404,84 @@ export const PRESET_OPTIONS: readonly Option[] = [
|
|
|
146
404
|
...new Set(Object.values(DATA_TYPE_PRESETS).flatMap((p) => p.takes)),
|
|
147
405
|
]
|
|
148
406
|
|
|
407
|
+
const letters = (name: string) => name.toLowerCase().replace(/[^a-z0-9]/g, '')
|
|
408
|
+
|
|
409
|
+
/** The preset a name means: a preset's own name, or its editor's or editor UI's full name. */
|
|
410
|
+
export function findPreset(name: string): [string, Preset] | undefined {
|
|
411
|
+
const own = DATA_TYPE_PRESETS[name]
|
|
412
|
+
if (own) return [name, own]
|
|
413
|
+
const entries = Object.entries(DATA_TYPE_PRESETS)
|
|
414
|
+
return (
|
|
415
|
+
entries.find(([key]) => letters(key) === letters(name)) ??
|
|
416
|
+
entries.find(([, preset]) => preset.editorUi === name) ??
|
|
417
|
+
entries.find(([, preset]) => preset.editor === name)
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** The preset a data type's editor and UI are, when there is one. */
|
|
422
|
+
export function presetOf(editor: string, editorUi?: string): [string, Preset] | undefined {
|
|
423
|
+
const entries = Object.entries(DATA_TYPE_PRESETS)
|
|
424
|
+
return (
|
|
425
|
+
entries.find(([, p]) => p.editor === editor && editorUi && p.editorUi === editorUi) ??
|
|
426
|
+
entries.find(([, p]) => p.editor === editor && (!editorUi || !EDITOR_UIS[editorUi]))
|
|
427
|
+
)
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** Why a preset cannot take these options, or the config and blocks they give over its defaults. */
|
|
431
|
+
export function presetConfig(name: string, preset: Preset, options: PresetOptions): Built | string {
|
|
432
|
+
const given = (Object.keys(options) as Option[]).filter((o) => options[o] !== undefined)
|
|
433
|
+
const extra = given.filter((option) => !preset.takes.includes(option))
|
|
434
|
+
if (extra.length > 0) return `${name} does not take ${extra.map(optionFlag).join(', ')}`
|
|
435
|
+
const fraction = given.find(
|
|
436
|
+
(option) => preset.whole?.includes(option) && !Number.isInteger(options[option]),
|
|
437
|
+
)
|
|
438
|
+
if (fraction) return `${optionFlag(fraction)} takes a whole number for ${name}`
|
|
439
|
+
const built = preset.build(options)
|
|
440
|
+
if (typeof built === 'string') return built
|
|
441
|
+
return {
|
|
442
|
+
config: { ...editorDefaults(preset.editor, preset.editorUi), ...built.config },
|
|
443
|
+
...(built.blocks ? { blocks: built.blocks } : {}),
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
149
447
|
export type PresetResult = { ok: true; dataType: SchemaDataType } | { ok: false; reason: string }
|
|
150
448
|
|
|
151
|
-
/**
|
|
449
|
+
/** Every name `--editor` takes: the presets', then each editor's and editor UI's. */
|
|
450
|
+
export const EDITOR_NAMES: readonly string[] = [
|
|
451
|
+
...Object.keys(DATA_TYPE_PRESETS),
|
|
452
|
+
...Object.keys(EDITOR_SCHEMAS),
|
|
453
|
+
...Object.keys(EDITOR_UIS),
|
|
454
|
+
]
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* The data type a preset, or an editor's full name, and its options describe,
|
|
458
|
+
* with any `settings` over them; or why it cannot be built.
|
|
459
|
+
*/
|
|
152
460
|
export function presetDataType(
|
|
153
461
|
alias: string,
|
|
154
|
-
|
|
462
|
+
editor: string,
|
|
155
463
|
options: PresetOptions = {},
|
|
156
464
|
name?: string,
|
|
465
|
+
settings: Record<string, unknown> = {},
|
|
157
466
|
): PresetResult {
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
DATA_TYPE_PRESETS[preset] ??
|
|
161
|
-
Object.entries(DATA_TYPE_PRESETS).find(([key]) => letters(key) === letters(preset))?.[1]
|
|
162
|
-
if (!chosen)
|
|
163
|
-
return {
|
|
164
|
-
ok: false,
|
|
165
|
-
reason: `unknown editor "${preset}"; one of ${Object.keys(DATA_TYPE_PRESETS).join(', ')}`,
|
|
166
|
-
}
|
|
167
|
-
const extra = (Object.keys(options) as Option[]).filter(
|
|
168
|
-
(option) => options[option] !== undefined && !chosen.takes.includes(option),
|
|
169
|
-
)
|
|
170
|
-
if (extra.length > 0)
|
|
467
|
+
const found = findPreset(editor)
|
|
468
|
+
if (!found)
|
|
171
469
|
return {
|
|
172
470
|
ok: false,
|
|
173
|
-
reason:
|
|
471
|
+
reason: `unknown editor "${editor}"; did you mean ${closestNames(editor, EDITOR_NAMES).join(', ')}? \`types editors --all\` lists them all`,
|
|
174
472
|
}
|
|
175
|
-
const
|
|
473
|
+
const [presetName, preset] = found
|
|
474
|
+
const built = presetConfig(presetName, preset, options)
|
|
475
|
+
if (typeof built === 'string') return { ok: false, reason: built }
|
|
176
476
|
return {
|
|
177
477
|
ok: true,
|
|
178
478
|
dataType: {
|
|
179
479
|
alias,
|
|
180
480
|
name: name ?? nameFor(alias),
|
|
181
|
-
editor:
|
|
182
|
-
editorUi:
|
|
183
|
-
config,
|
|
184
|
-
...(blocks && blocks.length > 0 ? { blocks } : {}),
|
|
481
|
+
editor: preset.editor,
|
|
482
|
+
editorUi: preset.editorUi,
|
|
483
|
+
config: { ...built.config, ...settings },
|
|
484
|
+
...(built.blocks && built.blocks.length > 0 ? { blocks: built.blocks } : {}),
|
|
185
485
|
},
|
|
186
486
|
}
|
|
187
487
|
}
|
package/src/site-edit.ts
CHANGED
|
@@ -83,6 +83,9 @@ export interface UserGroupChanges {
|
|
|
83
83
|
allLanguages?: boolean
|
|
84
84
|
addLanguages?: readonly string[]
|
|
85
85
|
removeLanguages?: readonly string[]
|
|
86
|
+
/** Owners, by alias: for a file that names them (story 356). */
|
|
87
|
+
addOwners?: readonly string[]
|
|
88
|
+
removeOwners?: readonly string[]
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
const plus = (list: readonly string[], more: readonly string[] = []) => [
|
|
@@ -130,10 +133,17 @@ export function updateUserGroup(
|
|
|
130
133
|
if (typeof named === 'string') return { ok: false, reason: named }
|
|
131
134
|
languages = named
|
|
132
135
|
}
|
|
136
|
+
let owners = group.owners
|
|
137
|
+
if (changes.addOwners?.length || changes.removeOwners?.length) {
|
|
138
|
+
const named = minus(plus(owners ?? [], changes.addOwners), changes.removeOwners, 'owner')
|
|
139
|
+
if (typeof named === 'string') return { ok: false, reason: named }
|
|
140
|
+
owners = named
|
|
141
|
+
}
|
|
133
142
|
return {
|
|
134
143
|
ok: true,
|
|
135
144
|
group: {
|
|
136
145
|
...group,
|
|
146
|
+
...(owners !== undefined ? { owners } : {}),
|
|
137
147
|
...(changes.name !== undefined ? { name: changes.name } : {}),
|
|
138
148
|
...(changes.description !== undefined
|
|
139
149
|
? { description: changes.description || undefined }
|