@jay-framework/stack-client-runtime 0.11.0 → 0.12.0

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
@@ -79,6 +79,23 @@ function mergeArraysByTrackBy$1(baseArray, overlayArray, trackByField, trackByMa
79
79
  }
80
80
  });
81
81
  }
82
+ const HEADLESS_INSTANCES = runtime.createJayContext();
83
+ function makeSignals$1(obj) {
84
+ return Object.keys(obj).reduce((signals, key) => {
85
+ signals[key] = component.createSignal(obj[key]);
86
+ return signals;
87
+ }, {});
88
+ }
89
+ function makeHeadlessInstanceComponent(preRender, interactiveConstructor, coordinateKey, pluginContexts = []) {
90
+ const wrappedConstructor = (props, refs, ...pluginResolvedContexts) => {
91
+ const instanceData = runtime.useContext(HEADLESS_INSTANCES);
92
+ const fastVS = instanceData?.viewStates?.[coordinateKey];
93
+ const cf = instanceData?.carryForwards?.[coordinateKey] || {};
94
+ const signalVS = fastVS ? makeSignals$1(fastVS) : void 0;
95
+ return interactiveConstructor(props, refs, signalVS, cf, ...pluginResolvedContexts);
96
+ };
97
+ return component.makeJayComponent(preRender, wrappedConstructor, ...pluginContexts);
98
+ }
82
99
  function makeSignals(obj) {
83
100
  return Object.keys(obj).reduce((signals, key) => {
84
101
  signals[key] = component.createSignal(obj[key]);
@@ -88,7 +105,21 @@ function makeSignals(obj) {
88
105
  function makeCompositeJayComponent(preRender, defaultViewState, fastCarryForward, parts, trackByMap = {}) {
89
106
  const interactiveParts = parts.filter((part) => part.comp !== void 0);
90
107
  const hasFastRendering = defaultViewState !== null && defaultViewState !== void 0;
108
+ const headlessInstanceViewStates = defaultViewState?.__headlessInstances;
109
+ const headlessInstanceCarryForwards = fastCarryForward?.__headlessInstances;
110
+ if (headlessInstanceViewStates)
111
+ delete defaultViewState.__headlessInstances;
112
+ if (headlessInstanceCarryForwards)
113
+ delete fastCarryForward.__headlessInstances;
91
114
  const comp = (props, refs, ...contexts) => {
115
+ if (headlessInstanceViewStates || headlessInstanceCarryForwards) {
116
+ const componentContext = runtime.useContext(component.COMPONENT_CONTEXT);
117
+ const instancesData = {
118
+ viewStates: headlessInstanceViewStates || {},
119
+ carryForwards: headlessInstanceCarryForwards || {}
120
+ };
121
+ componentContext.provideContexts.push([HEADLESS_INSTANCES, instancesData]);
122
+ }
92
123
  const instances = interactiveParts.map(
93
124
  (part) => {
94
125
  const partRefs = part.key ? refs[part.key] : refs;
@@ -487,7 +518,9 @@ function wrapWithAutomation(component2, options) {
487
518
  const AUTOMATION_CONTEXT = runtime.createJayContext();
488
519
  exports.AUTOMATION_CONTEXT = AUTOMATION_CONTEXT;
489
520
  exports.ActionError = ActionError;
521
+ exports.HEADLESS_INSTANCES = HEADLESS_INSTANCES;
490
522
  exports.createActionCaller = createActionCaller;
491
523
  exports.makeCompositeJayComponent = makeCompositeJayComponent;
524
+ exports.makeHeadlessInstanceComponent = makeHeadlessInstanceComponent;
492
525
  exports.setActionCallerOptions = setActionCallerOptions;
493
526
  exports.wrapWithAutomation = wrapWithAutomation;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _jay_framework_component from '@jay-framework/component';
2
2
  import { ComponentConstructor, ContextMarkers, JayComponentCore } from '@jay-framework/component';
3
- import { JayElement, PreRenderElement } from '@jay-framework/runtime';
3
+ import { JayElement, PreRenderElement, ContextMarker } from '@jay-framework/runtime';
4
4
  import { TrackByMap } from '@jay-framework/view-state-merge';
5
5
  export { AUTOMATION_CONTEXT, AutomationAPI, AutomationWrappedComponent, Coordinate, Interaction, PageState, wrapWithAutomation } from '@jay-framework/runtime-automation';
6
6
 
@@ -17,6 +17,47 @@ interface CompositePart {
17
17
 
18
18
  declare function makeCompositeJayComponent<PropsT extends object, ViewState extends object, Refs extends object, JayElementT extends JayElement<ViewState, Refs>, CompCore extends JayComponentCore<PropsT, ViewState>>(preRender: PreRenderElement<ViewState, Refs, JayElementT>, defaultViewState: ViewState, fastCarryForward: object, parts: Array<CompositePart>, trackByMap?: TrackByMap): (props: PropsT) => _jay_framework_component.ConcreteJayComponent<PropsT, ViewState, Refs, CompCore, JayElementT>;
19
19
 
20
+ /**
21
+ * Client-side context and helpers for headless component instances.
22
+ *
23
+ * Provides the mechanism to deliver server-produced fast ViewState and carryForward
24
+ * to headless component instances on the client.
25
+ *
26
+ * Flow:
27
+ * 1. makeCompositeJayComponent extracts __headlessInstances from ViewState/carryForward
28
+ * 2. Registers HEADLESS_INSTANCES context during component construction
29
+ * 3. makeHeadlessInstanceComponent creates instance components that resolve their data
30
+ * from this context by coordinate key
31
+ */
32
+
33
+ /**
34
+ * Data structure for headless instance ViewStates and carryForwards.
35
+ * Keyed by coordinate path (e.g., "product-card:0", "p1/product-card:0").
36
+ */
37
+ interface HeadlessInstancesData {
38
+ viewStates: Record<string, object>;
39
+ carryForwards: Record<string, object>;
40
+ }
41
+ /**
42
+ * Context marker for headless instance data.
43
+ * Provided by makeCompositeJayComponent, consumed by makeHeadlessInstanceComponent.
44
+ */
45
+ declare const HEADLESS_INSTANCES: ContextMarker<HeadlessInstancesData>;
46
+ /**
47
+ * Create a headless instance component that receives its fast ViewState from the
48
+ * HEADLESS_INSTANCES context, matched by coordinate key.
49
+ *
50
+ * This replaces makeJayComponent for headless instances. It wraps the plugin's
51
+ * interactive constructor to inject the instance's fast ViewState signals and
52
+ * carryForward before any plugin-defined context markers.
53
+ *
54
+ * @param preRender - The inline template's render function
55
+ * @param interactiveConstructor - The plugin's interactive constructor
56
+ * @param coordinateKey - The coordinate key for this instance (e.g., "product-card:0")
57
+ * @param pluginContexts - Additional context markers from the plugin (if any)
58
+ */
59
+ declare function makeHeadlessInstanceComponent<PropsT extends object, ViewState extends object, Refs extends object, JayElementT extends JayElement<ViewState, Refs>, CompCore extends JayComponentCore<PropsT, ViewState>>(preRender: PreRenderElement<ViewState, Refs, JayElementT>, interactiveConstructor: ComponentConstructor<PropsT, Refs, ViewState, any, CompCore>, coordinateKey: string, pluginContexts?: ContextMarkers<any>): any;
60
+
20
61
  /**
21
62
  * Client-side action caller for Jay Stack.
22
63
  *
@@ -82,4 +123,4 @@ declare function setActionCallerOptions(options: ActionCallerOptions): void;
82
123
  */
83
124
  declare function createActionCaller<Input, Output>(actionName: string, method?: HttpMethod): (input: Input) => Promise<Output>;
84
125
 
85
- export { type ActionCallerOptions, ActionError, type CompositePart, type HttpMethod, createActionCaller, makeCompositeJayComponent, setActionCallerOptions };
126
+ export { type ActionCallerOptions, ActionError, type CompositePart, HEADLESS_INSTANCES, type HeadlessInstancesData, type HttpMethod, createActionCaller, makeCompositeJayComponent, makeHeadlessInstanceComponent, setActionCallerOptions };
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ var __publicField = (obj, key, value) => {
4
4
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
  return value;
6
6
  };
7
- import { makeJayComponent, materializeViewState, createSignal } from "@jay-framework/component";
8
- import { createJayContext } from "@jay-framework/runtime";
7
+ import { makeJayComponent, createSignal, COMPONENT_CONTEXT, materializeViewState } from "@jay-framework/component";
8
+ import { createJayContext, useContext } from "@jay-framework/runtime";
9
9
  function deepMergeViewStates$1(base, overlay, trackByMap, path = "") {
10
10
  if (!base && !overlay)
11
11
  return {};
@@ -77,6 +77,23 @@ function mergeArraysByTrackBy$1(baseArray, overlayArray, trackByField, trackByMa
77
77
  }
78
78
  });
79
79
  }
80
+ const HEADLESS_INSTANCES = createJayContext();
81
+ function makeSignals$1(obj) {
82
+ return Object.keys(obj).reduce((signals, key) => {
83
+ signals[key] = createSignal(obj[key]);
84
+ return signals;
85
+ }, {});
86
+ }
87
+ function makeHeadlessInstanceComponent(preRender, interactiveConstructor, coordinateKey, pluginContexts = []) {
88
+ const wrappedConstructor = (props, refs, ...pluginResolvedContexts) => {
89
+ const instanceData = useContext(HEADLESS_INSTANCES);
90
+ const fastVS = instanceData?.viewStates?.[coordinateKey];
91
+ const cf = instanceData?.carryForwards?.[coordinateKey] || {};
92
+ const signalVS = fastVS ? makeSignals$1(fastVS) : void 0;
93
+ return interactiveConstructor(props, refs, signalVS, cf, ...pluginResolvedContexts);
94
+ };
95
+ return makeJayComponent(preRender, wrappedConstructor, ...pluginContexts);
96
+ }
80
97
  function makeSignals(obj) {
81
98
  return Object.keys(obj).reduce((signals, key) => {
82
99
  signals[key] = createSignal(obj[key]);
@@ -86,7 +103,21 @@ function makeSignals(obj) {
86
103
  function makeCompositeJayComponent(preRender, defaultViewState, fastCarryForward, parts, trackByMap = {}) {
87
104
  const interactiveParts = parts.filter((part) => part.comp !== void 0);
88
105
  const hasFastRendering = defaultViewState !== null && defaultViewState !== void 0;
106
+ const headlessInstanceViewStates = defaultViewState?.__headlessInstances;
107
+ const headlessInstanceCarryForwards = fastCarryForward?.__headlessInstances;
108
+ if (headlessInstanceViewStates)
109
+ delete defaultViewState.__headlessInstances;
110
+ if (headlessInstanceCarryForwards)
111
+ delete fastCarryForward.__headlessInstances;
89
112
  const comp = (props, refs, ...contexts) => {
113
+ if (headlessInstanceViewStates || headlessInstanceCarryForwards) {
114
+ const componentContext = useContext(COMPONENT_CONTEXT);
115
+ const instancesData = {
116
+ viewStates: headlessInstanceViewStates || {},
117
+ carryForwards: headlessInstanceCarryForwards || {}
118
+ };
119
+ componentContext.provideContexts.push([HEADLESS_INSTANCES, instancesData]);
120
+ }
90
121
  const instances = interactiveParts.map(
91
122
  (part) => {
92
123
  const partRefs = part.key ? refs[part.key] : refs;
@@ -486,8 +517,10 @@ const AUTOMATION_CONTEXT = createJayContext();
486
517
  export {
487
518
  AUTOMATION_CONTEXT,
488
519
  ActionError,
520
+ HEADLESS_INSTANCES,
489
521
  createActionCaller,
490
522
  makeCompositeJayComponent,
523
+ makeHeadlessInstanceComponent,
491
524
  setActionCallerOptions,
492
525
  wrapWithAutomation
493
526
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/stack-client-runtime",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -27,15 +27,15 @@
27
27
  "test:watch": "vitest"
28
28
  },
29
29
  "dependencies": {
30
- "@jay-framework/component": "^0.11.0",
31
- "@jay-framework/fullstack-component": "^0.11.0",
32
- "@jay-framework/runtime": "^0.11.0",
33
- "@jay-framework/runtime-automation": "^0.11.0",
34
- "@jay-framework/view-state-merge": "^0.11.0"
30
+ "@jay-framework/component": "^0.12.0",
31
+ "@jay-framework/fullstack-component": "^0.12.0",
32
+ "@jay-framework/runtime": "^0.12.0",
33
+ "@jay-framework/runtime-automation": "^0.12.0",
34
+ "@jay-framework/view-state-merge": "^0.12.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@jay-framework/dev-environment": "^0.11.0",
38
- "@jay-framework/jay-cli": "^0.11.0",
37
+ "@jay-framework/dev-environment": "^0.12.0",
38
+ "@jay-framework/jay-cli": "^0.12.0",
39
39
  "@types/express": "^5.0.2",
40
40
  "@types/node": "^22.15.21",
41
41
  "nodemon": "^3.0.3",