alinea
Version:
Headless git-based CMS
76 lines (74 loc) • 1.88 kB
JavaScript
import "../../chunks/chunk-NZLE2WMY.js";
// src/field/link/LinkEditor.ts
import { createId } from "alinea/core/Id";
import { Reference } from "alinea/core/Reference";
import { ListEditor } from "alinea/core/field/ListField";
import { EntryReference } from "alinea/picker/entry/EntryReference";
import { UrlReference } from "alinea/picker/url/UrlPicker";
var LinkEditor = class {
row;
add(type, value) {
this.row = {
[Reference.id]: createId(),
[Reference.type]: type,
...value
};
return this;
}
addUrl(data, fields) {
return this.add("url", {
[UrlReference.url]: data.url,
[UrlReference.title]: data.title,
[UrlReference.target]: data.target ?? "_blank",
...fields
});
}
addEntry(entryId, fields) {
return this.add("entry", {
[EntryReference.entry]: entryId,
...fields
});
}
addImage(entryId, fields) {
return this.add("image", {
[EntryReference.entry]: entryId,
...fields
});
}
addFile(entryId, fields) {
return this.add("file", { [EntryReference.entry]: entryId, ...fields });
}
value() {
if (!this.row) throw new Error("LinkEditor row not created");
return this.row;
}
};
var LinksEditor = class extends ListEditor {
addUrl(data, fields) {
return this.add("url", {
[UrlReference.url]: data.url,
[UrlReference.title]: data.title,
[UrlReference.target]: data.target ?? "_blank",
...fields
});
}
addEntry(entryId, fields) {
return this.add("entry", {
[EntryReference.entry]: entryId,
...fields
});
}
addImage(entryId, fields) {
return this.add("image", {
[EntryReference.entry]: entryId,
...fields
});
}
addFile(entryId, fields) {
return this.add("file", { [EntryReference.entry]: entryId, ...fields });
}
};
export {
LinkEditor,
LinksEditor
};