@seamlet/astro 0.2.0 → 0.3.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/README.md +29 -0
- package/dist/bridge.d.ts +3 -3
- package/dist/bridge.js +2 -2
- package/dist/{chunk-2MRY5Z6U.js → chunk-AFTVM755.js} +178 -2
- package/dist/{chunk-LADJH7RU.js → chunk-N2UE3EQU.js} +1 -1
- package/dist/{content-CD5TXi4R.d.ts → content-GL5k9Mch.d.ts} +37 -6
- package/dist/{messages-BQSbv5YE.d.ts → messages-CJ8vKPs9.d.ts} +2 -2
- package/dist/{parse-content-CVoASb5i.d.ts → parse-content-CVU-pHrH.d.ts} +7 -2
- package/dist/protocol.d.ts +3 -3
- package/dist/protocol.js +2 -2
- package/dist/schema.d.ts +30 -6
- package/dist/schema.js +19 -3
- package/dist/site.d.ts +1 -1
- package/dist/site.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -90,6 +90,8 @@ The site's pages take their published content with `site.loadPublishedContent()`
|
|
|
90
90
|
| `toggle({ label })` | `true` or `false` | `false` |
|
|
91
91
|
| `choice({ label, options })` | the `value` of one option | `null` |
|
|
92
92
|
| `choices({ label, options })` | the `value`s of any number of options | `[]` |
|
|
93
|
+
| `reference({ label, collection })` | the `id` of a record of a collection of the schema | `null` |
|
|
94
|
+
| `references({ label, collection })` | the `id`s of any number of such records | `[]` |
|
|
93
95
|
| `group({ label, fields })` | named fields shown together | each field empty |
|
|
94
96
|
| `collection({ label, item, itemTitle? })` | a list of records of the same fields | `[]` |
|
|
95
97
|
|
|
@@ -113,6 +115,33 @@ item: { name: text({ label: "Название" }), isHidden: toggle({ label: "С
|
|
|
113
115
|
// content.practices.filter((practice) => !practice.isHidden)
|
|
114
116
|
```
|
|
115
117
|
|
|
118
|
+
## Records and references
|
|
119
|
+
|
|
120
|
+
Every record of a collection has an `id` of its own, which never changes when records move, so a record has no field named `id`. The CMS gives ids to records that have none (`withRecordIds`), so a site's initial content may leave them out, unless something refers to those records.
|
|
121
|
+
|
|
122
|
+
A reference points at a record of another collection by its id: the teacher of a practice is chosen from the teachers, so renaming the teacher changes every practice at once. `collection` is where the collection is, its name or a path through groups:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const schema = defineSchema({
|
|
126
|
+
teachers: collection({
|
|
127
|
+
label: "Преподаватели",
|
|
128
|
+
itemTitle: "name",
|
|
129
|
+
item: { name: text({ label: "Имя" }) },
|
|
130
|
+
}),
|
|
131
|
+
practices: collection({
|
|
132
|
+
label: "Практики",
|
|
133
|
+
itemTitle: "name",
|
|
134
|
+
item: {
|
|
135
|
+
name: text({ label: "Название" }),
|
|
136
|
+
teacher: reference({ label: "Ведёт", collection: "teachers" }),
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
// findRecord(content.teachers, practice.teacher)?.name
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
A reference to a record removed since is kept, with the issue `missing-record`: the content is not saved until the person picks another one or clears it.
|
|
144
|
+
|
|
116
145
|
## What the page hides
|
|
117
146
|
|
|
118
147
|
A field is edited where it is seen, so the editor opens what hides it when a person chooses it in the list of fields. A native `<details>` needs nothing: a click on its summary opens it in the editor too. A part the site hides and shows by itself (its own accordion, a step of a quiz, a dialog, a tab) gets the attribute `data-cms-reveal` (`REVEAL_ATTRIBUTE`). When a field inside it is chosen, the bridge sets `data-cms-revealed` on it and sends it the event `cms:reveal`, which bubbles; the site shows the part with CSS or with its own script:
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { F as Fields } from './content-
|
|
2
|
-
import { P as PageMessage, E as EditorMessage } from './messages-
|
|
3
|
-
import './parse-content-
|
|
1
|
+
import { F as Fields } from './content-GL5k9Mch.js';
|
|
2
|
+
import { P as PageMessage, E as EditorMessage } from './messages-CJ8vKPs9.js';
|
|
3
|
+
import './parse-content-CVU-pHrH.js';
|
|
4
4
|
|
|
5
5
|
interface BridgeOptions {
|
|
6
6
|
/** The origin of the CMS whose editor may frame the page, such as `https://cms.example.com`. */
|
package/dist/bridge.js
CHANGED
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
imageFieldAt,
|
|
6
6
|
readEditorMessage,
|
|
7
7
|
shortcutOf
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-N2UE3EQU.js";
|
|
9
9
|
import {
|
|
10
10
|
FIELD_PATH_ATTRIBUTE,
|
|
11
11
|
REVEALED_ATTRIBUTE,
|
|
12
12
|
REVEAL_ATTRIBUTE,
|
|
13
13
|
REVEAL_EVENT
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-AFTVM755.js";
|
|
15
15
|
|
|
16
16
|
// src/bridge/page-markers.ts
|
|
17
17
|
var MARKER_SELECTOR = `[${FIELD_PATH_ATTRIBUTE}]`;
|
|
@@ -32,6 +32,12 @@ function url(options) {
|
|
|
32
32
|
function time(options) {
|
|
33
33
|
return { kind: "time", ...options };
|
|
34
34
|
}
|
|
35
|
+
function reference(options) {
|
|
36
|
+
return { kind: "reference", ...options };
|
|
37
|
+
}
|
|
38
|
+
function references(options) {
|
|
39
|
+
return { kind: "references", ...options };
|
|
40
|
+
}
|
|
35
41
|
function group(options) {
|
|
36
42
|
return { kind: "group", ...options };
|
|
37
43
|
}
|
|
@@ -47,6 +53,7 @@ function defaultValue(field) {
|
|
|
47
53
|
case "toggle":
|
|
48
54
|
return false;
|
|
49
55
|
case "choices":
|
|
56
|
+
case "references":
|
|
50
57
|
return [];
|
|
51
58
|
case "number":
|
|
52
59
|
case "date":
|
|
@@ -55,6 +62,7 @@ function defaultValue(field) {
|
|
|
55
62
|
case "choice":
|
|
56
63
|
case "url":
|
|
57
64
|
case "time":
|
|
65
|
+
case "reference":
|
|
58
66
|
return null;
|
|
59
67
|
case "group":
|
|
60
68
|
return defaultContent(field.fields);
|
|
@@ -139,6 +147,132 @@ function withoutPrefix(address, prefix) {
|
|
|
139
147
|
return hasPrefix ? address.slice(prefix.length) : void 0;
|
|
140
148
|
}
|
|
141
149
|
|
|
150
|
+
// src/schema/record-ids.ts
|
|
151
|
+
var RECORD_ID_KEY = "id";
|
|
152
|
+
var RECORD_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/u;
|
|
153
|
+
function isRecordId(value) {
|
|
154
|
+
return typeof value === "string" && RECORD_ID_PATTERN.test(value);
|
|
155
|
+
}
|
|
156
|
+
function newRecord(collection2, id) {
|
|
157
|
+
return { ...defaultContent(collection2.item), [RECORD_ID_KEY]: id };
|
|
158
|
+
}
|
|
159
|
+
function withRecordIds(schema, content, newId) {
|
|
160
|
+
return withIdsInFields(schema, content, newId);
|
|
161
|
+
}
|
|
162
|
+
var COLLECTION_PATH_SEPARATOR = ".";
|
|
163
|
+
function collectionAt(schema, content, path) {
|
|
164
|
+
return collectionIn(schema, content, path.split(COLLECTION_PATH_SEPARATOR));
|
|
165
|
+
}
|
|
166
|
+
function collectionIn(fields, content, names) {
|
|
167
|
+
const [name, ...rest] = names;
|
|
168
|
+
const field = name !== void 0 && Object.hasOwn(fields, name) ? fields[name] : void 0;
|
|
169
|
+
if (name === void 0 || field === void 0) return void 0;
|
|
170
|
+
const value = content[name];
|
|
171
|
+
if (rest.length === 0 && field.kind === "collection") {
|
|
172
|
+
const records = Array.isArray(value) ? value.filter(isContent) : [];
|
|
173
|
+
return { collection: field, records };
|
|
174
|
+
}
|
|
175
|
+
if (rest.length > 0 && field.kind === "group" && isContent(value)) {
|
|
176
|
+
return collectionIn(field.fields, value, rest);
|
|
177
|
+
}
|
|
178
|
+
return void 0;
|
|
179
|
+
}
|
|
180
|
+
function findRecord(records, id) {
|
|
181
|
+
if (id === null) return void 0;
|
|
182
|
+
return records.find((record) => record.id === id);
|
|
183
|
+
}
|
|
184
|
+
function withIdsInFields(fields, content, newId) {
|
|
185
|
+
const entries = Object.entries(content).map(([name, value]) => {
|
|
186
|
+
const field = Object.hasOwn(fields, name) ? fields[name] : void 0;
|
|
187
|
+
return [name, field === void 0 ? value : withIdsIn(field, value, newId)];
|
|
188
|
+
});
|
|
189
|
+
return Object.fromEntries(entries);
|
|
190
|
+
}
|
|
191
|
+
function withIdsIn(field, value, newId) {
|
|
192
|
+
if (field.kind === "group" && isContent(value)) {
|
|
193
|
+
return withIdsInFields(field.fields, value, newId);
|
|
194
|
+
}
|
|
195
|
+
if (field.kind === "collection" && Array.isArray(value)) {
|
|
196
|
+
return withIdsInRecords(field, value.filter(isContent), newId);
|
|
197
|
+
}
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
function withIdsInRecords(collection2, records, newId) {
|
|
201
|
+
const taken = /* @__PURE__ */ new Set();
|
|
202
|
+
return records.map((record) => {
|
|
203
|
+
const own = record[RECORD_ID_KEY];
|
|
204
|
+
const isOwnFree = isRecordId(own) && !taken.has(own);
|
|
205
|
+
const id = isOwnFree ? own : newId();
|
|
206
|
+
taken.add(id);
|
|
207
|
+
const fields = withIdsInFields(collection2.item, record, newId);
|
|
208
|
+
return { ...fields, [RECORD_ID_KEY]: id };
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function isContent(value) {
|
|
212
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/schema/reference-checks.ts
|
|
216
|
+
function missingRecordIssues(schema, content) {
|
|
217
|
+
const idsOf = (collection2) => recordIdsAt(schema, content, collection2);
|
|
218
|
+
return issuesInFields(schema, content, [], idsOf);
|
|
219
|
+
}
|
|
220
|
+
function issuesInFields(fields, content, path, idsOf) {
|
|
221
|
+
return Object.entries(fields).flatMap(
|
|
222
|
+
([name, field]) => issuesInField(field, content[name], [...path, name], idsOf)
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
function issuesInField(field, value, path, idsOf) {
|
|
226
|
+
switch (field.kind) {
|
|
227
|
+
case "reference":
|
|
228
|
+
return missingIds(
|
|
229
|
+
typeof value === "string" ? [value] : [],
|
|
230
|
+
field,
|
|
231
|
+
path,
|
|
232
|
+
idsOf
|
|
233
|
+
);
|
|
234
|
+
case "references":
|
|
235
|
+
return missingIds(stringsOf(value), field, path, idsOf);
|
|
236
|
+
case "group":
|
|
237
|
+
return isContent2(value) ? issuesInFields(field.fields, value, path, idsOf) : [];
|
|
238
|
+
case "collection":
|
|
239
|
+
return recordsOf(value).flatMap(
|
|
240
|
+
(record, index) => issuesInFields(field.item, record, [...path, index], idsOf)
|
|
241
|
+
);
|
|
242
|
+
case "text":
|
|
243
|
+
case "number":
|
|
244
|
+
case "date":
|
|
245
|
+
case "image":
|
|
246
|
+
case "link":
|
|
247
|
+
case "toggle":
|
|
248
|
+
case "choice":
|
|
249
|
+
case "choices":
|
|
250
|
+
case "url":
|
|
251
|
+
case "time":
|
|
252
|
+
return [];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function missingIds(ids, field, path, idsOf) {
|
|
256
|
+
const known = idsOf(field.collection);
|
|
257
|
+
const missing = ids.filter((id) => !known.has(id));
|
|
258
|
+
return missing.map((id) => ({ path, code: "missing-record", id }));
|
|
259
|
+
}
|
|
260
|
+
function recordIdsAt(schema, content, path) {
|
|
261
|
+
const records = collectionAt(schema, content, path)?.records ?? [];
|
|
262
|
+
const ids = records.map((record) => record[RECORD_ID_KEY]);
|
|
263
|
+
return new Set(ids.filter((id) => typeof id === "string"));
|
|
264
|
+
}
|
|
265
|
+
function recordsOf(value) {
|
|
266
|
+
return Array.isArray(value) ? value.filter(isContent2) : [];
|
|
267
|
+
}
|
|
268
|
+
function stringsOf(value) {
|
|
269
|
+
const list = Array.isArray(value) ? value : [];
|
|
270
|
+
return list.filter((id) => typeof id === "string");
|
|
271
|
+
}
|
|
272
|
+
function isContent2(value) {
|
|
273
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
274
|
+
}
|
|
275
|
+
|
|
142
276
|
// src/schema/parse-content.ts
|
|
143
277
|
var DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/u;
|
|
144
278
|
var TIME_PATTERN = /^(?:[01]\d|2[0-3]):[0-5]\d$/u;
|
|
@@ -151,7 +285,11 @@ function countCharacters(text2) {
|
|
|
151
285
|
}
|
|
152
286
|
function parseContent(schema, input) {
|
|
153
287
|
const parsed = parseFields(schema, input, []);
|
|
154
|
-
|
|
288
|
+
const missingRecords = missingRecordIssues(schema, parsed.value);
|
|
289
|
+
return {
|
|
290
|
+
content: parsed.value,
|
|
291
|
+
issues: [...parsed.issues, ...missingRecords]
|
|
292
|
+
};
|
|
155
293
|
}
|
|
156
294
|
function parseFields(fields, input, path) {
|
|
157
295
|
if (!isRecord(input)) {
|
|
@@ -192,6 +330,10 @@ function parseField(field, input, path) {
|
|
|
192
330
|
return parseUrl(field, input, path);
|
|
193
331
|
case "time":
|
|
194
332
|
return parseTime(field, input, path);
|
|
333
|
+
case "reference":
|
|
334
|
+
return parseReference(field, input, path);
|
|
335
|
+
case "references":
|
|
336
|
+
return parseReferences(field, input, path);
|
|
195
337
|
case "group":
|
|
196
338
|
return parseFields(field.fields, input, path);
|
|
197
339
|
case "collection":
|
|
@@ -346,13 +488,39 @@ function parseCollection(field, input, path) {
|
|
|
346
488
|
}
|
|
347
489
|
const records = input;
|
|
348
490
|
const parsedRecords = records.map(
|
|
349
|
-
(record, index) =>
|
|
491
|
+
(record, index) => parseRecord(field, record, [...path, index])
|
|
350
492
|
);
|
|
351
493
|
return {
|
|
352
494
|
value: parsedRecords.map((parsed) => parsed.value),
|
|
353
495
|
issues: parsedRecords.flatMap((parsed) => parsed.issues)
|
|
354
496
|
};
|
|
355
497
|
}
|
|
498
|
+
function parseRecord(field, input, path) {
|
|
499
|
+
const parsed = parseFields(field.item, input, path);
|
|
500
|
+
const id = isRecord(input) ? input[RECORD_ID_KEY] : void 0;
|
|
501
|
+
if (!isRecordId(id)) return parsed;
|
|
502
|
+
return {
|
|
503
|
+
value: { ...parsed.value, [RECORD_ID_KEY]: id },
|
|
504
|
+
issues: parsed.issues
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
function parseReference(field, input, path) {
|
|
508
|
+
if (input === null) {
|
|
509
|
+
return valid(null);
|
|
510
|
+
}
|
|
511
|
+
if (!isRecordId(input)) {
|
|
512
|
+
return invalidType(defaultValue(field), path);
|
|
513
|
+
}
|
|
514
|
+
return valid(input);
|
|
515
|
+
}
|
|
516
|
+
function parseReferences(field, input, path) {
|
|
517
|
+
const isListOfIds = Array.isArray(input) && input.every((id) => isRecordId(id));
|
|
518
|
+
if (!isListOfIds) {
|
|
519
|
+
return invalidType(defaultValue(field), path);
|
|
520
|
+
}
|
|
521
|
+
const ids = [...new Set(input)];
|
|
522
|
+
return valid(ids);
|
|
523
|
+
}
|
|
356
524
|
function isCalendarDate(value) {
|
|
357
525
|
if (!DATE_PATTERN.test(value)) {
|
|
358
526
|
return false;
|
|
@@ -432,12 +600,20 @@ export {
|
|
|
432
600
|
choices,
|
|
433
601
|
url,
|
|
434
602
|
time,
|
|
603
|
+
reference,
|
|
604
|
+
references,
|
|
435
605
|
group,
|
|
436
606
|
collection,
|
|
437
607
|
defaultValue,
|
|
438
608
|
defaultContent,
|
|
439
609
|
linkTargetOf,
|
|
440
610
|
hrefOf,
|
|
611
|
+
RECORD_ID_KEY,
|
|
612
|
+
isRecordId,
|
|
613
|
+
newRecord,
|
|
614
|
+
withRecordIds,
|
|
615
|
+
collectionAt,
|
|
616
|
+
findRecord,
|
|
441
617
|
formatFieldPath,
|
|
442
618
|
countCharacters,
|
|
443
619
|
parseContent,
|
|
@@ -64,26 +64,48 @@ interface TimeField {
|
|
|
64
64
|
readonly kind: "time";
|
|
65
65
|
readonly label: string;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* A record of a collection of the schema, by its id: the teacher of a practice. `collection` is
|
|
69
|
+
* where that collection is, its name or a path through groups: "teachers", "studio.teachers".
|
|
70
|
+
*/
|
|
71
|
+
interface ReferenceField {
|
|
72
|
+
readonly kind: "reference";
|
|
73
|
+
readonly label: string;
|
|
74
|
+
readonly collection: string;
|
|
75
|
+
}
|
|
76
|
+
/** Any number of records of a collection of the schema, by their ids: the practices a teacher leads. */
|
|
77
|
+
interface ReferencesField {
|
|
78
|
+
readonly kind: "references";
|
|
79
|
+
readonly label: string;
|
|
80
|
+
readonly collection: string;
|
|
81
|
+
}
|
|
67
82
|
/** Named fields shown and stored together, for example the first screen of a page. */
|
|
68
83
|
interface GroupField<F extends Fields = Fields> {
|
|
69
84
|
readonly kind: "group";
|
|
70
85
|
readonly label: string;
|
|
71
86
|
readonly fields: F;
|
|
72
87
|
}
|
|
73
|
-
/**
|
|
74
|
-
|
|
88
|
+
/**
|
|
89
|
+
* A list of records of the same shape, for example the items of a menu. Every record also has an
|
|
90
|
+
* `id` of its own, which never changes (see withRecordIds), so a record has no field named `id`.
|
|
91
|
+
*/
|
|
92
|
+
interface CollectionField<F extends RecordFields = RecordFields> {
|
|
75
93
|
readonly kind: "collection";
|
|
76
94
|
readonly label: string;
|
|
77
95
|
readonly item: F;
|
|
78
96
|
/** The field of a record that names it in the editor: a text field, or a link by its text. */
|
|
79
97
|
readonly itemTitle?: keyof F & string;
|
|
80
98
|
}
|
|
81
|
-
type Field = TextField | NumberField | DateField | ImageField | LinkField | ToggleField | ChoiceField | ChoicesField | UrlField | TimeField | GroupField | CollectionField;
|
|
99
|
+
type Field = TextField | NumberField | DateField | ImageField | LinkField | ToggleField | ChoiceField | ChoicesField | UrlField | TimeField | ReferenceField | ReferencesField | GroupField | CollectionField;
|
|
82
100
|
type FieldKind = Field["kind"];
|
|
83
101
|
/** Field names to fields; the order of the keys is the order of the form. */
|
|
84
102
|
interface Fields {
|
|
85
103
|
readonly [name: string]: Field;
|
|
86
104
|
}
|
|
105
|
+
/** The fields of a record of a collection: any fields but `id`, which is the record's own. */
|
|
106
|
+
type RecordFields = Fields & {
|
|
107
|
+
readonly id?: never;
|
|
108
|
+
};
|
|
87
109
|
type FieldOptions<F extends Field> = Omit<F, "kind">;
|
|
88
110
|
/** The root of a site's schema. Only checks the shape and keeps the literal types. */
|
|
89
111
|
declare function defineSchema<F extends Fields>(fields: F): F;
|
|
@@ -98,8 +120,10 @@ declare function choice<const O extends readonly ChoiceOption[]>(options: FieldO
|
|
|
98
120
|
declare function choices<const O extends readonly ChoiceOption[]>(options: FieldOptions<ChoicesField<O>>): ChoicesField<O>;
|
|
99
121
|
declare function url(options: FieldOptions<UrlField>): UrlField;
|
|
100
122
|
declare function time(options: FieldOptions<TimeField>): TimeField;
|
|
123
|
+
declare function reference(options: FieldOptions<ReferenceField>): ReferenceField;
|
|
124
|
+
declare function references(options: FieldOptions<ReferencesField>): ReferencesField;
|
|
101
125
|
declare function group<F extends Fields>(options: FieldOptions<GroupField<F>>): GroupField<F>;
|
|
102
|
-
declare function collection<F extends
|
|
126
|
+
declare function collection<F extends RecordFields>(options: FieldOptions<CollectionField<F>>): CollectionField<F>;
|
|
103
127
|
|
|
104
128
|
interface ImageValue {
|
|
105
129
|
readonly src: string;
|
|
@@ -114,7 +138,14 @@ interface LinkValue {
|
|
|
114
138
|
* The value of each field. A text can be empty (""), the other scalar fields can be unset (null):
|
|
115
139
|
* content is filled in by people, so a site must be ready for a missing price or date.
|
|
116
140
|
*/
|
|
117
|
-
type ValueOf<F extends Field> = F extends TextField ? string : F extends NumberField ? number | null : F extends DateField ? string | null : F extends ImageField ? ImageValue | null : F extends LinkField ? LinkValue | null : F extends ToggleField ? boolean : F extends ChoiceField<infer Options> ? OptionValue<Options> | null : F extends ChoicesField<infer Options> ? readonly OptionValue<Options>[] : F extends UrlField ? string | null : F extends TimeField ? string | null : F extends GroupField<infer Group> ? ContentOf<Group> : F extends CollectionField<infer Item> ? readonly
|
|
141
|
+
type ValueOf<F extends Field> = F extends TextField ? string : F extends NumberField ? number | null : F extends DateField ? string | null : F extends ImageField ? ImageValue | null : F extends LinkField ? LinkValue | null : F extends ToggleField ? boolean : F extends ChoiceField<infer Options> ? OptionValue<Options> | null : F extends ChoicesField<infer Options> ? readonly OptionValue<Options>[] : F extends UrlField ? string | null : F extends TimeField ? string | null : F extends ReferenceField ? string | null : F extends ReferencesField ? readonly string[] : F extends GroupField<infer Group> ? ContentOf<Group> : F extends CollectionField<infer Item> ? readonly RecordOf<Item>[] : never;
|
|
142
|
+
/**
|
|
143
|
+
* A record of a collection: its fields and its id. The id is missing only in content no editor has
|
|
144
|
+
* saved yet, such as a site's initial content (see withRecordIds).
|
|
145
|
+
*/
|
|
146
|
+
type RecordOf<F extends RecordFields> = ContentOf<F> & {
|
|
147
|
+
readonly id?: string;
|
|
148
|
+
};
|
|
118
149
|
/** The values a list of options stores: `"soft" | "active"` for options with those values. */
|
|
119
150
|
type OptionValue<O extends readonly ChoiceOption[]> = O[number]["value"];
|
|
120
151
|
/** The content a schema describes: `ContentOf<typeof schema>` is the type a site renders. */
|
|
@@ -129,4 +160,4 @@ type FieldValue = string | number | boolean | null | readonly string[] | ImageVa
|
|
|
129
160
|
declare function defaultValue(field: Field): FieldValue;
|
|
130
161
|
declare function defaultContent(fields: Fields): Content;
|
|
131
162
|
|
|
132
|
-
export {
|
|
163
|
+
export { reference as A, references as B, type ContentOf as C, type DateField as D, text as E, type Fields as F, type GroupField as G, time as H, type ImageField as I, toggle as J, url as K, type LinkValue as L, type NumberField as N, type OptionValue as O, type RecordFields as R, type TextField as T, type UrlField as U, type ValueOf as V, type Content as a, type ImageValue as b, type Field as c, type CollectionField as d, type ChoiceField as e, type ChoiceOption as f, type ChoicesField as g, type FieldKind as h, type FieldValue as i, type LinkField as j, type RecordOf as k, type ReferenceField as l, type ReferencesField as m, type TimeField as n, type ToggleField as o, choice as p, choices as q, collection as r, date as s, defaultContent as t, defaultValue as u, defineSchema as v, group as w, image as x, link as y, number as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as Fields, a as Content } from './content-
|
|
2
|
-
import { F as FieldPath } from './parse-content-
|
|
1
|
+
import { F as Fields, a as Content } from './content-GL5k9Mch.js';
|
|
2
|
+
import { F as FieldPath } from './parse-content-CVU-pHrH.js';
|
|
3
3
|
|
|
4
4
|
interface Box {
|
|
5
5
|
readonly top: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as Fields, C as ContentOf } from './content-
|
|
1
|
+
import { F as Fields, C as ContentOf } from './content-GL5k9Mch.js';
|
|
2
2
|
|
|
3
3
|
/** Where a value lives in the content: field names and, inside a collection, record indexes. */
|
|
4
4
|
type FieldPath = readonly (string | number)[];
|
|
@@ -39,6 +39,10 @@ type ContentIssue = {
|
|
|
39
39
|
readonly path: FieldPath;
|
|
40
40
|
readonly code: "unknown-choice";
|
|
41
41
|
readonly value: string;
|
|
42
|
+
} | {
|
|
43
|
+
readonly path: FieldPath;
|
|
44
|
+
readonly code: "missing-record";
|
|
45
|
+
readonly id: string;
|
|
42
46
|
};
|
|
43
47
|
interface ParsedContent<C> {
|
|
44
48
|
readonly content: C;
|
|
@@ -56,7 +60,8 @@ declare function countCharacters(text: string): number;
|
|
|
56
60
|
* - a value of the wrong type or format gets the default too, and an issue;
|
|
57
61
|
* - a value of the right type that breaks a rule of its field (too long, below the minimum) is
|
|
58
62
|
* kept, with an issue: nothing a person typed is lost;
|
|
59
|
-
* - keys the schema does not know are dropped
|
|
63
|
+
* - keys the schema does not know are dropped; a record keeps its id (see withRecordIds);
|
|
64
|
+
* - a reference to a record its collection does not have (removed since) is kept, with an issue.
|
|
60
65
|
* Content with issues is valid to show and edit, but not to save.
|
|
61
66
|
*/
|
|
62
67
|
declare function parseContent<F extends Fields>(schema: F, input: unknown): ParsedContent<ContentOf<F>>;
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { B as Box, a as EditorKey, E as EditorMessage, I as InlineEditingOutcome, L as LinkBox, M as MarkerBox, b as PROTOCOL_VERSION, c as PageLayout, P as PageMessage, d as Point, S as Shortcut, V as Viewport, r as readEditorMessage, e as readPageMessage, s as shortcutOf } from './messages-
|
|
2
|
-
import { F as Fields, I as ImageField } from './content-
|
|
3
|
-
import { F as FieldPath } from './parse-content-
|
|
1
|
+
export { B as Box, a as EditorKey, E as EditorMessage, I as InlineEditingOutcome, L as LinkBox, M as MarkerBox, b as PROTOCOL_VERSION, c as PageLayout, P as PageMessage, d as Point, S as Shortcut, V as Viewport, r as readEditorMessage, e as readPageMessage, s as shortcutOf } from './messages-CJ8vKPs9.js';
|
|
2
|
+
import { F as Fields, I as ImageField } from './content-GL5k9Mch.js';
|
|
3
|
+
import { F as FieldPath } from './parse-content-CVU-pHrH.js';
|
|
4
4
|
|
|
5
5
|
declare function carriesFiles(event: DragEvent): boolean;
|
|
6
6
|
|
package/dist/protocol.js
CHANGED
package/dist/schema.d.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { b as ImageValue, L as LinkValue, c as Field, d as CollectionField, F as Fields } from './content-
|
|
2
|
-
export { e as ChoiceField, f as ChoiceOption, g as ChoicesField,
|
|
3
|
-
import { F as FieldPath } from './parse-content-
|
|
4
|
-
export { C as ContentIssue, P as ParsedContent, c as countCharacters, f as formatFieldPath, p as parseContent } from './parse-content-
|
|
1
|
+
import { b as ImageValue, L as LinkValue, c as Field, d as CollectionField, F as Fields, a as Content, R as RecordFields, C as ContentOf } from './content-GL5k9Mch.js';
|
|
2
|
+
export { e as ChoiceField, f as ChoiceOption, g as ChoicesField, D as DateField, h as FieldKind, i as FieldValue, G as GroupField, I as ImageField, j as LinkField, N as NumberField, O as OptionValue, k as RecordOf, l as ReferenceField, m as ReferencesField, T as TextField, n as TimeField, o as ToggleField, U as UrlField, V as ValueOf, p as choice, q as choices, r as collection, s as date, t as defaultContent, u as defaultValue, v as defineSchema, w as group, x as image, y as link, z as number, A as reference, B as references, E as text, H as time, J as toggle, K as url } from './content-GL5k9Mch.js';
|
|
3
|
+
import { F as FieldPath } from './parse-content-CVU-pHrH.js';
|
|
4
|
+
export { C as ContentIssue, P as ParsedContent, c as countCharacters, f as formatFieldPath, p as parseContent } from './parse-content-CVU-pHrH.js';
|
|
5
5
|
|
|
6
6
|
declare const FIELD_PATH_ATTRIBUTE = "data-cms-path";
|
|
7
7
|
interface FieldMarker {
|
|
8
8
|
readonly [FIELD_PATH_ATTRIBUTE]: string;
|
|
9
9
|
}
|
|
10
|
+
type Leaf = string | number | boolean | null | ImageValue | LinkValue | readonly string[];
|
|
10
11
|
/**
|
|
11
12
|
* Every path in content of type C, as a tuple: ["hero"], ["hero", "title"], ["menu", 2],
|
|
12
13
|
* ["menu", 2, "price"]. Scalars, images and links are leaves: an image is one field, not two.
|
|
13
14
|
*/
|
|
14
|
-
type ContentPath<C> = C extends readonly (infer Record)[] ? [number] | [number, ...ContentPath<Record>] :
|
|
15
|
+
type ContentPath<C> = C extends Leaf ? never : C extends readonly (infer Record)[] ? [number] | [number, ...ContentPath<Record>] : {
|
|
15
16
|
[Name in keyof C & string]: [Name] | [Name, ...ContentPath<C[Name]>];
|
|
16
17
|
}[keyof C & string];
|
|
17
18
|
/**
|
|
@@ -39,6 +40,29 @@ type FieldTarget = {
|
|
|
39
40
|
*/
|
|
40
41
|
declare function resolveFieldPath(schema: Fields, text: string): FieldTarget | undefined;
|
|
41
42
|
|
|
43
|
+
declare const RECORD_ID_KEY = "id";
|
|
44
|
+
declare function isRecordId(value: unknown): value is string;
|
|
45
|
+
/** A new record of a collection: its fields empty, its id the given one. */
|
|
46
|
+
declare function newRecord<F extends RecordFields>(collection: CollectionField<F>, id: string): Content;
|
|
47
|
+
/**
|
|
48
|
+
* The content with an id given to every record that has none, and a new one to a record whose id
|
|
49
|
+
* another record of its collection already has (a copy). Records with ids of their own keep them.
|
|
50
|
+
*/
|
|
51
|
+
declare function withRecordIds<F extends Fields>(schema: F, content: ContentOf<F>, newId: () => string): ContentOf<F>;
|
|
52
|
+
interface CollectionRecords {
|
|
53
|
+
readonly collection: CollectionField;
|
|
54
|
+
readonly records: readonly Content[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The collection a reference points at, `"teachers"` or `"studio.teachers"` through groups, with
|
|
58
|
+
* its records in the content; undefined when the schema has no collection there.
|
|
59
|
+
*/
|
|
60
|
+
declare function collectionAt(schema: Fields, content: Content, path: string): CollectionRecords | undefined;
|
|
61
|
+
/** The record of the list with the id, if it is there. */
|
|
62
|
+
declare function findRecord<R extends {
|
|
63
|
+
readonly id?: string;
|
|
64
|
+
}>(records: readonly R[], id: string | null): R | undefined;
|
|
65
|
+
|
|
42
66
|
/** On the element the site hides and shows itself: `<div data-cms-reveal hidden>`. */
|
|
43
67
|
declare const REVEAL_ATTRIBUTE = "data-cms-reveal";
|
|
44
68
|
/** Set by the bridge on a part it revealed; a site can show it with CSS alone. */
|
|
@@ -72,4 +96,4 @@ declare function linkTargetOf(href: string): LinkTarget | undefined;
|
|
|
72
96
|
*/
|
|
73
97
|
declare function hrefOf(target: LinkTarget): string;
|
|
74
98
|
|
|
75
|
-
export { CollectionField, type ContentPath, FIELD_PATH_ATTRIBUTE, Field, type FieldMarker, FieldPath, type FieldTarget, Fields, ImageValue, type LinkKind, type LinkTarget, LinkValue, REVEALED_ATTRIBUTE, REVEAL_ATTRIBUTE, REVEAL_EVENT, editable, hrefOf, linkTargetOf, resolveFieldPath };
|
|
99
|
+
export { CollectionField, type CollectionRecords, Content, ContentOf, type ContentPath, FIELD_PATH_ATTRIBUTE, Field, type FieldMarker, FieldPath, type FieldTarget, Fields, ImageValue, type LinkKind, type LinkTarget, LinkValue, RECORD_ID_KEY, REVEALED_ATTRIBUTE, REVEAL_ATTRIBUTE, REVEAL_EVENT, RecordFields, collectionAt, editable, findRecord, hrefOf, isRecordId, linkTargetOf, newRecord, resolveFieldPath, withRecordIds };
|
package/dist/schema.js
CHANGED
|
@@ -1,56 +1,72 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FIELD_PATH_ATTRIBUTE,
|
|
3
|
+
RECORD_ID_KEY,
|
|
3
4
|
REVEALED_ATTRIBUTE,
|
|
4
5
|
REVEAL_ATTRIBUTE,
|
|
5
6
|
REVEAL_EVENT,
|
|
6
7
|
choice,
|
|
7
8
|
choices,
|
|
8
9
|
collection,
|
|
10
|
+
collectionAt,
|
|
9
11
|
countCharacters,
|
|
10
12
|
date,
|
|
11
13
|
defaultContent,
|
|
12
14
|
defaultValue,
|
|
13
15
|
defineSchema,
|
|
14
16
|
editable,
|
|
17
|
+
findRecord,
|
|
15
18
|
formatFieldPath,
|
|
16
19
|
group,
|
|
17
20
|
hrefOf,
|
|
18
21
|
image,
|
|
22
|
+
isRecordId,
|
|
19
23
|
link,
|
|
20
24
|
linkTargetOf,
|
|
25
|
+
newRecord,
|
|
21
26
|
number,
|
|
22
27
|
parseContent,
|
|
28
|
+
reference,
|
|
29
|
+
references,
|
|
23
30
|
resolveFieldPath,
|
|
24
31
|
text,
|
|
25
32
|
time,
|
|
26
33
|
toggle,
|
|
27
|
-
url
|
|
28
|
-
|
|
34
|
+
url,
|
|
35
|
+
withRecordIds
|
|
36
|
+
} from "./chunk-AFTVM755.js";
|
|
29
37
|
export {
|
|
30
38
|
FIELD_PATH_ATTRIBUTE,
|
|
39
|
+
RECORD_ID_KEY,
|
|
31
40
|
REVEALED_ATTRIBUTE,
|
|
32
41
|
REVEAL_ATTRIBUTE,
|
|
33
42
|
REVEAL_EVENT,
|
|
34
43
|
choice,
|
|
35
44
|
choices,
|
|
36
45
|
collection,
|
|
46
|
+
collectionAt,
|
|
37
47
|
countCharacters,
|
|
38
48
|
date,
|
|
39
49
|
defaultContent,
|
|
40
50
|
defaultValue,
|
|
41
51
|
defineSchema,
|
|
42
52
|
editable,
|
|
53
|
+
findRecord,
|
|
43
54
|
formatFieldPath,
|
|
44
55
|
group,
|
|
45
56
|
hrefOf,
|
|
46
57
|
image,
|
|
58
|
+
isRecordId,
|
|
47
59
|
link,
|
|
48
60
|
linkTargetOf,
|
|
61
|
+
newRecord,
|
|
49
62
|
number,
|
|
50
63
|
parseContent,
|
|
64
|
+
reference,
|
|
65
|
+
references,
|
|
51
66
|
resolveFieldPath,
|
|
52
67
|
text,
|
|
53
68
|
time,
|
|
54
69
|
toggle,
|
|
55
|
-
url
|
|
70
|
+
url,
|
|
71
|
+
withRecordIds
|
|
56
72
|
};
|
package/dist/site.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AstroComponentFactory } from 'astro/runtime/server/index.js';
|
|
2
|
-
import { F as Fields, C as ContentOf } from './content-
|
|
2
|
+
import { F as Fields, C as ContentOf } from './content-GL5k9Mch.js';
|
|
3
3
|
|
|
4
4
|
interface SeamletSiteDefinition<F extends Fields> {
|
|
5
5
|
/** The site's address in the CMS: `/sites/<id>`. */
|
package/dist/site.js
CHANGED
package/package.json
CHANGED