pxengine 0.1.107 → 0.1.108

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -345,7 +345,9 @@ __export(index_exports, {
345
345
  formatQAMessage: () => formatQAMessage,
346
346
  generateFieldsFromData: () => generateFieldsFromData,
347
347
  generateFieldsFromPropDefinitions: () => generateFieldsFromPropDefinitions,
348
+ getPxAuthToken: () => getPxAuthToken,
348
349
  isInputAtom: () => isInputAtom,
350
+ setPxAuthTokenProvider: () => setPxAuthTokenProvider,
349
351
  submitWidgetToAgent: () => submitWidgetToAgent,
350
352
  th: () => th,
351
353
  useCreatorWidgetPolling: () => useCreatorWidgetPolling,
@@ -3480,7 +3482,7 @@ __export(lucide_react_exports, {
3480
3482
  LucideMailX: () => MailX,
3481
3483
  LucideMailbox: () => Mailbox,
3482
3484
  LucideMails: () => Mails,
3483
- LucideMap: () => Map,
3485
+ LucideMap: () => Map2,
3484
3486
  LucideMapPin: () => MapPin,
3485
3487
  LucideMapPinCheck: () => MapPinCheck,
3486
3488
  LucideMapPinCheckInside: () => MapPinCheckInside,
@@ -4272,8 +4274,8 @@ __export(lucide_react_exports, {
4272
4274
  MailboxIcon: () => Mailbox,
4273
4275
  Mails: () => Mails,
4274
4276
  MailsIcon: () => Mails,
4275
- Map: () => Map,
4276
- MapIcon: () => Map,
4277
+ Map: () => Map2,
4278
+ MapIcon: () => Map2,
4277
4279
  MapPin: () => MapPin,
4278
4280
  MapPinCheck: () => MapPinCheck,
4279
4281
  MapPinCheckIcon: () => MapPinCheck,
@@ -6684,7 +6686,7 @@ __export(icons_exports, {
6684
6686
  MailX: () => MailX,
6685
6687
  Mailbox: () => Mailbox,
6686
6688
  Mails: () => Mails,
6687
- Map: () => Map,
6689
+ Map: () => Map2,
6688
6690
  MapPin: () => MapPin,
6689
6691
  MapPinCheck: () => MapPinCheck,
6690
6692
  MapPinCheckInside: () => MapPinCheckInside,
@@ -17499,7 +17501,7 @@ var __iconNode891 = [
17499
17501
  ["path", { d: "M15 5.764v15", key: "1pn4in" }],
17500
17502
  ["path", { d: "M9 3.236v15", key: "1uimfh" }]
17501
17503
  ];
17502
- var Map = createLucideIcon("Map", __iconNode891);
17504
+ var Map2 = createLucideIcon("Map", __iconNode891);
17503
17505
 
17504
17506
  // node_modules/lucide-react/dist/esm/icons/mars-stroke.js
17505
17507
  var __iconNode892 = [
@@ -33510,7 +33512,7 @@ var ChartTooltipContent = React80.forwardRef(
33510
33512
  )
33511
33513
  ] })
33512
33514
  },
33513
- item.dataKey
33515
+ `${item.dataKey ?? index}`
33514
33516
  );
33515
33517
  }) })
33516
33518
  ]
@@ -41721,6 +41723,28 @@ SearchSpecCard.displayName = "SearchSpecCard";
41721
41723
  // src/molecules/creator-discovery/MCQCard/MCQCard.tsx
41722
41724
  var import_react83 = __toESM(require("react"), 1);
41723
41725
 
41726
+ // src/lib/auth-provider.ts
41727
+ var _provider = null;
41728
+ function setPxAuthTokenProvider(provider) {
41729
+ _provider = provider;
41730
+ }
41731
+ function getPxAuthToken() {
41732
+ if (_provider) {
41733
+ try {
41734
+ const t = _provider();
41735
+ if (t) return t;
41736
+ } catch {
41737
+ }
41738
+ }
41739
+ if (typeof document !== "undefined") {
41740
+ for (const name of ["adminTokenBuilder", "adminToken", "token"]) {
41741
+ const match2 = document.cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
41742
+ if (match2?.[1]) return match2[1];
41743
+ }
41744
+ }
41745
+ return null;
41746
+ }
41747
+
41724
41748
  // src/molecules/creator-discovery/MCQCard/defaultFetchers.ts
