UNPKG

@turbo-red/strapi-plugin-lookup-enum

Version:

Like enum field, but options are extracted from a field provided by a single-type content.

426 lines (425 loc) 14.6 kB
import { jsxs, jsx } from "react/jsx-runtime"; import { getFetchClient } from "@strapi/strapi/admin"; const __variableDynamicImportRuntimeHelper = (glob, path, segs) => { const v = glob[path]; if (v) { return typeof v === "function" ? v() : Promise.resolve(v); } return new Promise((_, reject) => { (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)( reject.bind( null, new Error( "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "") ) ) ); }); }; const version = "1.0.0"; const keywords = []; const type = "commonjs"; const exports = { "./package.json": "./package.json", "./strapi-admin": { types: "./dist/admin/src/index.d.ts", source: "./admin/src/index.ts", "import": "./dist/admin/index.mjs", require: "./dist/admin/index.js", "default": "./dist/admin/index.js" }, "./strapi-server": { types: "./dist/server/src/index.d.ts", source: "./server/src/index.ts", "import": "./dist/server/index.mjs", require: "./dist/server/index.js", "default": "./dist/server/index.js" } }; const files = [ "dist" ]; const scripts = { build: "strapi-plugin build", watch: "strapi-plugin watch", "watch:link": "strapi-plugin watch:link", verify: "strapi-plugin verify", "test:ts:front": "run -T tsc -p admin/tsconfig.json", "test:ts:back": "run -T tsc -p server/tsconfig.json" }; const dependencies = { "@strapi/design-system": "^2.0.0-rc.11", "@strapi/icons": "^2.0.0-rc.11", "react-intl": "^6.8.1" }; const devDependencies = { "@strapi/sdk-plugin": "^5.2.7", "@strapi/strapi": "^5.1.0", "@strapi/typescript-utils": "^5.1.0", "@types/react": "^18.3.11", "@types/react-dom": "^18.3.1", prettier: "^3.3.3", react: "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.27.0", "styled-components": "^6.1.13", typescript: "^5.6.3", "vite-plugin-svgr": "^4.2.0" }; const peerDependencies = { "@strapi/strapi": "5.x", react: "18.x", "react-dom": "18.x", "react-router-dom": "6.x", "styled-components": "6.x" }; const strapi = { kind: "plugin", name: "lookup-enum", displayName: "TurboRED Lookup Enum", description: "Like enum field, but options are extracted from a field provided by a single-type content." }; const name = "@turbo-red/strapi-plugin-lookup-enum"; const description = "Like enum field, but options are extracted from a field provided by a single-type content."; const license = "MIT"; const author = "Andrea Chiumenti <achiumenti@red.software.systems>"; const packageManager = "yarn@4.5.1+sha512.341db9396b6e289fecc30cd7ab3af65060e05ebff4b3b47547b278b9e67b08f485ecd8c79006b405446262142c7a38154445ef7f17c1d5d1de7d90bf9ce7054d"; const jsonPackage = { version, keywords, type, exports, files, scripts, dependencies, devDependencies, peerDependencies, strapi, name, description, license, author, packageManager }; const pluginId = jsonPackage.strapi.name; const getTranslation = (id) => `${pluginId}.${id}`; function Icon$1() { return /* @__PURE__ */ jsxs( "svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", className: "sc-blHHSb fTSiDe", version: "1.1", viewBox: "0 0 32 32", children: [ /* @__PURE__ */ jsx( "rect", { width: "31", height: "23", x: "0.5", y: "4.5", fill: "#fbe7e7", fillOpacity: "1", stroke: "#872525", strokeOpacity: "1", rx: "2.5" } ), /* @__PURE__ */ jsx( "path", { fill: "#7a3030", fillOpacity: "1", d: "M9.679 7.18a.75.75 0 00-1.358 0l-4 8.5a.75.75 0 001.357.64l.974-2.07h4.695l.974 2.07a.75.75 0 101.358-.64zm-2.32 5.57l1.64-3.489 1.643 3.489zm9.14-3c-.865 0-1.547.241-2.027.717a.75.75 0 101.056 1.063c.188-.187.516-.283.972-.283.584 0 1.074.323 1.21.757a3 3 0 00-1.21-.254c-1.516 0-2.75 1.121-2.75 2.5s1.234 2.5 2.75 2.5c.479.001.95-.114 1.375-.336A.75.75 0 0019.25 16v-3.75c0-1.379-1.234-2.5-2.75-2.5m0 5.5c-.687 0-1.25-.449-1.25-1 0-.551.563-1 1.25-1s1.25.449 1.25 1c0 .551-.562 1-1.25 1" } ), /* @__PURE__ */ jsxs( "g", { stroke: "#020101", strokeDasharray: "none", strokeOpacity: "1", transform: "translate(1.285 -1.897)", children: [ /* @__PURE__ */ jsx( "circle", { cx: "15.212", cy: "16.58", r: "5.432", fill: "#efe7fb", fillOpacity: "0.559", strokeWidth: "0.6" } ), /* @__PURE__ */ jsx( "path", { fill: "none", fillOpacity: "1", strokeLinecap: "round", strokeWidth: "1.623", d: "M19.427 20.761l4.94 4.94" } ), /* @__PURE__ */ jsx( "path", { fill: "none", fillOpacity: "1", strokeLinecap: "round", strokeWidth: "2.84", d: "M21.133 22.443l3.172 3.172" } ) ] } ) ] } ); } function Icon() { return /* @__PURE__ */ jsxs( "svg", { xmlns: "http://www.w3.org/2000/svg", width: "16", height: "16", className: "sc-blHHSb fTSiDe", viewBox: "0 0 32 32", children: [ /* @__PURE__ */ jsx("rect", { width: "31", height: "23", x: "0.5", y: "4.5", fill: "#fbe7e7", stroke: "#872525", rx: "2.5" }), /* @__PURE__ */ jsxs("g", { fill: "#7a3030", transform: "translate(.612 1.407)", children: [ /* @__PURE__ */ jsx("path", { d: "M9.68 7.18a.75.75 0 00-1.358 0l-4 8.5a.75.75 0 001.357.64l.974-2.07h4.695l.974 2.07a.75.75 0 101.358-.64zm-2.32 5.57L9 9.26l1.643 3.49zm9.14-3c-.865 0-1.547.24-2.027.717a.75.75 0 101.056 1.063c.188-.187.516-.283.972-.283.584 0 1.074.323 1.21.757a3 3 0 00-1.21-.254c-1.516 0-2.75 1.12-2.75 2.5s1.234 2.5 2.75 2.5c.479 0 .95-.114 1.375-.336A.75.75 0 0019.25 16v-3.75c0-1.38-1.234-2.5-2.75-2.5m0 5.5c-.687 0-1.25-.45-1.25-1s.563-1 1.25-1 1.25.449 1.25 1-.562 1-1.25 1" }), /* @__PURE__ */ jsx( "path", { strokeLinecap: "round", strokeWidth: "1.153", d: "M2.045 18.326h3.36v-.922h-2.16v-10.8h2.16v-.92h-3.36z" } ), /* @__PURE__ */ jsx( "path", { strokeLinecap: "round", strokeWidth: "1.154", d: "M27.645 18.326h-3.36v-.922h2.16v-10.8h-2.16v-.92h3.36z" } ), /* @__PURE__ */ jsx("circle", { cx: "20.807", cy: "15.922", r: "0.817" }), /* @__PURE__ */ jsx("circle", { cx: "23.01", cy: "15.922", r: "0.817" }), /* @__PURE__ */ jsx("circle", { cx: "25.09", cy: "15.922", r: "0.817" }) ] }), /* @__PURE__ */ jsxs("g", { stroke: "#020101", transform: "translate(1.286 -1.896)", children: [ /* @__PURE__ */ jsx( "circle", { cx: "15.212", cy: "16.58", r: "5.431", fill: "#efe7fb", fillOpacity: "0.559", strokeWidth: "0.6" } ), /* @__PURE__ */ jsx( "path", { fill: "none", strokeLinecap: "round", strokeWidth: "1.623", d: "M19.427 20.761l4.94 4.94" } ), /* @__PURE__ */ jsx( "path", { fill: "none", strokeLinecap: "round", strokeWidth: "2.84", d: "M21.133 22.443l3.172 3.172" } ) ] }) ] } ); } const index = { async register(app) { const { get } = getFetchClient(); const contentTypesResp = await get( "/content-type-builder/content-types" ); const contentTypeOptions = !contentTypesResp.status || contentTypesResp.status === 200 ? contentTypesResp.data.data.filter((item) => item.schema.kind === "singleType").map((item) => item.uid) : []; app.customFields.register( [ { name: "lookup-enum", pluginId, type: "string", icon: Icon$1, intlLabel: { id: "lookup-enum.label", defaultMessage: "Lookup enum" }, intlDescription: { id: "lookup-enum.description", defaultMessage: "Like enum field , but options are extracted from a field provided by a single content type!" }, description: { id: "lookup-enum.description", defaultMessage: "Like enum field , but options are extracted from a field provided by a single content type!" } }, { name: "multi-lookup-enum", pluginId, type: "json", icon: Icon, intlLabel: { id: "multi-lookup-enum.label", defaultMessage: "Multiple lookup enum" }, intlDescription: { id: "multi-lookup-enum.description", defaultMessage: "Multiple selection enum field , options are extracted from a field provided by a single content type!" } } ].map( (item) => ({ ...item, components: { Input: async () => { const makeDynamicEnum = (await import( /* webpackChunkName: "lookup-enum" */ "../_chunks/DynamicEnum-Lh31j-z3.mjs" )).default; const component = makeDynamicEnum(item.type === "json"); return { default: component }; } }, options: { base: [ { sectionTitle: { id: getTranslation("lookup-enum.options.advanced.optionsSection"), defaultMessage: "Options source" }, items: [ { intlLabel: { id: getTranslation("lookup-enum.options.base.lookupSingleType"), defaultMessage: "Single-Type" }, name: "options.lookupSingleType", type: "select", description: { id: getTranslation("lookup-enum.options.base.description"), defaultMessage: "Lookup Single-Type entity" }, options: contentTypeOptions.map((value) => { return { key: value, value, metadatas: { intlLabel: { id: `${value}.no-override`, defaultMessage: value } } }; }) }, { intlLabel: { id: getTranslation("lookup-enum.options.base.lookupField"), defaultMessage: "Lookup field" }, name: "options.lookupField", type: "text", description: { id: getTranslation("lookup-enum.options.base.description"), defaultMessage: "Single-type text field where options are extracted using spaces,tabs and returns as delimiter." } } ] } ], advanced: [ { sectionTitle: { id: getTranslation("lookup-enum.options.advanced.settings"), defaultMessage: "Settings" }, items: [ { name: "required", type: "checkbox", intlLabel: { id: "form.attribute.item.requiredField", defaultMessage: "Required field" }, description: { id: "form.attribute.item.requiredField.description", defaultMessage: "You won't be able to create an entry if this field is empty" } }, { name: "unique", type: "checkbox", intlLabel: { id: "form.attribute.item.uniqueField", defaultMessage: "Unique field" }, description: { id: "form.attribute.item.uniqueField.description", defaultMessage: "You won't be able to create an entry if there is an existing entry with identical content" } }, { name: "private", type: "checkbox", intlLabel: { id: "form.attribute.item.privateField", defaultMessage: "Private field" }, description: { id: "form.attribute.item.privateField.description", defaultMessage: "This field will not show up in the API response" } } ] } ] } }) ) ); }, async registerTrads(app) { const { locales } = app; const importedTranslations = await Promise.all( locales.map((locale) => { return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => import("../_chunks/en-B02xVeks.mjs") }), `./translations/${locale}.json`, 3).then(({ default: data }) => { return { data: getTranslation(data), locale }; }).catch(() => { return { data: {}, locale }; }); }) ); return importedTranslations; } }; export { index as default }; //# sourceMappingURL=index.mjs.map