@nizza/core 0.7.1-beta.0 → 0.8.0-beta.2

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.mjs CHANGED
@@ -21358,7 +21358,7 @@ let PT = class bf {
21358
21358
  }
21359
21359
  };
21360
21360
  function BU(t) {
21361
- return Hr().logger.lazyChild(t);
21361
+ return Hr().baseLogger.lazyChild(t);
21362
21362
  }
21363
21363
  function DT(t, e) {
21364
21364
  return PT.create(
@@ -21512,6 +21512,14 @@ const Rn = class Rn {
21512
21512
  var e;
21513
21513
  (e = this.cfg) != null && e.account && await this.loadAccount(this.cfg.account, !!this.cfg.authToken);
21514
21514
  }
21515
+ /**
21516
+ * Reset account state and related config fields to their initial values.
21517
+ */
21518
+ resetAccount() {
21519
+ this.accountData = void 0, this.statusInternal = "idle", this.currentFetchId = null, this.pds = void 0, this.cfg && (this.cfg.account = void 0, this.cfg.authToken = void 0, this.cfg.productId = null, this.cfg.orderFormId = null), this.logger.debug(
21520
+ "Account state and related config fields have been reset"
21521
+ );
21522
+ }
21515
21523
  /** @returns Current version */
21516
21524
  get version() {
21517
21525
  return Rn.version;
@@ -21548,7 +21556,7 @@ const Rn = class Rn {
21548
21556
  return this.pds;
21549
21557
  }
21550
21558
  };
21551
- Pe(Rn, "version", "10"), Pe(Rn, "instanceRef");
21559
+ Pe(Rn, "version", "11"), Pe(Rn, "instanceRef");
21552
21560
  let _f = Rn;
21553
21561
  const Hr = (t) => {
21554
21562
  const e = _f.instance();
@@ -23262,7 +23270,6 @@ class _O {
23262
23270
  async get(e, n) {
23263
23271
  const i = `/info${LT({ planType: e })}`, s = vv + i, { data: o } = await hs({
23264
23272
  url: s,
23265
- secure: !0,
23266
23273
  account: n
23267
23274
  });
23268
23275
  return o;
@@ -31918,27 +31925,80 @@ Pe(dU, "baseStyles", RF`
31918
31925
  }
31919
31926
  `);
31920
31927
  class fU {
31928
+ /**
31929
+ * @param containerId ID of DOM element to render into
31930
+ * @param renderHandler async function that mounts and returns control methods
31931
+ * @param logger logging utility for debug tracing
31932
+ */
31921
31933
  constructor(e, n, r) {
31922
- Pe(this, "renderFn");
31923
- Pe(this, "logger");
31924
- // Id of the root container, usually a <div>
31925
- Pe(this, "rootId");
31934
+ // stores handlers for each lifecycle event; ensures uniqueness
31935
+ Pe(this, "_lifecycleHandlers", /* @__PURE__ */ new Map([
31936
+ ["mount", /* @__PURE__ */ new Set()],
31937
+ ["update", /* @__PURE__ */ new Set()],
31938
+ ["unmount", /* @__PURE__ */ new Set()]
31939
+ ]));
31940
+ Pe(this, "_containerId");
31941
+ // ID of root HTML container
31942
+ Pe(this, "_renderHandler");
31943
+ // strategy to mount component
31944
+ Pe(this, "_logger");
31945
+ // logger for debug output
31946
+ /** currently mounted element, null if none */
31926
31947
  Pe(this, "element", null);
31927
- Pe(this, "unmount");
31948
+ /** update component props or throw if not mounted */
31928
31949
  Pe(this, "updateProps");
31929
- this.rootId = e, this.renderFn = n, this.logger = r;
31950
+ /** unmount component or throw if not mounted */
31951
+ Pe(this, "unmount");
31952
+ this._containerId = e, this._renderHandler = n, this._logger = r;
31930
31953
  }
31954
+ /**
31955
+ * Mounts or updates the component with given props.
31956
+ * Calls appropriate lifecycle hooks and logs each phase.
31957
+ * @param props data passed to component on render/update
31958
+ */
31931
31959
  async render(e = {}) {
31932
31960
  var n;
31933
31961
  if (this.element)
31934
31962
  this.updateProps(e);
31935
31963
  else {
31936
- const r = await this.renderFn(this.rootId, e);
31937
- this.element = (n = r == null ? void 0 : r.element) != null ? n : null, this.updateProps = (i) => r == null ? void 0 : r.updateProps(i), this.unmount = () => {
31938
- r == null || r.unmount(), this.element = null;
31939
- };
31964
+ this._logger.debug("mounting component", e);
31965
+ const r = await this._renderHandler(this._containerId, e);
31966
+ this.element = (n = r == null ? void 0 : r.element) != null ? n : null, this.updateProps = (i) => {
31967
+ r == null || r.updateProps(i), this._logger.debug("updating props", i), this._trigger("update", i);
31968
+ }, this.unmount = () => {
31969
+ this._logger.debug("unmounting component"), r == null || r.unmount(), this._trigger("unmount"), this.element = null;
31970
+ }, this._trigger("mount");
31940
31971
  }
31941
31972
  }
31973
+ /**
31974
+ * Registers a callback to run after mounting.
31975
+ * @param callback no-args handler
31976
+ */
31977
+ onMount(e) {
31978
+ return this._lifecycleHandlers.get("mount").add(e), this;
31979
+ }
31980
+ /**
31981
+ * Registers a callback to run after props update.
31982
+ * @param callback receives new props
31983
+ */
31984
+ onUpdate(e) {
31985
+ return this._lifecycleHandlers.get("update").add(e), this;
31986
+ }
31987
+ /**
31988
+ * Registers a callback to run when unmounting.
31989
+ * @param callback no-args handler
31990
+ */
31991
+ onUnmount(e) {
31992
+ return this._lifecycleHandlers.get("unmount").add(e), this;
31993
+ }
31994
+ /**
31995
+ * Internal: triggers all handlers for an event.
31996
+ * @param event lifecycle phase to trigger
31997
+ * @param props optional props for update handlers
31998
+ */
31999
+ _trigger(e, n) {
32000
+ this._lifecycleHandlers.get(e).forEach((i) => i(n));
32001
+ }
31942
32002
  }
31943
32003
  class Ah {
31944
32004
  constructor(e) {