UNPKG

@inspirer-dev/hero-widget-selector

Version:

A custom field plugin for Strapi v5 that provides a widget selector with size filtering capabilities. Perfect for selecting hero widgets from a filtered collection based on size (S, M, L, XL).

136 lines (135 loc) 4.11 kB
"use strict"; const icons = require("@strapi/icons"); const react = require("react"); 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 PLUGIN_ID = "hero-widget-selector"; const Initializer = ({ setPlugin }) => { const ref = react.useRef(setPlugin); react.useEffect(() => { ref.current(PLUGIN_ID); }, []); return null; }; const index = { register(app) { app.customFields.register({ name: "widget-selector", pluginId: PLUGIN_ID, plugin: PLUGIN_ID, type: "string", intlLabel: { id: `${PLUGIN_ID}.widget-selector.label`, defaultMessage: "Widget Selector" }, intlDescription: { id: `${PLUGIN_ID}.widget-selector.description`, defaultMessage: "Select a widget from filtered collection" }, icon: icons.Stack, components: { Input: async () => Promise.resolve().then(() => require("../_chunks/index-CNnHBpv6.js")) }, options: { base: [ { sectionTitle: { id: `${PLUGIN_ID}.widget-selector.section.filter`, defaultMessage: "Filter Options" }, items: [ { intlLabel: { id: `${PLUGIN_ID}.widget-selector.size`, defaultMessage: "Widget Size" }, name: "options.size", type: "select", value: "S", options: [ { key: "S", value: "S", defaultValue: "S", metadatas: { intlLabel: { id: `${PLUGIN_ID}.widget-selector.size.s`, defaultMessage: "Small (S)" } } }, { key: "M", value: "M", metadatas: { intlLabel: { id: `${PLUGIN_ID}.widget-selector.size.m`, defaultMessage: "Medium (M)" } } }, { key: "L", value: "L", metadatas: { intlLabel: { id: `${PLUGIN_ID}.widget-selector.size.l`, defaultMessage: "Large (L)" } } }, { key: "XL", value: "XL", metadatas: { intlLabel: { id: `${PLUGIN_ID}.widget-selector.size.xl`, defaultMessage: "Extra Large (XL)" } } } ] } ] } ], advanced: [] } }); app.registerPlugin({ id: PLUGIN_ID, initializer: Initializer, isReady: false, name: PLUGIN_ID }); }, bootstrap(app) { }, async registerTrads({ locales }) { return Promise.all( locales.map(async (locale) => { try { const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => Promise.resolve().then(() => require("../_chunks/en-B6WaGFnq.js")) }), `./translations/${locale}.json`, 3); return { data, locale }; } catch { return { data: {}, locale }; } }) ); } }; module.exports = index;