@gravito/ion 2.0.0 → 3.0.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.
package/dist/index.cjs CHANGED
@@ -116,6 +116,7 @@ var InertiaService = class {
116
116
  )
117
117
  );
118
118
  }
119
+ // ...
119
120
  /**
120
121
  * Share data with all Inertia responses
121
122
  *
@@ -154,22 +155,35 @@ var InertiaService = class {
154
155
 
155
156
  // src/index.ts
156
157
  var OrbitIon = class {
158
+ constructor(options = {}) {
159
+ this.options = options;
160
+ }
157
161
  /**
158
- * Install the Inertia orbit into PlanetCore
162
+ * Install the inertia orbit into PlanetCore
159
163
  */
160
164
  install(core) {
161
- core.logger.info("\u{1F6F0}\uFE0F Orbit Inertia installed");
162
- const appVersion = core.config.get("APP_VERSION", "1.0.0");
165
+ core.logger.info("\u{1F6F0}\uFE0F Orbit Inertia installed (Callable Interface)");
166
+ const appVersion = this.options.version ?? core.config.get("APP_VERSION", "1.0.0");
167
+ const rootView = this.options.rootView ?? "app";
163
168
  core.adapter.use("*", async (c, next) => {
164
- const gravitoCtx = c;
165
- const inertia = new InertiaService(gravitoCtx, {
169
+ const service = new InertiaService(c, {
166
170
  version: String(appVersion),
167
- rootView: "app"
168
- // Default to src/views/app.html
171
+ rootView
172
+ });
173
+ const inertiaProxy = (component, props = {}, rootVars = {}) => {
174
+ return service.render(component, props, rootVars);
175
+ };
176
+ Object.assign(inertiaProxy, {
177
+ share: service.share.bind(service),
178
+ shareAll: service.shareAll.bind(service),
179
+ getSharedProps: service.getSharedProps.bind(service),
180
+ render: service.render.bind(service),
181
+ // Also allow .render()
182
+ service
183
+ // Access to the raw service instance
169
184
  });
170
- c.set("inertia", inertia);
171
- await next();
172
- return void 0;
185
+ c.set("inertia", inertiaProxy);
186
+ return await next();
173
187
  });
174
188
  }
175
189
  };
package/dist/index.d.cts CHANGED
@@ -122,33 +122,80 @@ declare class InertiaService {
122
122
  * @since 1.0.0
123
123
  */
124
124
 
125
- declare module '@gravito/core' {
126
- interface GravitoVariables {
127
- /** Inertia.js service for SPA rendering */
128
- inertia?: InertiaService;
129
- }
125
+ /**
126
+ * InertiaHelper is a callable function and service suite injected into the Gravito context.
127
+ * It allows you to render Inertia components directly or manage shared data.
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * // Direct call rendering
132
+ * return ctx.get('inertia')('Welcome', { user });
133
+ *
134
+ * // Using shared data
135
+ * ctx.get('inertia').share('appName', 'Gravito App');
136
+ * ```
137
+ * @public
138
+ */
139
+ interface InertiaHelper {
140
+ /**
141
+ * Render an Inertia component.
142
+ * Shortcut for context.get('inertia').render()
143
+ *
144
+ * @param component - The name of the frontend component (e.g., 'Pages/Home')
145
+ * @param props - Data to pass to the component
146
+ * @param rootVars - Variables for the root HTML template (e.g., meta tags)
147
+ */
148
+ (component: string, props?: Record<string, unknown>, rootVars?: Record<string, unknown>): Response;
149
+ /** Share data with all Inertia responses for the remainder of the request */
150
+ share(key: string, value: unknown): void;
151
+ /** Share multiple props at once */
152
+ shareAll(props: Record<string, unknown>): void;
153
+ /** Get all currently shared props */
154
+ getSharedProps(): Record<string, unknown>;
155
+ /** Explicitly render an Inertia component */
156
+ render(component: string, props?: Record<string, unknown>, rootVars?: Record<string, unknown>): Response;
157
+ /** Direct access to the low-level Inertia service instance */
158
+ service: InertiaService;
130
159
  }
131
160
  /**
132
- * OrbitIon - Inertia.js integration orbit
161
+ * Options for configuring OrbitIon.
162
+ * @public
163
+ */
164
+ interface OrbitIonOptions {
165
+ /** Current asset version to detect staleness (X-Inertia-Version) */
166
+ version?: string;
167
+ /** The root HTML template view (default: 'app') */
168
+ rootView?: string;
169
+ }
170
+ /**
171
+ * OrbitIon provides official Inertia.js integration for Gravito.
133
172
  *
134
- * This orbit provides seamless Inertia.js integration, enabling
135
- * SPA-like navigation with server-side routing.
173
+ * It handles Inertia requests, partial reloads, asset versioning, and seamless
174
+ * data sharing between the server and your frontend application (React, Vue, etc.).
175
+ *
176
+ * It injects an `InertiaHelper` into the context, allowing you to render
177
+ * components with a simple function call: `c.get('inertia')('Page', { props })`.
136
178
  *
137
179
  * @example
138
180
  * ```typescript
139
- * import { PlanetCore, defineConfig } from '@gravito/core'
140
- * import { OrbitIon } from '@gravito/ion'
181
+ * import { OrbitIon } from '@gravito/ion';
141
182
  *
142
- * const core = await PlanetCore.boot(defineConfig({
143
- * orbits: [OrbitIon]
144
- * }))
183
+ * core.addOrbit(new OrbitIon({
184
+ * version: '1.0.0',
185
+ * rootView: 'app'
186
+ * }));
145
187
  * ```
188
+ *
189
+ * @public
190
+ * @since 3.0.0
146
191
  */
147
192
  declare class OrbitIon implements GravitoOrbit {
193
+ private options;
194
+ constructor(options?: OrbitIonOptions);
148
195
  /**
149
- * Install the Inertia orbit into PlanetCore
196
+ * Install the inertia orbit into PlanetCore
150
197
  */
151
198
  install(core: PlanetCore): void;
152
199
  }
153
200
 
154
- export { type InertiaConfig, InertiaService, OrbitIon, OrbitIon as default };
201
+ export { type InertiaConfig, type InertiaHelper, InertiaService, OrbitIon, type OrbitIonOptions, OrbitIon as default };
package/dist/index.d.ts CHANGED
@@ -122,33 +122,80 @@ declare class InertiaService {
122
122
  * @since 1.0.0
123
123
  */
124
124
 
125
- declare module '@gravito/core' {
126
- interface GravitoVariables {
127
- /** Inertia.js service for SPA rendering */
128
- inertia?: InertiaService;
129
- }
125
+ /**
126
+ * InertiaHelper is a callable function and service suite injected into the Gravito context.
127
+ * It allows you to render Inertia components directly or manage shared data.
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * // Direct call rendering
132
+ * return ctx.get('inertia')('Welcome', { user });
133
+ *
134
+ * // Using shared data
135
+ * ctx.get('inertia').share('appName', 'Gravito App');
136
+ * ```
137
+ * @public
138
+ */
139
+ interface InertiaHelper {
140
+ /**
141
+ * Render an Inertia component.
142
+ * Shortcut for context.get('inertia').render()
143
+ *
144
+ * @param component - The name of the frontend component (e.g., 'Pages/Home')
145
+ * @param props - Data to pass to the component
146
+ * @param rootVars - Variables for the root HTML template (e.g., meta tags)
147
+ */
148
+ (component: string, props?: Record<string, unknown>, rootVars?: Record<string, unknown>): Response;
149
+ /** Share data with all Inertia responses for the remainder of the request */
150
+ share(key: string, value: unknown): void;
151
+ /** Share multiple props at once */
152
+ shareAll(props: Record<string, unknown>): void;
153
+ /** Get all currently shared props */
154
+ getSharedProps(): Record<string, unknown>;
155
+ /** Explicitly render an Inertia component */
156
+ render(component: string, props?: Record<string, unknown>, rootVars?: Record<string, unknown>): Response;
157
+ /** Direct access to the low-level Inertia service instance */
158
+ service: InertiaService;
130
159
  }
131
160
  /**
132
- * OrbitIon - Inertia.js integration orbit
161
+ * Options for configuring OrbitIon.
162
+ * @public
163
+ */
164
+ interface OrbitIonOptions {
165
+ /** Current asset version to detect staleness (X-Inertia-Version) */
166
+ version?: string;
167
+ /** The root HTML template view (default: 'app') */
168
+ rootView?: string;
169
+ }
170
+ /**
171
+ * OrbitIon provides official Inertia.js integration for Gravito.
133
172
  *
134
- * This orbit provides seamless Inertia.js integration, enabling
135
- * SPA-like navigation with server-side routing.
173
+ * It handles Inertia requests, partial reloads, asset versioning, and seamless
174
+ * data sharing between the server and your frontend application (React, Vue, etc.).
175
+ *
176
+ * It injects an `InertiaHelper` into the context, allowing you to render
177
+ * components with a simple function call: `c.get('inertia')('Page', { props })`.
136
178
  *
137
179
  * @example
138
180
  * ```typescript
139
- * import { PlanetCore, defineConfig } from '@gravito/core'
140
- * import { OrbitIon } from '@gravito/ion'
181
+ * import { OrbitIon } from '@gravito/ion';
141
182
  *
142
- * const core = await PlanetCore.boot(defineConfig({
143
- * orbits: [OrbitIon]
144
- * }))
183
+ * core.addOrbit(new OrbitIon({
184
+ * version: '1.0.0',
185
+ * rootView: 'app'
186
+ * }));
145
187
  * ```
188
+ *
189
+ * @public
190
+ * @since 3.0.0
146
191
  */
147
192
  declare class OrbitIon implements GravitoOrbit {
193
+ private options;
194
+ constructor(options?: OrbitIonOptions);
148
195
  /**
149
- * Install the Inertia orbit into PlanetCore
196
+ * Install the inertia orbit into PlanetCore
150
197
  */
151
198
  install(core: PlanetCore): void;
152
199
  }
153
200
 
154
- export { type InertiaConfig, InertiaService, OrbitIon, OrbitIon as default };
201
+ export { type InertiaConfig, type InertiaHelper, InertiaService, OrbitIon, type OrbitIonOptions, OrbitIon as default };
package/dist/index.js CHANGED
@@ -88,6 +88,7 @@ var InertiaService = class {
88
88
  )
89
89
  );
90
90
  }
91
+ // ...
91
92
  /**
92
93
  * Share data with all Inertia responses
93
94
  *
@@ -126,22 +127,35 @@ var InertiaService = class {
126
127
 
127
128
  // src/index.ts
128
129
  var OrbitIon = class {
130
+ constructor(options = {}) {
131
+ this.options = options;
132
+ }
129
133
  /**
130
- * Install the Inertia orbit into PlanetCore
134
+ * Install the inertia orbit into PlanetCore
131
135
  */
132
136
  install(core) {
133
- core.logger.info("\u{1F6F0}\uFE0F Orbit Inertia installed");
134
- const appVersion = core.config.get("APP_VERSION", "1.0.0");
137
+ core.logger.info("\u{1F6F0}\uFE0F Orbit Inertia installed (Callable Interface)");
138
+ const appVersion = this.options.version ?? core.config.get("APP_VERSION", "1.0.0");
139
+ const rootView = this.options.rootView ?? "app";
135
140
  core.adapter.use("*", async (c, next) => {
136
- const gravitoCtx = c;
137
- const inertia = new InertiaService(gravitoCtx, {
141
+ const service = new InertiaService(c, {
138
142
  version: String(appVersion),
139
- rootView: "app"
140
- // Default to src/views/app.html
143
+ rootView
144
+ });
145
+ const inertiaProxy = (component, props = {}, rootVars = {}) => {
146
+ return service.render(component, props, rootVars);
147
+ };
148
+ Object.assign(inertiaProxy, {
149
+ share: service.share.bind(service),
150
+ shareAll: service.shareAll.bind(service),
151
+ getSharedProps: service.getSharedProps.bind(service),
152
+ render: service.render.bind(service),
153
+ // Also allow .render()
154
+ service
155
+ // Access to the raw service instance
141
156
  });
142
- c.set("inertia", inertia);
143
- await next();
144
- return void 0;
157
+ c.set("inertia", inertiaProxy);
158
+ return await next();
145
159
  });
146
160
  }
147
161
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravito/ion",
3
- "version": "2.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Inertia.js adapter for Gravito",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",