@becklyn/contentful-adapter
Version:
[](https://github.com/Becklyn-Studios/contentful-adapter/actions/workflows/ci.yml)
75 lines (74 loc) • 2.16 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateBaseBlockFields = exports.THEME_BLOCK = void 0;
exports.THEME_BLOCK = {
en: {
background: "With background",
noBackground: "Without background",
},
de: {
background: "Mit Hintergrund",
noBackground: "Kein Hintergrund",
},
};
const translations = {
en: {
name: "Internal Name",
theme: {
name: "Theme",
default: exports.THEME_BLOCK.en.noBackground,
in: [exports.THEME_BLOCK.en.noBackground, exports.THEME_BLOCK.en.background],
},
anchor: "Anchor",
anchorLabel: "Anchor Label",
},
de: {
name: "Interner Name",
theme: {
name: "Theme",
default: exports.THEME_BLOCK.de.noBackground,
in: [exports.THEME_BLOCK.de.noBackground, exports.THEME_BLOCK.de.background],
},
anchor: "Anker",
anchorLabel: "Anker Label",
},
};
const migrateBaseBlockFields = (block, language, trackingFieldId = "name") => {
const t = translations[language];
block.createField("theme", {
type: "Symbol",
name: t.theme.name,
required: true,
defaultValue: {
[language]: t.theme.default,
},
validations: [
{
in: t.theme.in,
},
],
});
block.changeFieldControl("theme", "builtin", "radio");
block.createField("anchor", {
type: "Symbol",
name: t.anchor,
required: true,
validations: [{ regexp: { pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$" } }],
});
block.changeFieldControl("anchor", "builtin", "slugEditor", {
trackingFieldId,
});
block.createField("anchorLabel", {
type: "Symbol",
name: t.anchorLabel,
validations: [{ size: { max: 25 } }],
});
block.createField("name", {
type: "Symbol",
name: t.name,
required: true,
});
block.moveField("name").toTheTop();
block.displayField("name");
};
exports.migrateBaseBlockFields = migrateBaseBlockFields;