@uniweb/runtime 0.7.2 → 0.7.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.
Files changed (30) hide show
  1. package/dist/app/_importmap/@uniweb-core.js +2 -0
  2. package/dist/app/_importmap/@uniweb-core.js.map +1 -0
  3. package/dist/app/_importmap/react-dom.js +2 -0
  4. package/dist/app/_importmap/react-dom.js.map +1 -0
  5. package/dist/app/_importmap/react-jsx-dev-runtime.js +2 -0
  6. package/dist/app/_importmap/react-jsx-dev-runtime.js.map +1 -0
  7. package/dist/app/_importmap/react-jsx-runtime.js +2 -0
  8. package/dist/app/_importmap/react-jsx-runtime.js.map +1 -0
  9. package/dist/app/_importmap/react.js +2 -0
  10. package/dist/app/_importmap/react.js.map +1 -0
  11. package/dist/app/assets/_commonjsHelpers-CqkleIqs.js +2 -0
  12. package/dist/app/assets/_commonjsHelpers-CqkleIqs.js.map +1 -0
  13. package/dist/app/assets/_importmap_react-CrAkajDz.js +2 -0
  14. package/dist/app/assets/_importmap_react-CrAkajDz.js.map +1 -0
  15. package/dist/app/assets/index-C6EFXW_H.js +133 -0
  16. package/dist/app/assets/index-C6EFXW_H.js.map +1 -0
  17. package/dist/app/assets/index-CL1goElX.js +16 -0
  18. package/dist/app/assets/index-CL1goElX.js.map +1 -0
  19. package/dist/app/assets/index-CxUeIbEw.js +2 -0
  20. package/dist/app/assets/index-CxUeIbEw.js.map +1 -0
  21. package/dist/app/assets/index-VvOM7xKK.js +2 -0
  22. package/dist/app/assets/index-VvOM7xKK.js.map +1 -0
  23. package/dist/app/assets/jsx-runtime-0PlsXv6K.js +2 -0
  24. package/dist/app/assets/jsx-runtime-0PlsXv6K.js.map +1 -0
  25. package/dist/app/index.html +31 -0
  26. package/dist/app/manifest.json +19 -0
  27. package/dist/ssr.js +33 -1
  28. package/dist/ssr.js.map +1 -1
  29. package/package.json +4 -4
  30. package/src/prepare-props.js +83 -11
@@ -213,13 +213,45 @@ function mergeEntityData(block, entityData) {
213
213
  }
214
214
  }
215
215
 