41725
41749
  function getBackendOrigin() {
41726
41750
  if (typeof window === "undefined") return null;
@@ -41736,25 +41760,10 @@ function getBaseUrl() {
41736
41760
  if (backend) return `${backend}/api/custom-agents`;
41737
41761
  return "/api/agents-proxy/custom-agents";
41738
41762
  }
41739
- function getAuthToken() {
41740
- if (typeof window === "undefined") return null;
41741
- try {
41742
- const ls = localStorage.getItem("px_auth_token");
41743
- if (ls) return ls;
41744
- } catch {
41745
- }
41746
- if (typeof document !== "undefined") {
41747
- for (const name of ["adminTokenBuilder", "adminToken", "token"]) {
41748
- const match2 = document.cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
41749
- if (match2?.[1]) return match2[1];
41750
- }
41751
- }
41752
- return null;
41753
- }
41754
41763
  function buildHeaders() {
41755
41764
  const headers = { "Content-Type": "application/json" };
41756
41765
  if (getBackendOrigin()) {
41757
- const token = getAuthToken();
41766
+ const token = getPxAuthToken();
41758
41767
  if (token) headers["Authorization"] = `Bearer ${token}`;
41759
41768
  }
41760
41769
  return headers;
@@ -43333,26 +43342,11 @@ function getBackendOrigin2() {
43333
43342
  }
43334
43343
  return raw;
43335
43344
  }
43336
- function getAuthToken2() {
43337
- if (typeof window === "undefined") return null;
43338
- try {
43339
- const ls = localStorage.getItem("px_auth_token");
43340
- if (ls) return ls;
43341
- } catch {
43342
- }
43343
- if (typeof document !== "undefined") {
43344
- for (const name of ["adminTokenBuilder", "adminToken", "token"]) {
43345
- const match2 = document.cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
43346
- if (match2?.[1]) return match2[1];
43347
- }
43348
- }
43349
- return null;
43350
- }
43351
43345
  function buildHeaders2(includeJson = false) {
43352
43346
  const headers = {};
43353
43347
  if (includeJson) headers["Content-Type"] = "application/json";
43354
43348
  if (getBackendOrigin2()) {
43355
- const token = getAuthToken2();
43349
+ const token = getPxAuthToken();
43356
43350
  if (token) headers["Authorization"] = `Bearer ${token}`;
43357
43351
  }
43358
43352
  return headers;
@@ -47212,6 +47206,37 @@ ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName;
47212
47206
  // src/render/PXEngineRenderer.tsx
47213
47207
  var import_jsx_runtime188 = require("react/jsx-runtime");
47214
47208
  var MOLECULE_REFS = new Set(Object.values(molecules_exports));
47209
+ var ATOMS_WITH_RENDER = /* @__PURE__ */ new Set([
47210
+ "LayoutAtom",
47211
+ "CardAtom",
47212
+ "TabsAtom",
47213
+ "AccordionAtom",
47214
+ "ScrollAreaAtom",
47215
+ "CarouselAtom",
47216
+ "AspectRatioAtom",
47217
+ "CollapsibleAtom",
47218
+ "TooltipAtom",
47219
+ "PopoverAtom",
47220
+ "DialogAtom",
47221
+ "SheetAtom",
47222
+ "ResizableAtom"
47223
+ ]);
47224
+ var COMPONENT_LOOKUP_CACHE = /* @__PURE__ */ new Map();
47225
+ var resolveComponent = (identifier) => {
47226
+ const cached = COMPONENT_LOOKUP_CACHE.get(identifier);
47227
+ if (cached !== void 0) return cached;
47228
+ const normalized = identifier.split(/[-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
47229
+ const atomName = normalized.endsWith("Atom") ? normalized : `${normalized}Atom`;
47230
+ let Comp = atoms_exports[atomName] || atoms_exports[normalized] || atoms_exports[identifier] || null;
47231
+ if (!Comp) {
47232
+ Comp = molecules_exports[normalized] || molecules_exports[identifier] || null;
47233
+ }
47234
+ if (!Comp && !CONTEXT_DEPENDENT_COMPONENTS.has(normalized)) {
47235
+ Comp = ui_exports[normalized] || ui_exports[identifier] || null;
47236
+ }
47237
+ COMPONENT_LOOKUP_CACHE.set(identifier, Comp);
47238
+ return Comp;
47239
+ };
47215
47240
  var CONTEXT_DEPENDENT_COMPONENTS = /* @__PURE__ */ new Set([
47216
47241
  // Form components - require FormField + FormItem context
47217
47242
  "FormLabel",
@@ -47340,7 +47365,10 @@ var renderContextDependentError = (componentName, normalizedName, key) => {
47340
47365
  key
47341
47366
  );
47342
47367
  };
47368
+ var NORMALIZE_PROPS_CACHE = /* @__PURE__ */ new WeakMap();
47343
47369
  var normalizeProps = (props) => {
47370
+ const cached = NORMALIZE_PROPS_CACHE.get(props);
47371
+ if (cached) return cached;
47344
47372
  const normalized = {};
47345
47373
  const dynamicStyle = {};
47346
47374
  Object.entries(props).forEach(([key, value]) => {
@@ -47400,7 +47428,9 @@ var normalizeProps = (props) => {
47400
47428
  }
47401
47429
  normalized[key] = value;
47402
47430
  });
47403
- return { normalized, dynamicStyle };
47431
+ const result = { normalized, dynamicStyle };
47432
+ NORMALIZE_PROPS_CACHE.set(props, result);
47433
+ return result;
47404
47434
  };
47405
47435
  var FORM_INPUT_ATOM_NAMES = /* @__PURE__ */ new Set([
47406
47436
  "InputAtom",
@@ -47419,13 +47449,13 @@ var FORM_INPUT_ATOM_NAMES = /* @__PURE__ */ new Set([
47419
47449
  "InputOTPAtom",
47420
47450
  "ToggleAtom"
47421
47451
  ]);
47422
- var PXEngineRenderer = ({
47452
+ var PXEngineRenderer = import_react96.default.memo(function PXEngineRenderer2({
47423
47453
  schema,
47424
47454
  onAction,
47425
47455
  disabled,
47426
47456
  theme,
47427
47457
  onFormSubmit
47428
- }) => {
47458
+ }) {
47429
47459
  const contextTheme = import_react96.default.useContext(WidgetThemeContext);
47430
47460
  const effectiveTheme = theme ?? contextTheme;
47431
47461
  const formValuesRef = import_react96.default.useRef({});
@@ -47460,28 +47490,34 @@ var PXEngineRenderer = ({
47460
47490
  } = component;
47461
47491
  const componentName = name || type || componentType;
47462
47492
  if (!componentName || typeof componentName !== "string") return null;
47463
- const rawProps = { ...remainingProps, ...props };
47464
- delete rawProps.key;
47465
- if (disabled !== void 0 && rawProps.disabled === void 0) {
47466
- rawProps.disabled = disabled;
47493
+ const hasRemaining = Object.keys(remainingProps).length > 0;
47494
+ let baseProps = hasRemaining ? { ...remainingProps, ...props } : props;
47495
+ if (baseProps && baseProps.key !== void 0) {
47496
+ const { key: _k, ...rest } = baseProps;
47497
+ baseProps = rest;
47498
+ }
47499
+ const { normalized, dynamicStyle } = normalizeProps(baseProps || {});
47500
+ const finalProps = { ...normalized };
47501
+ if (disabled !== void 0 && finalProps.disabled === void 0) {
47502
+ finalProps.disabled = disabled;
47467
47503
  }
47468
47504
  const normalizedName = componentName.charAt(0).toUpperCase() + componentName.slice(1);
47469
47505
  const earlyAtomName = normalizedName.endsWith("Atom") ? normalizedName : `${normalizedName}Atom`;
47470
47506
  if (onFormSubmit && FORM_INPUT_ATOM_NAMES.has(earlyAtomName)) {
47471
- const fieldKey = rawProps.fieldKey || rawProps.id || id || rawProps.label || componentName;
47507
+ const fieldKey = finalProps.fieldKey || finalProps.id || id || finalProps.label || componentName;
47472
47508
  const storedValue = formValuesRef.current[fieldKey];
47473
47509
  if (storedValue !== void 0) {
47474
- rawProps.defaultValue = storedValue;
47510
+ finalProps.defaultValue = storedValue;
47475
47511
  }
47476
- rawProps.onValueChange = handleInputValueChange;
47477
- rawProps.fieldKey = fieldKey;
47478
- if (id) rawProps.id = id;
47512
+ finalProps.onValueChange = handleInputValueChange;
47513
+ finalProps.fieldKey = fieldKey;
47514
+ if (id) finalProps.id = id;
47479
47515
  }
47480
47516
  if (onFormSubmit && earlyAtomName === "ButtonAtom") {
47481
- const action = rawProps.action || rawProps.buttonAction;
47517
+ const action = finalProps.action || finalProps.buttonAction;
47482
47518
  if (action === "submit") {
47483
- const originalOnAction = rawProps.onAction;
47484
- rawProps.onAction = (evt) => {
47519
+ const originalOnAction = finalProps.onAction;
47520
+ finalProps.onAction = (evt) => {
47485
47521
  const elements = Object.entries(formValuesRef.current).map(
47486
47522
  ([key, value]) => ({
47487
47523
  id: key,
@@ -47497,23 +47533,10 @@ var PXEngineRenderer = ({
47497
47533
  };
47498
47534
  }
47499
47535
  }
47500
- const { normalized: finalProps, dynamicStyle } = normalizeProps(rawProps);
47501
47536
  if (id && !finalProps.id) {
47502
47537
  finalProps.id = id;
47503
47538
  }
47504
47539
  const uniqueKey = id || (index !== void 0 ? `${componentName}-${index}` : `${componentName}-root`);
47505
- const resolveComponent = (identifier) => {
47506
- const normalized = identifier.split(/[-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
47507
- const atomName2 = normalized.endsWith("Atom") ? normalized : `${normalized}Atom`;
47508
- let Comp = atoms_exports[atomName2] || atoms_exports[normalized] || atoms_exports[identifier];
47509
- if (!Comp) {
47510
- Comp = molecules_exports[normalized] || molecules_exports[identifier];
47511
- }
47512
- if (!Comp && !CONTEXT_DEPENDENT_COMPONENTS.has(normalized)) {
47513
- Comp = ui_exports[normalized] || ui_exports[identifier];
47514
- }
47515
- return Comp;
47516
- };
47517
47540
  let TargetComponent = resolveComponent(componentName);
47518
47541
  let resolvedIdentifier = componentName;
47519
47542
  if (!TargetComponent && type && type !== componentName) {
@@ -47538,21 +47561,6 @@ var PXEngineRenderer = ({
47538
47561
  }
47539
47562
  const resolvedNormalized = resolvedIdentifier.charAt(0).toUpperCase() + resolvedIdentifier.slice(1);
47540
47563
  const atomName = resolvedNormalized.endsWith("Atom") ? resolvedNormalized : `${resolvedNormalized}Atom`;
47541
- const ATOMS_WITH_RENDER = /* @__PURE__ */ new Set([
47542
- "LayoutAtom",
47543
- "CardAtom",
47544
- "TabsAtom",
47545
- "AccordionAtom",
47546
- "ScrollAreaAtom",
47547
- "CarouselAtom",
47548
- "AspectRatioAtom",
47549
- "CollapsibleAtom",
47550
- "TooltipAtom",
47551
- "PopoverAtom",
47552
- "DialogAtom",
47553
- "SheetAtom",
47554
- "ResizableAtom"
47555
- ]);
47556
47564
  const isAtomWithRenderProp = ATOMS_WITH_RENDER.has(atomName);
47557
47565
  if (effectiveTheme && finalProps.theme === void 0 && MOLECULE_REFS.has(TargetComponent)) {
47558
47566
  finalProps.theme = effectiveTheme;
@@ -47586,7 +47594,8 @@ var PXEngineRenderer = ({
47586
47594
  }
47587
47595
  };
47588
47596
  return /* @__PURE__ */ (0, import_jsx_runtime188.jsx)(WidgetThemeContext.Provider, { value: effectiveTheme, children: /* @__PURE__ */ (0, import_jsx_runtime188.jsx)("div", { className: "px-engine-root relative w-full h-full", children: renderRecursive(root) }) });
47589
- };
47597
+ });
47598
+ PXEngineRenderer.displayName = "PXEngineRenderer";
47590
47599
  // Annotate the CommonJS export names for ESM import in node:
47591
47600
  0 && (module.exports = {
47592
47601
  Accordion,
@@ -47904,7 +47913,9 @@ var PXEngineRenderer = ({
47904
47913
  formatQAMessage,
47905
47914
  generateFieldsFromData,
47906
47915
  generateFieldsFromPropDefinitions,
47916
+ getPxAuthToken,
47907
47917
  isInputAtom,
47918
+ setPxAuthTokenProvider,
47908
47919
  submitWidgetToAgent,
47909
47920
  th,
47910
47921
  useCreatorWidgetPolling,