@medusajs/admin-shared
Advanced tools
Comparing version 0.0.2-preview-20240515175257 to 0.0.2-preview-20240523131811
@@ -1,2 +0,64 @@ | ||
export * from "./constants"; | ||
export * from "./types"; | ||
import { ComponentType } from 'react'; | ||
/** | ||
* All valid injection zones in the admin panel. An injection zone is a specific place | ||
* in the admin panel where a plugin can inject custom widgets. | ||
*/ | ||
declare const INJECTION_ZONES: readonly ["order.details.before", "order.details.after", "order.list.before", "order.list.after", "draft_order.list.before", "draft_order.list.after", "draft_order.details.before", "draft_order.details.after", "customer.details.before", "customer.details.after", "customer.list.before", "customer.list.after", "customer_group.details.before", "customer_group.details.after", "customer_group.list.before", "customer_group.list.after", "product.details.before", "product.details.after", "product.list.before", "product.list.after", "product.details.side.before", "product.details.side.after", "product_collection.details.before", "product_collection.details.after", "product_collection.list.before", "product_collection.list.after", "product_category.details.before", "product_category.details.after", "product_category.list.before", "product_category.list.after", "price_list.details.before", "price_list.details.after", "price_list.list.before", "price_list.list.after", "discount.details.before", "discount.details.after", "discount.list.before", "discount.list.after", "promotion.details.before", "promotion.details.after", "promotion.list.before", "promotion.list.after", "gift_card.details.before", "gift_card.details.after", "gift_card.list.before", "gift_card.list.after", "custom_gift_card.before", "custom_gift_card.after", "login.before", "login.after"]; | ||
type InjectionZone = (typeof INJECTION_ZONES)[number]; | ||
/** | ||
* Validates that the provided zone is a valid injection zone for a widget. | ||
*/ | ||
declare function isValidInjectionZone(zone: any): zone is InjectionZone; | ||
type WidgetConfig = { | ||
zone: InjectionZone | InjectionZone[]; | ||
}; | ||
type RouteConfig = { | ||
label?: string; | ||
icon?: ComponentType; | ||
}; | ||
/** | ||
* Define a widget configuration. | ||
* | ||
* @param config The widget configuration. | ||
* @returns The widget configuration. | ||
*/ | ||
declare function defineWidgetConfig(config: WidgetConfig): WidgetConfig; | ||
/** | ||
* Define a route configuration. | ||
* | ||
* @param config The route configuration. | ||
* @returns The route configuration. | ||
*/ | ||
declare function defineRouteConfig(config: RouteConfig): RouteConfig; | ||
/** | ||
* All virtual modules that are used in the admin panel. Virtual modules are used | ||
* to inject custom widgets, routes and settings. A virtual module is imported using | ||
* a string that corresponds to the id of the virtual module. | ||
* | ||
* @example | ||
* ```ts | ||
* import ProductDetailsBefore from "virtual:medusa/widgets/product/details/before" | ||
* ``` | ||
*/ | ||
declare const VIRTUAL_MODULES: string[]; | ||
/** | ||
* Reolved paths to all virtual widget modules. | ||
*/ | ||
declare const RESOLVED_WIDGET_MODULES: string[]; | ||
/** | ||
* Reolved paths to all virtual route modules. | ||
*/ | ||
declare const RESOLVED_ROUTE_MODULES: string[]; | ||
declare const getVirtualId: (name: string) => string; | ||
declare const resolveVirtualId: (id: string) => string; | ||
declare const getWidgetImport: (zone: InjectionZone) => string; | ||
declare const getWidgetZone: (resolvedId: string) => InjectionZone; | ||
export { INJECTION_ZONES, type InjectionZone, RESOLVED_ROUTE_MODULES, RESOLVED_WIDGET_MODULES, type RouteConfig, VIRTUAL_MODULES, type WidgetConfig, defineRouteConfig, defineWidgetConfig, getVirtualId, getWidgetImport, getWidgetZone, isValidInjectionZone, resolveVirtualId }; |
@@ -1,2 +0,200 @@ | ||
export * from "./constants"; | ||
export * from "./types"; | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
INJECTION_ZONES: () => INJECTION_ZONES, | ||
RESOLVED_ROUTE_MODULES: () => RESOLVED_ROUTE_MODULES, | ||
RESOLVED_WIDGET_MODULES: () => RESOLVED_WIDGET_MODULES, | ||
VIRTUAL_MODULES: () => VIRTUAL_MODULES, | ||
defineRouteConfig: () => defineRouteConfig, | ||
defineWidgetConfig: () => defineWidgetConfig, | ||
getVirtualId: () => getVirtualId, | ||
getWidgetImport: () => getWidgetImport, | ||
getWidgetZone: () => getWidgetZone, | ||
isValidInjectionZone: () => isValidInjectionZone, | ||
resolveVirtualId: () => resolveVirtualId | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/extensions/config/utils.ts | ||
function createConfigHelper(config) { | ||
return { | ||
...config, | ||
/** | ||
* This property is required to allow the config to be exported, | ||
* while still allowing HMR to work correctly. | ||
* | ||
* It tricks Fast Refresh into thinking that the config is a React component, | ||
* which allows it to be updated without a full page reload. | ||
*/ | ||
$$typeof: Symbol.for("react.memo") | ||
}; | ||
} | ||
function defineWidgetConfig(config) { | ||
return createConfigHelper(config); | ||
} | ||
function defineRouteConfig(config) { | ||
return createConfigHelper(config); | ||
} | ||
// src/extensions/routes/constants.ts | ||
var ROUTE_IMPORTS = ["routes/pages", "routes/links"]; | ||
// src/extensions/widgets/constants.ts | ||
var ORDER_INJECTION_ZONES = [ | ||
"order.details.before", | ||
"order.details.after", | ||
"order.list.before", | ||
"order.list.after" | ||
]; | ||
var DRAFT_ORDER_INJECTION_ZONES = [ | ||
"draft_order.list.before", | ||
"draft_order.list.after", | ||
"draft_order.details.before", | ||
"draft_order.details.after" | ||
]; | ||
var CUSTOMER_INJECTION_ZONES = [ | ||
"customer.details.before", | ||
"customer.details.after", | ||
"customer.list.before", | ||
"customer.list.after" | ||
]; | ||
var CUSTOMER_GROUP_INJECTION_ZONES = [ | ||
"customer_group.details.before", | ||
"customer_group.details.after", | ||
"customer_group.list.before", | ||
"customer_group.list.after" | ||
]; | ||
var PRODUCT_INJECTION_ZONES = [ | ||
"product.details.before", | ||
"product.details.after", | ||
"product.list.before", | ||
"product.list.after", | ||
"product.details.side.before", | ||
"product.details.side.after" | ||
]; | ||
var PRODUCT_COLLECTION_INJECTION_ZONES = [ | ||
"product_collection.details.before", | ||
"product_collection.details.after", | ||
"product_collection.list.before", | ||
"product_collection.list.after" | ||
]; | ||
var PRODUCT_CATEGORY_INJECTION_ZONES = [ | ||
"product_category.details.before", | ||
"product_category.details.after", | ||
"product_category.list.before", | ||
"product_category.list.after" | ||
]; | ||
var PRICE_LIST_INJECTION_ZONES = [ | ||
"price_list.details.before", | ||
"price_list.details.after", | ||
"price_list.list.before", | ||
"price_list.list.after" | ||
]; | ||
var DISCOUNT_INJECTION_ZONES = [ | ||
"discount.details.before", | ||
"discount.details.after", | ||
"discount.list.before", | ||
"discount.list.after" | ||
]; | ||
var PROMOTION_INJECTION_ZONES = [ | ||
"promotion.details.before", | ||
"promotion.details.after", | ||
"promotion.list.before", | ||
"promotion.list.after" | ||
]; | ||
var GIFT_CARD_INJECTION_ZONES = [ | ||
"gift_card.details.before", | ||
"gift_card.details.after", | ||
"gift_card.list.before", | ||
"gift_card.list.after", | ||
"custom_gift_card.before", | ||
"custom_gift_card.after" | ||
]; | ||
var LOGIN_INJECTION_ZONES = ["login.before", "login.after"]; | ||
var INJECTION_ZONES = [ | ||
...ORDER_INJECTION_ZONES, | ||
...DRAFT_ORDER_INJECTION_ZONES, | ||
...CUSTOMER_INJECTION_ZONES, | ||
...CUSTOMER_GROUP_INJECTION_ZONES, | ||
...PRODUCT_INJECTION_ZONES, | ||
...PRODUCT_COLLECTION_INJECTION_ZONES, | ||
...PRODUCT_CATEGORY_INJECTION_ZONES, | ||
...PRICE_LIST_INJECTION_ZONES, | ||
...DISCOUNT_INJECTION_ZONES, | ||
...PROMOTION_INJECTION_ZONES, | ||
...GIFT_CARD_INJECTION_ZONES, | ||
...LOGIN_INJECTION_ZONES | ||
]; | ||
// src/extensions/widgets/utils.ts | ||
function isValidInjectionZone(zone) { | ||
return INJECTION_ZONES.includes(zone); | ||
} | ||
// src/extensions/virtual/utils.ts | ||
var PREFIX = "virtual:medusa/"; | ||
var getVirtualId = (name) => { | ||
return `${PREFIX}${name}`; | ||
}; | ||
var resolveVirtualId = (id) => { | ||
return `\0${id}`; | ||
}; | ||
var getWidgetImport = (zone) => { | ||
return `widgets/${zone.replace(/\./g, "/")}`; | ||
}; | ||
var getWidgetZone = (resolvedId) => { | ||
const virtualPrefix = `\0${PREFIX}widgets/`; | ||
const zone = resolvedId.replace(virtualPrefix, "").replace(/\//g, "."); | ||
return zone; | ||
}; | ||
// src/extensions/virtual/constants.ts | ||
var VIRTUAL_WIDGET_MODULES = INJECTION_ZONES.map((zone) => { | ||
return getVirtualId(getWidgetImport(zone)); | ||
}); | ||
var VIRTUAL_ROUTE_MODULES = ROUTE_IMPORTS.map((route) => { | ||
return getVirtualId(route); | ||
}); | ||
var VIRTUAL_MODULES = [ | ||
...VIRTUAL_WIDGET_MODULES, | ||
...VIRTUAL_ROUTE_MODULES | ||
]; | ||
var RESOLVED_WIDGET_MODULES = VIRTUAL_WIDGET_MODULES.map((id) => { | ||
return resolveVirtualId(id); | ||
}); | ||
var RESOLVED_ROUTE_MODULES = VIRTUAL_ROUTE_MODULES.map((id) => { | ||
return resolveVirtualId(id); | ||
}); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
INJECTION_ZONES, | ||
RESOLVED_ROUTE_MODULES, | ||
RESOLVED_WIDGET_MODULES, | ||
VIRTUAL_MODULES, | ||
defineRouteConfig, | ||
defineWidgetConfig, | ||
getVirtualId, | ||
getWidgetImport, | ||
getWidgetZone, | ||
isValidInjectionZone, | ||
resolveVirtualId | ||
}); |
{ | ||
"name": "@medusajs/admin-shared", | ||
"description": "Shared code for Medusa admin packages.", | ||
"version": "0.0.2-preview-20240515175257", | ||
"version": "0.0.2-preview-20240523131811", | ||
"author": "Kasper Kristensen <kasper@medusajs.com>", | ||
"types": "dist/index.d.ts", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"files": [ | ||
@@ -13,5 +14,7 @@ "dist", | ||
"scripts": { | ||
"build": "tsc" | ||
"build": "tsup" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.3.2", | ||
"tsup": "^8.0.2", | ||
"typescript": "^5.3.3" | ||
@@ -18,0 +21,0 @@ }, |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
17680
412
3
6
1