alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
64 lines (62 loc) • 1.76 kB
JavaScript
import "../../chunks/chunk-U5RRZUYZ.js";
// src/picker/entry/EntryPicker.ts
import { Entry } from "alinea/core/Entry";
import { Hint } from "alinea/core/Hint";
import { Type } from "alinea/core/Type";
import { MediaFile } from "alinea/core/media/MediaSchema";
import { RecordShape } from "alinea/core/shape/RecordShape";
import { ScalarShape } from "alinea/core/shape/ScalarShape";
import { assign } from "alinea/core/util/Objects";
var entryFields = {
title: Entry.title,
entryType: Entry.type,
url: Entry.url,
path: Entry.path
};
var fileFields = {
title: Entry.title,
url: MediaFile.location,
extension: MediaFile.extension,
size: MediaFile.size
};
var imageFields = {
title: Entry.title,
src: MediaFile.location,
extension: MediaFile.extension,
size: MediaFile.size,
hash: MediaFile.hash,
width: MediaFile.width,
height: MediaFile.height,
averageColor: MediaFile.averageColor,
thumbHash: MediaFile.thumbHash,
focus: MediaFile.focus
};
function entryPicker(options) {
const extra = options.fields && Type.shape(options.fields);
return {
shape: new RecordShape("Entry", {
entry: new ScalarShape("Entry")
}).concat(extra),
hint: options.fields ? Hint.Intersection(options.hint, Type.hint(options.fields)) : options.hint,
fields: options.fields,
label: options.label || "Page link",
handlesMultiple: true,
options,
async postProcess(row, loader) {
const link = row;
if (!link.entry)
return;
const linkIds = [link.entry];
if (!options.selection)
return;
const [fields] = await loader.resolveLinks(options.selection, linkIds);
assign(row, fields);
}
};
}
export {
entryFields,
entryPicker,
fileFields,
imageFields
};