@almadar/ui 4.28.0 → 4.29.1

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.
@@ -29334,6 +29334,8 @@ var init_Form = __esm({
29334
29334
  const [collapsedSections, setCollapsedSections] = React118__namespace.default.useState(
29335
29335
  /* @__PURE__ */ new Set()
29336
29336
  );
29337
+ const [submitError, setSubmitError] = React118__namespace.default.useState(null);
29338
+ const formRef = React118__namespace.default.useRef(null);
29337
29339
  const formMode = props.mode;
29338
29340
  const mountedRef = React118__namespace.default.useRef(false);
29339
29341
  if (!mountedRef.current) {
@@ -29459,6 +29461,7 @@ var init_Form = __esm({
29459
29461
  };
29460
29462
  const handleSubmit = (e) => {
29461
29463
  e.preventDefault();
29464
+ setSubmitError(null);
29462
29465
  debug("forms", "submit-enter", {
29463
29466
  mode: formMode,
29464
29467
  submitEvent,
@@ -29476,6 +29479,37 @@ var init_Form = __esm({
29476
29479
  eventBus.emit(`UI:${onSubmit}`, payload);
29477
29480
  }
29478
29481
  };
29482
+ const handleInvalid = (e) => {
29483
+ const target = e.target;
29484
+ const fieldName = target.getAttribute("data-field-name") ?? target.name ?? "";
29485
+ const fieldMessage = target.validationMessage || "Invalid value";
29486
+ debug("forms", "invalid", { mode: formMode, fieldName, fieldMessage });
29487
+ queueMicrotask(() => {
29488
+ const form = formRef.current;
29489
+ if (!form) return;
29490
+ const invalidEls = Array.from(
29491
+ form.querySelectorAll(
29492
+ ":invalid"
29493
+ )
29494
+ );
29495
+ if (invalidEls.length === 0) return;
29496
+ const missing = invalidEls.map(
29497
+ (el) => el.getAttribute("data-field-name") ?? el.name ?? ""
29498
+ );
29499
+ const messages = invalidEls.map((el) => ({
29500
+ field: el.getAttribute("data-field-name") ?? el.name ?? "",
29501
+ message: el.validationMessage
29502
+ }));
29503
+ const summary = missing.length === 1 ? `${missing[0]}: ${messages[0]?.message}` : `Please fix ${missing.length} fields: ${missing.join(", ")}`;
29504
+ setSubmitError(summary);
29505
+ eventBus.emit("UI:VALIDATION_FAILED", {
29506
+ submitEvent,
29507
+ missing,
29508
+ messages,
29509
+ summary
29510
+ });
29511
+ });
29512
+ };
29479
29513
  const handleCancel = () => {
29480
29514
  eventBus.emit(`UI:${cancelEvent}`);
29481
29515
  eventBus.emit("UI:CLOSE");
@@ -29579,7 +29613,8 @@ var init_Form = __esm({
29579
29613
  "data-field-name": fieldName,
29580
29614
  required: field.required,
29581
29615
  disabled: isLoading,
29582
- placeholder: field.placeholder
29616
+ placeholder: field.placeholder,
29617
+ pattern: field.pattern
29583
29618
  };
29584
29619
  switch (inputType) {
29585
29620
  case "checkbox":
@@ -29675,7 +29710,9 @@ var init_Form = __esm({
29675
29710
  ...commonProps,
29676
29711
  type: "email",
29677
29712
  value: String(currentValue),
29678
- onChange: (e) => handleChange(fieldName, e.target.value)
29713
+ onChange: (e) => handleChange(fieldName, e.target.value),
29714
+ minLength: field.min,
29715
+ maxLength: field.max
29679
29716
  }
29680
29717
  );
29681
29718
  case "url":
@@ -29685,7 +29722,9 @@ var init_Form = __esm({
29685
29722
  ...commonProps,
29686
29723
  type: "url",
29687
29724
  value: String(currentValue),
29688
- onChange: (e) => handleChange(fieldName, e.target.value)
29725
+ onChange: (e) => handleChange(fieldName, e.target.value),
29726
+ minLength: field.min,
29727
+ maxLength: field.max
29689
29728
  }
29690
29729
  );
29691
29730
  case "password":
@@ -29695,7 +29734,9 @@ var init_Form = __esm({
29695
29734
  ...commonProps,
29696
29735
  type: "password",
29697
29736
  value: String(currentValue),
29698
- onChange: (e) => handleChange(fieldName, e.target.value)
29737
+ onChange: (e) => handleChange(fieldName, e.target.value),
29738
+ minLength: field.min,
29739
+ maxLength: field.max
29699
29740
  }
29700
29741
  );
29701
29742
  case "text":
@@ -29708,8 +29749,7 @@ var init_Form = __esm({
29708
29749
  value: String(currentValue),
29709
29750
  onChange: (e) => handleChange(fieldName, e.target.value),
29710
29751
  minLength: field.min,
29711
- maxLength: field.max,
29712
- pattern: field.pattern
29752
+ maxLength: field.max
29713
29753
  }
29714
29754
  );
29715
29755
  }
@@ -29717,12 +29757,14 @@ var init_Form = __esm({
29717
29757
  return /* @__PURE__ */ jsxRuntime.jsxs(
29718
29758
  "form",
29719
29759
  {
29720
- noValidate: true,
29760
+ ref: formRef,
29721
29761
  "data-pattern": "form-section",
29722
29762
  className: cn(layoutStyles[layout], gapStyles8[gap], className),
29723
29763
  onSubmit: handleSubmit,
29764
+ onInvalid: handleInvalid,
29724
29765
  ...props,
29725
29766
  children: [
29767
+ submitError && /* @__PURE__ */ jsxRuntime.jsx(Alert, { variant: "error", className: "mb-4", children: submitError }),
29726
29768
  error && /* @__PURE__ */ jsxRuntime.jsx(Alert, { variant: "error", className: "mb-4", children: error.message || t("error.occurred") }),
29727
29769
  sectionElements && sectionElements.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(VStack, { gap: gap === "sm" ? "sm" : gap === "lg" ? "lg" : "md", children: sectionElements }),
29728
29770
  schemaFields,
@@ -49603,6 +49645,7 @@ function useTraitStateMachine(traitBindings, uiSlots, options) {
49603
49645
  }
49604
49646
  console.log("[TraitStateMachine] Subscribing to events:", Array.from(allEvents));
49605
49647
  const unsubscribes = [];
49648
+ const subscribedBusKeys = /* @__PURE__ */ new Set();
49606
49649
  for (const binding of traitBindings) {
49607
49650
  const traitName = binding.trait.name;
49608
49651
  const orbitalName = orbitalsByTrait?.[traitName];
@@ -49613,6 +49656,8 @@ function useTraitStateMachine(traitBindings, uiSlots, options) {
49613
49656
  continue;
49614
49657
  }
49615
49658
  const selfBusKey = `UI:${orbitalName}.${traitName}.${eventKey}`;
49659
+ if (subscribedBusKeys.has(selfBusKey)) continue;
49660
+ subscribedBusKeys.add(selfBusKey);
49616
49661
  crossTraitLog.debug("self:subscribe", { traitName, busKey: selfBusKey, eventKey });
49617
49662
  const unsub = eventBus.on(selfBusKey, (event) => {
49618
49663
  if (event.source && event.source.dispatched) {
@@ -50433,6 +50478,11 @@ function formatPayloadTooltip(fields) {
50433
50478
  );
50434
50479
  return `{ ${parts.join(", ")} }`;
50435
50480
  }
50481
+ function entityNameOf(ref) {
50482
+ if (!ref) return void 0;
50483
+ if (typeof ref === "string") return ref;
50484
+ return "name" in ref ? ref.name : void 0;
50485
+ }
50436
50486
  var ScreenSizeContext = React118.createContext("tablet");
50437
50487
  var PatternSelectionContext = React118.createContext({ selected: null, select: () => {
50438
50488
  } });
@@ -50473,19 +50523,116 @@ function buildOrbitalSchema(fullSchema, orbitalName) {
50473
50523
  if (!orbital) return fullSchema;
50474
50524
  return { ...fullSchema, name: `${fullSchema.name}__${orbitalName}`, orbitals: [orbital] };
50475
50525
  }
50476
- function buildTransitionSchema(fullSchema, orbitalName, traitName, transitionEvent, fromState, toState) {
50526
+ function generateMockPayload(payloadSchema, schema, linkedEntity, mockData) {
50527
+ const payload = {};
50528
+ if (!payloadSchema || payloadSchema.length === 0) return payload;
50529
+ const entityNames = /* @__PURE__ */ new Set();
50530
+ for (const orb of schema.orbitals ?? []) {
50531
+ const name = entityNameOf(orb.entity);
50532
+ if (name) entityNames.add(name);
50533
+ }
50534
+ const linkedRows = linkedEntity ? mockData?.[linkedEntity] ?? [] : [];
50535
+ const linkedFirstRow = linkedRows[0];
50536
+ const valueForType = (rawType, entityType) => {
50537
+ const type = rawType.replace(/!$/, "").trim();
50538
+ const arrayMatch = /^\[\s*(\w+)\s*\]$/.exec(type);
50539
+ if (arrayMatch) {
50540
+ return mockData?.[arrayMatch[1]] ?? linkedRows;
50541
+ }
50542
+ if (type === "array") return linkedRows;
50543
+ if (type === "entity") {
50544
+ const target = entityType && mockData?.[entityType] ? entityType : linkedEntity;
50545
+ return (target && mockData?.[target]?.[0]) ?? linkedFirstRow ?? {};
50546
+ }
50547
+ if (entityNames.has(type)) {
50548
+ return mockData?.[type]?.[0] ?? linkedFirstRow ?? {};
50549
+ }
50550
+ switch (type) {
50551
+ case "string":
50552
+ return "Sample";
50553
+ case "number":
50554
+ return 1;
50555
+ case "boolean":
50556
+ return false;
50557
+ case "object":
50558
+ return {};
50559
+ case "date":
50560
+ case "datetime":
50561
+ case "timestamp":
50562
+ return (/* @__PURE__ */ new Date()).toISOString();
50563
+ default:
50564
+ return void 0;
50565
+ }
50566
+ };
50567
+ const setByPath = (target, path, value) => {
50568
+ const parts = path.split(".");
50569
+ let cur = target;
50570
+ for (let i = 0; i < parts.length - 1; i++) {
50571
+ const k = parts[i];
50572
+ const next = cur[k];
50573
+ if (next === null || typeof next !== "object" || Array.isArray(next)) {
50574
+ cur[k] = {};
50575
+ }
50576
+ cur = cur[k];
50577
+ }
50578
+ cur[parts[parts.length - 1]] = value;
50579
+ };
50580
+ for (const field of payloadSchema) {
50581
+ let value = valueForType(field.type, field.entityType);
50582
+ if (linkedFirstRow !== void 0 && field.name.includes(".") && (typeof value === "string" || typeof value === "number" || typeof value === "boolean")) {
50583
+ const tail = field.name.split(".").pop();
50584
+ const fromRow = linkedFirstRow[tail];
50585
+ if (fromRow !== void 0) value = fromRow;
50586
+ }
50587
+ setByPath(payload, field.name, value);
50588
+ }
50589
+ return payload;
50590
+ }
50591
+ function substitutePayloadBindings(effects, payload) {
50592
+ const isPayloadObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && !(v instanceof Date);
50593
+ const getByPath = (path) => {
50594
+ let cur = payload;
50595
+ for (const k of path.split(".")) {
50596
+ if (!isPayloadObject(cur)) return void 0;
50597
+ cur = cur[k];
50598
+ }
50599
+ return cur;
50600
+ };
50601
+ const replaceValue = (v) => {
50602
+ if (typeof v === "string" && v.startsWith("@payload.")) {
50603
+ const resolved = getByPath(v.slice("@payload.".length));
50604
+ return resolved === void 0 ? v : resolved;
50605
+ }
50606
+ if (Array.isArray(v)) return v.map(replaceValue);
50607
+ if (v && typeof v === "object" && !(v instanceof Date)) {
50608
+ const out = {};
50609
+ for (const [k, inner] of Object.entries(v)) {
50610
+ out[k] = replaceValue(inner);
50611
+ }
50612
+ return out;
50613
+ }
50614
+ return v;
50615
+ };
50616
+ const tree = JSON.parse(JSON.stringify(effects));
50617
+ const substituted = replaceValue(tree);
50618
+ return substituted;
50619
+ }
50620
+ function findEmitContract(trait, event) {
50621
+ return trait.emits?.find((e) => e.event === event);
50622
+ }
50623
+ function buildTransitionSchema(fullSchema, orbitalName, traitName, transitionEvent, fromState, toState, mockData) {
50477
50624
  const orbital = (fullSchema.orbitals ?? []).find((o) => o.name === orbitalName);
50478
50625
  if (!orbital) return fullSchema;
50479
50626
  const clonedOrbital = JSON.parse(JSON.stringify(orbital));
50480
50627
  const traits2 = clonedOrbital.traits ?? [];
50481
50628
  for (let ti = 0; ti < traits2.length; ti++) {
50482
50629
  const trait = traits2[ti];
50483
- if (typeof trait === "string" || !("stateMachine" in trait)) continue;
50630
+ if (!core.isInlineTrait(trait)) continue;
50484
50631
  const traitObj = trait;
50485
50632
  if (traitObj.name !== traitName) continue;
50486
50633
  const sm = traitObj.stateMachine;
50487
50634
  if (!sm) continue;
50488
- const allTransitions = sm.transitions;
50635
+ const allTransitions = sm.transitions ?? [];
50489
50636
  const targetTransition = fromState && toState ? allTransitions.find((t) => t.event === transitionEvent && t.from === fromState && t.to === toState) ?? allTransitions.find((t) => t.event === transitionEvent) : allTransitions.find((t) => t.event === transitionEvent);
50490
50637
  if (!targetTransition?.effects) continue;
50491
50638
  const renderUIEffects = [];
@@ -50495,14 +50642,22 @@ function buildTransitionSchema(fullSchema, orbitalName, traitName, transitionEve
50495
50642
  }
50496
50643
  }
50497
50644
  if (renderUIEffects.length === 0) continue;
50498
- const rewrittenSm = {
50645
+ const linkedEntity = traitObj.linkedEntity ?? entityNameOf(clonedOrbital.entity);
50646
+ const emitContract = findEmitContract(traitObj, transitionEvent);
50647
+ const mockPayload = generateMockPayload(
50648
+ emitContract?.payloadSchema,
50649
+ fullSchema,
50650
+ linkedEntity,
50651
+ mockData
50652
+ );
50653
+ const seededEffects = substitutePayloadBindings(renderUIEffects, mockPayload);
50654
+ traitObj.stateMachine = {
50499
50655
  states: [{ name: "preview", isInitial: true }],
50500
50656
  events: [{ key: "INIT", name: "INIT" }],
50501
- transitions: [{ from: "preview", to: "preview", event: "INIT", effects: renderUIEffects }]
50657
+ transitions: [{ from: "preview", to: "preview", event: "INIT", effects: seededEffects }]
50502
50658
  };
50503
- traits2[ti].stateMachine = rewrittenSm;
50504
- traits2[ti].emits = [];
50505
- traits2[ti].listens = [];
50659
+ traitObj.emits = [];
50660
+ traitObj.listens = [];
50506
50661
  break;
50507
50662
  }
50508
50663
  const targetTrait = traits2.find((t) => {
@@ -50568,11 +50723,12 @@ var OrbPreviewNodeInner = (props) => {
50568
50723
  data.traitName,
50569
50724
  data.transitionEvent,
50570
50725
  data.fromState,
50571
- data.toState
50726
+ data.toState,
50727
+ data._mockData
50572
50728
  );
50573
50729
  }
50574
50730
  return buildOrbitalSchema(fullSchema, data.orbitalName);
50575
- }, [data._fullSchema, data.orbitalName, data.traitName, data.transitionEvent, data.fromState, data.toState, isExpanded]);
50731
+ }, [data._fullSchema, data._mockData, data.orbitalName, data.traitName, data.transitionEvent, data.fromState, data.toState, isExpanded]);
50576
50732
  const handleContentClick = React118.useCallback((e) => {
50577
50733
  e.stopPropagation();
50578
50734
  const target = e.target;
package/dist/avl/index.js CHANGED
@@ -30,7 +30,7 @@ import langDiff from 'react-syntax-highlighter/dist/esm/languages/prism/diff.js'
30
30
  import langToml from 'react-syntax-highlighter/dist/esm/languages/prism/toml.js';
31
31
  import langGo from 'react-syntax-highlighter/dist/esm/languages/prism/go.js';
32
32
  import langGraphql from 'react-syntax-highlighter/dist/esm/languages/prism/graphql.js';
33
- import { FieldTypeSchema, isEntityCall, schemaToIR, getPage, isCircuitEvent, isInlineTrait } from '@almadar/core';
33
+ import { FieldTypeSchema, isInlineTrait, isEntityCall, schemaToIR, getPage, isCircuitEvent } from '@almadar/core';
34
34
  import { useThree, useFrame, Canvas } from '@react-three/fiber';
35
35
  import * as THREE6 from 'three';
36
36
  import { Vector3, QuadraticBezierCurve3, MathUtils, Quaternion } from 'three';
@@ -29288,6 +29288,8 @@ var init_Form = __esm({
29288
29288
  const [collapsedSections, setCollapsedSections] = React118__default.useState(
29289
29289
  /* @__PURE__ */ new Set()
29290
29290
  );
29291
+ const [submitError, setSubmitError] = React118__default.useState(null);
29292
+ const formRef = React118__default.useRef(null);
29291
29293
  const formMode = props.mode;
29292
29294
  const mountedRef = React118__default.useRef(false);
29293
29295
  if (!mountedRef.current) {
@@ -29413,6 +29415,7 @@ var init_Form = __esm({
29413
29415
  };
29414
29416
  const handleSubmit = (e) => {
29415
29417
  e.preventDefault();
29418
+ setSubmitError(null);
29416
29419
  debug("forms", "submit-enter", {
29417
29420
  mode: formMode,
29418
29421
  submitEvent,
@@ -29430,6 +29433,37 @@ var init_Form = __esm({
29430
29433
  eventBus.emit(`UI:${onSubmit}`, payload);
29431
29434
  }
29432
29435
  };
29436
+ const handleInvalid = (e) => {
29437
+ const target = e.target;
29438
+ const fieldName = target.getAttribute("data-field-name") ?? target.name ?? "";
29439
+ const fieldMessage = target.validationMessage || "Invalid value";
29440
+ debug("forms", "invalid", { mode: formMode, fieldName, fieldMessage });
29441
+ queueMicrotask(() => {
29442
+ const form = formRef.current;
29443
+ if (!form) return;
29444
+ const invalidEls = Array.from(
29445
+ form.querySelectorAll(
29446
+ ":invalid"
29447
+ )
29448
+ );
29449
+ if (invalidEls.length === 0) return;
29450
+ const missing = invalidEls.map(
29451
+ (el) => el.getAttribute("data-field-name") ?? el.name ?? ""
29452
+ );
29453
+ const messages = invalidEls.map((el) => ({
29454
+ field: el.getAttribute("data-field-name") ?? el.name ?? "",
29455
+ message: el.validationMessage
29456
+ }));
29457
+ const summary = missing.length === 1 ? `${missing[0]}: ${messages[0]?.message}` : `Please fix ${missing.length} fields: ${missing.join(", ")}`;
29458
+ setSubmitError(summary);
29459
+ eventBus.emit("UI:VALIDATION_FAILED", {
29460
+ submitEvent,
29461
+ missing,
29462
+ messages,
29463
+ summary
29464
+ });
29465
+ });
29466
+ };
29433
29467
  const handleCancel = () => {
29434
29468
  eventBus.emit(`UI:${cancelEvent}`);
29435
29469
  eventBus.emit("UI:CLOSE");
@@ -29533,7 +29567,8 @@ var init_Form = __esm({
29533
29567
  "data-field-name": fieldName,
29534
29568
  required: field.required,
29535
29569
  disabled: isLoading,
29536
- placeholder: field.placeholder
29570
+ placeholder: field.placeholder,
29571
+ pattern: field.pattern
29537
29572
  };
29538
29573
  switch (inputType) {
29539
29574
  case "checkbox":
@@ -29629,7 +29664,9 @@ var init_Form = __esm({
29629
29664
  ...commonProps,
29630
29665
  type: "email",
29631
29666
  value: String(currentValue),
29632
- onChange: (e) => handleChange(fieldName, e.target.value)
29667
+ onChange: (e) => handleChange(fieldName, e.target.value),
29668
+ minLength: field.min,
29669
+ maxLength: field.max
29633
29670
  }
29634
29671
  );
29635
29672
  case "url":
@@ -29639,7 +29676,9 @@ var init_Form = __esm({
29639
29676
  ...commonProps,
29640
29677
  type: "url",
29641
29678
  value: String(currentValue),
29642
- onChange: (e) => handleChange(fieldName, e.target.value)
29679
+ onChange: (e) => handleChange(fieldName, e.target.value),
29680
+ minLength: field.min,
29681
+ maxLength: field.max
29643
29682
  }
29644
29683
  );
29645
29684
  case "password":
@@ -29649,7 +29688,9 @@ var init_Form = __esm({
29649
29688
  ...commonProps,
29650
29689
  type: "password",
29651
29690
  value: String(currentValue),
29652
- onChange: (e) => handleChange(fieldName, e.target.value)
29691
+ onChange: (e) => handleChange(fieldName, e.target.value),
29692
+ minLength: field.min,
29693
+ maxLength: field.max
29653
29694
  }
29654
29695
  );
29655
29696
  case "text":
@@ -29662,8 +29703,7 @@ var init_Form = __esm({
29662
29703
  value: String(currentValue),
29663
29704
  onChange: (e) => handleChange(fieldName, e.target.value),
29664
29705
  minLength: field.min,
29665
- maxLength: field.max,
29666
- pattern: field.pattern
29706
+ maxLength: field.max
29667
29707
  }
29668
29708
  );
29669
29709
  }
@@ -29671,12 +29711,14 @@ var init_Form = __esm({
29671
29711
  return /* @__PURE__ */ jsxs(
29672
29712
  "form",
29673
29713
  {
29674
- noValidate: true,
29714
+ ref: formRef,
29675
29715
  "data-pattern": "form-section",
29676
29716
  className: cn(layoutStyles[layout], gapStyles8[gap], className),
29677
29717
  onSubmit: handleSubmit,
29718
+ onInvalid: handleInvalid,
29678
29719
  ...props,
29679
29720
  children: [
29721
+ submitError && /* @__PURE__ */ jsx(Alert, { variant: "error", className: "mb-4", children: submitError }),
29680
29722
  error && /* @__PURE__ */ jsx(Alert, { variant: "error", className: "mb-4", children: error.message || t("error.occurred") }),
29681
29723
  sectionElements && sectionElements.length > 0 && /* @__PURE__ */ jsx(VStack, { gap: gap === "sm" ? "sm" : gap === "lg" ? "lg" : "md", children: sectionElements }),
29682
29724
  schemaFields,
@@ -49557,6 +49599,7 @@ function useTraitStateMachine(traitBindings, uiSlots, options) {
49557
49599
  }
49558
49600
  console.log("[TraitStateMachine] Subscribing to events:", Array.from(allEvents));
49559
49601
  const unsubscribes = [];
49602
+ const subscribedBusKeys = /* @__PURE__ */ new Set();
49560
49603
  for (const binding of traitBindings) {
49561
49604
  const traitName = binding.trait.name;
49562
49605
  const orbitalName = orbitalsByTrait?.[traitName];
@@ -49567,6 +49610,8 @@ function useTraitStateMachine(traitBindings, uiSlots, options) {
49567
49610
  continue;
49568
49611
  }
49569
49612
  const selfBusKey = `UI:${orbitalName}.${traitName}.${eventKey}`;
49613
+ if (subscribedBusKeys.has(selfBusKey)) continue;
49614
+ subscribedBusKeys.add(selfBusKey);
49570
49615
  crossTraitLog.debug("self:subscribe", { traitName, busKey: selfBusKey, eventKey });
49571
49616
  const unsub = eventBus.on(selfBusKey, (event) => {
49572
49617
  if (event.source && event.source.dispatched) {
@@ -50387,6 +50432,11 @@ function formatPayloadTooltip(fields) {
50387
50432
  );
50388
50433
  return `{ ${parts.join(", ")} }`;
50389
50434
  }
50435
+ function entityNameOf(ref) {
50436
+ if (!ref) return void 0;
50437
+ if (typeof ref === "string") return ref;
50438
+ return "name" in ref ? ref.name : void 0;
50439
+ }
50390
50440
  var ScreenSizeContext = createContext("tablet");
50391
50441
  var PatternSelectionContext = createContext({ selected: null, select: () => {
50392
50442
  } });
@@ -50427,19 +50477,116 @@ function buildOrbitalSchema(fullSchema, orbitalName) {
50427
50477
  if (!orbital) return fullSchema;
50428
50478
  return { ...fullSchema, name: `${fullSchema.name}__${orbitalName}`, orbitals: [orbital] };
50429
50479
  }
50430
- function buildTransitionSchema(fullSchema, orbitalName, traitName, transitionEvent, fromState, toState) {
50480
+ function generateMockPayload(payloadSchema, schema, linkedEntity, mockData) {
50481
+ const payload = {};
50482
+ if (!payloadSchema || payloadSchema.length === 0) return payload;
50483
+ const entityNames = /* @__PURE__ */ new Set();
50484
+ for (const orb of schema.orbitals ?? []) {
50485
+ const name = entityNameOf(orb.entity);
50486
+ if (name) entityNames.add(name);
50487
+ }
50488
+ const linkedRows = linkedEntity ? mockData?.[linkedEntity] ?? [] : [];
50489
+ const linkedFirstRow = linkedRows[0];
50490
+ const valueForType = (rawType, entityType) => {
50491
+ const type = rawType.replace(/!$/, "").trim();
50492
+ const arrayMatch = /^\[\s*(\w+)\s*\]$/.exec(type);
50493
+ if (arrayMatch) {
50494
+ return mockData?.[arrayMatch[1]] ?? linkedRows;
50495
+ }
50496
+ if (type === "array") return linkedRows;
50497
+ if (type === "entity") {
50498
+ const target = entityType && mockData?.[entityType] ? entityType : linkedEntity;
50499
+ return (target && mockData?.[target]?.[0]) ?? linkedFirstRow ?? {};
50500
+ }
50501
+ if (entityNames.has(type)) {
50502
+ return mockData?.[type]?.[0] ?? linkedFirstRow ?? {};
50503
+ }
50504
+ switch (type) {
50505
+ case "string":
50506
+ return "Sample";
50507
+ case "number":
50508
+ return 1;
50509
+ case "boolean":
50510
+ return false;
50511
+ case "object":
50512
+ return {};
50513
+ case "date":
50514
+ case "datetime":
50515
+ case "timestamp":
50516
+ return (/* @__PURE__ */ new Date()).toISOString();
50517
+ default:
50518
+ return void 0;
50519
+ }
50520
+ };
50521
+ const setByPath = (target, path, value) => {
50522
+ const parts = path.split(".");
50523
+ let cur = target;
50524
+ for (let i = 0; i < parts.length - 1; i++) {
50525
+ const k = parts[i];
50526
+ const next = cur[k];
50527
+ if (next === null || typeof next !== "object" || Array.isArray(next)) {
50528
+ cur[k] = {};
50529
+ }
50530
+ cur = cur[k];
50531
+ }
50532
+ cur[parts[parts.length - 1]] = value;
50533
+ };
50534
+ for (const field of payloadSchema) {
50535
+ let value = valueForType(field.type, field.entityType);
50536
+ if (linkedFirstRow !== void 0 && field.name.includes(".") && (typeof value === "string" || typeof value === "number" || typeof value === "boolean")) {
50537
+ const tail = field.name.split(".").pop();
50538
+ const fromRow = linkedFirstRow[tail];
50539
+ if (fromRow !== void 0) value = fromRow;
50540
+ }
50541
+ setByPath(payload, field.name, value);
50542
+ }
50543
+ return payload;
50544
+ }
50545
+ function substitutePayloadBindings(effects, payload) {
50546
+ const isPayloadObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && !(v instanceof Date);
50547
+ const getByPath = (path) => {
50548
+ let cur = payload;
50549
+ for (const k of path.split(".")) {
50550
+ if (!isPayloadObject(cur)) return void 0;
50551
+ cur = cur[k];
50552
+ }
50553
+ return cur;
50554
+ };
50555
+ const replaceValue = (v) => {
50556
+ if (typeof v === "string" && v.startsWith("@payload.")) {
50557
+ const resolved = getByPath(v.slice("@payload.".length));
50558
+ return resolved === void 0 ? v : resolved;
50559
+ }
50560
+ if (Array.isArray(v)) return v.map(replaceValue);
50561
+ if (v && typeof v === "object" && !(v instanceof Date)) {
50562
+ const out = {};
50563
+ for (const [k, inner] of Object.entries(v)) {
50564
+ out[k] = replaceValue(inner);
50565
+ }
50566
+ return out;
50567
+ }
50568
+ return v;
50569
+ };
50570
+ const tree = JSON.parse(JSON.stringify(effects));
50571
+ const substituted = replaceValue(tree);
50572
+ return substituted;
50573
+ }
50574
+ function findEmitContract(trait, event) {
50575
+ return trait.emits?.find((e) => e.event === event);
50576
+ }
50577
+ function buildTransitionSchema(fullSchema, orbitalName, traitName, transitionEvent, fromState, toState, mockData) {
50431
50578
  const orbital = (fullSchema.orbitals ?? []).find((o) => o.name === orbitalName);
50432
50579
  if (!orbital) return fullSchema;
50433
50580
  const clonedOrbital = JSON.parse(JSON.stringify(orbital));
50434
50581
  const traits2 = clonedOrbital.traits ?? [];
50435
50582
  for (let ti = 0; ti < traits2.length; ti++) {
50436
50583
  const trait = traits2[ti];
50437
- if (typeof trait === "string" || !("stateMachine" in trait)) continue;
50584
+ if (!isInlineTrait(trait)) continue;
50438
50585
  const traitObj = trait;
50439
50586
  if (traitObj.name !== traitName) continue;
50440
50587
  const sm = traitObj.stateMachine;
50441
50588
  if (!sm) continue;
50442
- const allTransitions = sm.transitions;
50589
+ const allTransitions = sm.transitions ?? [];
50443
50590
  const targetTransition = fromState && toState ? allTransitions.find((t) => t.event === transitionEvent && t.from === fromState && t.to === toState) ?? allTransitions.find((t) => t.event === transitionEvent) : allTransitions.find((t) => t.event === transitionEvent);
50444
50591
  if (!targetTransition?.effects) continue;
50445
50592
  const renderUIEffects = [];
@@ -50449,14 +50596,22 @@ function buildTransitionSchema(fullSchema, orbitalName, traitName, transitionEve
50449
50596
  }
50450
50597
  }
50451
50598
  if (renderUIEffects.length === 0) continue;
50452
- const rewrittenSm = {
50599
+ const linkedEntity = traitObj.linkedEntity ?? entityNameOf(clonedOrbital.entity);
50600
+ const emitContract = findEmitContract(traitObj, transitionEvent);
50601
+ const mockPayload = generateMockPayload(
50602
+ emitContract?.payloadSchema,
50603
+ fullSchema,
50604
+ linkedEntity,
50605
+ mockData
50606
+ );
50607
+ const seededEffects = substitutePayloadBindings(renderUIEffects, mockPayload);
50608
+ traitObj.stateMachine = {
50453
50609
  states: [{ name: "preview", isInitial: true }],
50454
50610
  events: [{ key: "INIT", name: "INIT" }],
50455
- transitions: [{ from: "preview", to: "preview", event: "INIT", effects: renderUIEffects }]
50611
+ transitions: [{ from: "preview", to: "preview", event: "INIT", effects: seededEffects }]
50456
50612
  };
50457
- traits2[ti].stateMachine = rewrittenSm;
50458
- traits2[ti].emits = [];
50459
- traits2[ti].listens = [];
50613
+ traitObj.emits = [];
50614
+ traitObj.listens = [];
50460
50615
  break;
50461
50616
  }
50462
50617
  const targetTrait = traits2.find((t) => {
@@ -50522,11 +50677,12 @@ var OrbPreviewNodeInner = (props) => {
50522
50677
  data.traitName,
50523
50678
  data.transitionEvent,
50524
50679
  data.fromState,
50525
- data.toState
50680
+ data.toState,
50681
+ data._mockData
50526
50682
  );
50527
50683
  }
50528
50684
  return buildOrbitalSchema(fullSchema, data.orbitalName);
50529
- }, [data._fullSchema, data.orbitalName, data.traitName, data.transitionEvent, data.fromState, data.toState, isExpanded]);
50685
+ }, [data._fullSchema, data._mockData, data.orbitalName, data.traitName, data.transitionEvent, data.fromState, data.toState, isExpanded]);
50530
50686
  const handleContentClick = useCallback((e) => {
50531
50687
  e.stopPropagation();
50532
50688
  const target = e.target;