alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
70 lines (68 loc) • 1.52 kB
JavaScript
import "../../chunks/chunk-U5RRZUYZ.js";
// src/input/richtext/ReferenceLink.ts
import { createId } from "alinea/core";
function referenceToAttributes(reference) {
switch (reference.type) {
case "url": {
const ref = reference;
return {
"data-id": ref.id,
"data-entry": void 0,
"data-type": "url",
href: ref.url,
target: ref.target
};
}
case "entry": {
const ref = reference;
return {
"data-id": ref.id,
"data-entry": ref.entry,
"data-type": "entry",
href: void 0,
target: void 0
};
}
case "file": {
const ref = reference;
return {
"data-id": ref.id,
"data-entry": ref.entry,
"data-type": "file",
href: void 0,
target: void 0
};
}
default:
throw new Error(`Unexpected reference type: ${reference.type}`);
}
}
function attributesToReference(attributes) {
const id = attributes["data-id"];
if (!id) {
if (attributes.href)
return {
id: createId(),
type: "url",
url: attributes.href,
target: attributes.target
};
return;
}
if (attributes["data-entry"])
return {
id,
type: attributes["data-type"] === "file" ? "file" : "entry",
entry: attributes["data-entry"]
};
return {
id,
type: "url",
url: attributes.href,
target: attributes.target
};
}
export {
attributesToReference,
referenceToAttributes
};