216
+ /**
217
+ * Run the foundation-level data handler on a block, if one is
218
+ * registered. Runs after entity data merge and before the content
219
+ * handler — the handler sees the fully assembled data and can filter,
220
+ * reshape, or augment it before Loom (or any content transform) runs.
221
+ *
222
+ * The handler receives `(data, block)` where data is
223
+ * `block.parsedContent.data`. It returns a new data object, or
224
+ * null/undefined for no change. The returned data replaces
225
+ * `block.parsedContent.data` for all downstream processing — both
226
+ * the content handler and the component see the transformed data.
227
+ *
228
+ * Skipped when the block is still waiting on async data
229
+ * (`block.dataLoading`), or when no handler is registered.
230
+ * Errors are logged and the original data is preserved.
231
+ */
232
+ function runDataHandler(block) {
233
+ if (block.dataLoading) return
234
+ const handler = globalThis.uniweb?.foundationConfig?.handlers?.data
235
+ if (typeof handler !== 'function') return
236
+
237
+ try {
238
+ const result = handler(block.parsedContent.data, block)
239
+ if (result != null && result !== block.parsedContent.data) {
240
+ block.parsedContent.data = result
241
+ }
242
+ } catch (err) {
243
+ console.error('Foundation data handler failed:', err)
244
+ }
245
+ }
246
+
216
247
  /**
217
248
  * Run the foundation-level content handler on a block, if one is
218
- * registered. Runs at prop-preparation time — after any entity data
219
- * has been merged onto `block.parsedContent.data` — so the handler
220
- * sees the fully assembled data. Replaces `block.parsedContent` in
221
- * place with the re-parsed, instantiated form. The handler receives
222
- * `(data, block)` and reads raw ProseMirror from `block.rawContent`.
249
+ * registered. Runs at prop-preparation time — after the data handler
250
+ * has had a chance to filter/reshape the data — so the handler sees
251
+ * the fully assembled (and possibly filtered) data. Replaces
252
+ * `block.parsedContent` in place with the re-parsed, instantiated
253
+ * form. The handler receives `(data, block)` and reads raw
254
+ * ProseMirror from `block.rawContent`.
223
255
  *
224
256
  * Skipped when the block is still waiting on async data
225
257
  * (`block.dataLoading`), when no handler is registered, when the
@@ -245,6 +277,32 @@ function runContentHandler(block) {
245
277
  }
246
278
  }
247
279
 
280
+ /**
281
+ * Run the foundation-level props handler on the final { content, params }
282
+ * before they reach the component. Runs after content parsing, param
283
+ * defaults, content guarantees, and schema application — the handler
284
+ * sees the exact shape the component would receive and can modify it.
285
+ *
286
+ * The handler receives `(content, params, block)` and returns a new
287
+ * `{ content, params }` object, or null/undefined for no change.
288
+ *
289
+ * Use cases: post-parse content reshaping, computed fields derived
290
+ * from both content and params, param-driven content reorganization.
291
+ * Errors are logged and the original props are preserved.
292
+ */
293
+ function runPropsHandler(content, params, block) {
294
+ const handler = globalThis.uniweb?.foundationConfig?.handlers?.props
295
+ if (typeof handler !== 'function') return null
296
+
297
+ try {
298
+ const result = handler(content, params, block)
299
+ if (result && typeof result === 'object') return result
300
+ } catch (err) {
301
+ console.error('Foundation props handler failed:', err)
302
+ }
303
+ return null
304
+ }
305
+
248
306
  /**
249
307
  * Prepare props for a component with runtime guarantees.
250
308
  *
@@ -254,14 +312,18 @@ function runContentHandler(block) {
254
312
  *
255
313
  * 1. Merge entity data (resolved by EntityStore) onto
256
314
  * `block.parsedContent.data`.
257
- * 2. Run the foundation content handler (if registered) on the
315
+ * 2. Run the foundation data handler (if registered) to filter or
316
+ * reshape the assembled data.
317
+ * 3. Run the foundation content handler (if registered) on the
258
318
  * block. This may replace `block.parsedContent` with a re-parsed,
259
319
  * instantiated version.
260
- * 3. Build the guaranteed content structure.
261
- * 4. Apply schemas from meta.
262
- * 5. Apply param defaults.
320
+ * 4. Apply param defaults from meta.
321
+ * 5. Build the guaranteed content structure.
322
+ * 6. Apply schemas to content.data.
323
+ * 7. Run the foundation props handler (if registered) for
324
+ * post-processing of the final { content, params }.
263
325
  *
264
- * Steps 1 and 2 mutate the block (vanilla JS layer). Steps 35 are
326
+ * Steps 1–3 mutate the block (vanilla JS layer). Steps 47 are
265
327
  * pure derivations of the block's now-assembled state.
266
328
  *
267
329
  * @param {Object} block - The block instance
@@ -271,6 +333,7 @@ function runContentHandler(block) {
271
333
  */
272
334
  export function prepareProps(block, meta, entityData = null) {
273
335
  mergeEntityData(block, entityData)
336
+ runDataHandler(block)
274
337
  runContentHandler(block)
275
338
 
276
339
  // Apply param defaults
@@ -278,7 +341,7 @@ export function prepareProps(block, meta, entityData = null) {
278
341
  const params = applyDefaults(block.properties, defaults)
279
342
 
280
343
  // Guarantee content structure
281
- const content = guaranteeContentStructure(block.parsedContent)
344
+ let content = guaranteeContentStructure(block.parsedContent)
282
345
 
283
346
  // Apply schemas to content.data
284
347
  const schemas = meta?.schemas || null
@@ -286,6 +349,15 @@ export function prepareProps(block, meta, entityData = null) {
286
349
  content.data = applySchemas(content.data, schemas)
287
350
  }
288
351
 
352
+ // Post-process hook
353
+ const adjusted = runPropsHandler(content, params, block)
354
+ if (adjusted) {
355
+ return {
356
+ content: adjusted.content || content,
357
+ params: adjusted.params || params,
358
+ }
359
+ }
360
+
289
361
  return { content, params }
290
362
  }
291
363