@mydatavalue/polter 0.1.2 → 0.1.4

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
@@ -328,7 +328,7 @@ async function resolveStepElement(target, actionName, params, config) {
328
328
  return config.resolveTarget(actionName, target.fromParam, paramValue, config.signal);
329
329
  }
330
330
  if (target.fromTarget && config.resolveNamedTarget) {
331
- return config.resolveNamedTarget(actionName, target.fromTarget, config.signal);
331
+ return config.resolveNamedTarget(actionName, target.fromTarget, config.signal, params);
332
332
  }
333
333
  return target.element;
334
334
  }
@@ -540,7 +540,7 @@ function AgentActionProvider({
540
540
  []
541
541
  );
542
542
  const resolveNamedTarget = useCallback(
543
- async (actionName, name, signal) => {
543
+ async (actionName, name, signal, params) => {
544
544
  const maxWait = 3e3;
545
545
  const pollInterval = 50;
546
546
  const start = Date.now();
@@ -548,6 +548,9 @@ function AgentActionProvider({
548
548
  if (signal?.aborted) return null;
549
549
  for (const entry of targetsRef.current.values()) {
550
550
  if ((!entry.action || entry.action === actionName) && entry.name === name && entry.element.isConnected) {
551
+ if (entry.prepareView && params) {
552
+ await entry.prepareView(params);
553
+ }
551
554
  return entry.element;
552
555
  }
553
556
  }
@@ -846,10 +849,12 @@ function AgentStep({
846
849
  if (!children) return null;
847
850
  return /* @__PURE__ */ jsx("div", { ref: wrapperRef, style: { display: "contents" }, children });
848
851
  }
849
- function AgentTarget({ action, param, value, name, children }) {
852
+ function AgentTarget({ action, param, value, name, prepareView, children }) {
850
853
  const id = useId();
851
854
  const wrapperRef = useRef(null);
852
855
  const context = useContext(AgentActionContext);
856
+ const prepareViewRef = useRef(prepareView);
857
+ prepareViewRef.current = prepareView;
853
858
  if (!context) {
854
859
  throw new Error("AgentTarget must be used within an AgentActionProvider");
855
860
  }
@@ -857,7 +862,7 @@ function AgentTarget({ action, param, value, name, children }) {
857
862
  useEffect(() => {
858
863
  const element = wrapperRef.current?.firstElementChild;
859
864
  if (element) {
860
- registerTarget(id, { action, param, value, name, element });
865
+ registerTarget(id, { action, param, value, name, element, prepareView: prepareViewRef.current });
861
866
  }
862
867
  return () => unregisterTarget(id);
863
868
  }, [id, action, param, value, name, registerTarget, unregisterTarget]);