alinea
Version:
Headless git-based CMS
59 lines (57 loc) • 1.88 kB
JavaScript
import "../../chunks/chunk-NZLE2WMY.js";
// src/picker/url/UrlPicker.ts
import { Reference } from "alinea/core/Reference";
import { Type, type } from "alinea/core/Type";
import { ListRow } from "alinea/core/shape/ListShape";
import { RecordShape } from "alinea/core/shape/RecordShape";
import { ScalarShape } from "alinea/core/shape/ScalarShape";
import { keys } from "alinea/core/util/Objects";
var UrlReference;
((UrlReference2) => {
UrlReference2.url = "_url";
UrlReference2.title = "_title";
UrlReference2.target = "_target";
function isUrl(value) {
return value && value[Reference.type] === "url";
}
UrlReference2.isUrl = isUrl;
})(UrlReference || (UrlReference = {}));
function urlPicker(options) {
const fieldType = Type.isType(options.fields) ? options.fields : options.fields && type("URL fields", { fields: options.fields });
const extra = fieldType && Type.shape(fieldType);
return {
shape: new RecordShape("Url", {
[Reference.id]: new ScalarShape("Id"),
[Reference.type]: new ScalarShape("Type"),
[UrlReference.url]: new ScalarShape("Url"),
[UrlReference.title]: new ScalarShape("Title"),
[UrlReference.target]: new ScalarShape("Target")
}).concat(extra),
label: "External website",
handlesMultiple: false,
fields: fieldType,
options,
async postProcess(row, loader) {
const {
[Reference.id]: id,
[Reference.type]: type2,
[UrlReference.url]: url,
[UrlReference.title]: title,
[UrlReference.target]: target,
[ListRow.index]: index,
...fields
} = row;
const fieldKeys = keys(fields);
for (const key of fieldKeys) delete row[key];
row.url = url;
row.href = url;
row.title = title;
row.target = target;
row.fields = fields;
}
};
}
export {
UrlReference,
urlPicker
};