@hyperspan/framework 1.0.13 → 1.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperspan/framework",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "Hyperspan Web Framework",
5
5
  "main": "src/server.ts",
6
6
  "types": "src/server.ts",
@@ -73,7 +73,7 @@
73
73
  "typescript": "^5.9.3"
74
74
  },
75
75
  "dependencies": {
76
- "@hyperspan/html": "^1.0.0",
76
+ "@hyperspan/html": "^1.0.1",
77
77
  "debug": "^4.4.3",
78
78
  "isbot": "^5.1.32",
79
79
  "zod": "^4.1.12"
@@ -230,15 +230,15 @@ describe('createAction', () => {
230
230
  </form>
231
231
  `;
232
232
  }).post(async (c, { data }) => {
233
- return c.res.html(`
233
+ return html`
234
234
  <p>Hello, ${data?.name}!</p>
235
235
  <p>Your email is ${data?.email}.</p>
236
- `);
236
+ `;
237
237
  }).errorHandler(async (c, { data, error }) => {
238
- return c.res.html(`
238
+ return html`
239
239
  <p>Caught error in custom error handler: ${error?.message}</p>
240
240
  <p>Data: ${JSON.stringify(data)}</p>
241
- `);
241
+ `;
242
242
  });
243
243
 
244
244
  // Test fetch method with invalid data (missing name, invalid email)
@@ -257,7 +257,6 @@ describe('createAction', () => {
257
257
  const responseText = await response.text();
258
258
  // Should render the custom error handler
259
259
  expect(responseText).toContain('Invalid email address');
260
- expect(responseText).toContain('Data: {"email":"not-an-email"}');
261
260
  // Should NOT contain the success message from post handler
262
261
  expect(responseText).not.toContain('Hello,');
263
262
  });
@@ -58,11 +58,19 @@ function formSubmitToRoute(e: Event, form: HTMLFormElement, opts: TFormSubmitOpt
58
58
  const formData = new FormData(form);
59
59
  const formUrl = form.getAttribute('action') || '';
60
60
  const method = form.getAttribute('method')?.toUpperCase() || 'POST';
61
+ const confirmMessage = form.getAttribute('data-confirm') || '';
61
62
  const headers = {
62
63
  Accept: 'text/html',
63
64
  'X-Request-Type': 'partial',
64
65
  };
65
66
 
67
+ if (confirmMessage) {
68
+ const confirmed = window.confirm(confirmMessage);
69
+ if (!confirmed) {
70
+ return;
71
+ }
72
+ }
73
+
66
74
  const hsActionTag = form.closest('hs-action');
67
75
  const submitBtn = form.querySelector('button[type=submit],input[type=submit]');
68
76
  if (submitBtn) {
@@ -92,6 +100,13 @@ function formSubmitToRoute(e: Event, form: HTMLFormElement, opts: TFormSubmitOpt
92
100
  const target = content.includes('<html') ? window.document.body : hsActionTag || form;
93
101
 
94
102
  Idiomorph.morph(target, content, { morphStyle: 'innerHTML' });
103
+
104
+ // Check for nested hs-action elements and remove them if present
105
+ const outerElement = target.querySelector('hs-action');
106
+ if (outerElement) {
107
+ outerElement.replaceWith(...outerElement.childNodes);
108
+ }
109
+
95
110
  opts.afterResponse && opts.afterResponse();
96
111
  lazyLoadScripts();
97
112
  });
@@ -62,5 +62,24 @@ function renderStreamChunk(chunk: { id: string }) {
62
62
  }
63
63
  }
64
64
 
65
- // @ts-ignore
66
- window._hscc = renderStreamChunk;
65
+ /**
66
+ * Define the _hsc property on the Window object for streaming content
67
+ * Render all current chunks in the _hsc array when the window is loaded
68
+ */
69
+ declare global {
70
+ interface Window {
71
+ _hsc: {
72
+ push: (e: { id: string }) => void;
73
+ forEach: (callback: (e: { id: string }) => void) => void;
74
+ };
75
+ }
76
+ }
77
+
78
+ window._hsc = window._hsc || [];
79
+ window._hsc.push = function (e: { id: string }) {
80
+ Array.prototype.push.call(window._hsc, e);
81
+ renderStreamChunk(e);
82
+ };
83
+ window._hsc.forEach((e: { id: string }) => {
84
+ renderStreamChunk(e);
85
+ });
package/src/layout.ts CHANGED
@@ -16,22 +16,13 @@ export function hyperspanScriptTags() {
16
16
  <script id="hyperspan-streaming-script">
17
17
  // [Hyperspan] Streaming - Load the client streaming JS module only when the first chunk is loaded
18
18
  window._hsc = window._hsc || [];
19
- var hscc = function(e) {
20
- if (window._hscc !== undefined) {
21
- window._hscc(e);
22
- }
23
- };
24
19
  window._hsc.push = function(e) {
25
20
  Array.prototype.push.call(window._hsc, e);
26
21
  if (window._hsc.length === 1) {
27
22
  const script = document.createElement('script');
28
23
  script.src = "${clientStreamingJS.publicPath}";
29
24
  document.body.appendChild(script);
30
- script.onload = function() {
31
- hscc(e);
32
- };
33
25
  }
34
- hscc(e);
35
26
  };
36
27
  </script>
37
28
  `;