@hyperspan/framework 0.5.2 → 0.5.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.
package/dist/server.js CHANGED
@@ -279,7 +279,7 @@ var tryDecode = (str, decoder) => {
279
279
  var tryDecodeURI = (str) => tryDecode(str, decodeURI);
280
280
  var getPath = (request) => {
281
281
  const url = request.url;
282
- const start = url.indexOf("/", url.charCodeAt(9) === 58 ? 13 : 8);
282
+ const start = url.indexOf("/", url.indexOf(":") + 4);
283
283
  let i = start;
284
284
  for (;i < url.length; i++) {
285
285
  const charCode = url.charCodeAt(i);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperspan/framework",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Hyperspan Web Framework",
5
5
  "main": "dist/server.ts",
6
6
  "types": "src/server.ts",
package/src/actions.ts CHANGED
@@ -30,22 +30,25 @@ export interface HSAction<T extends z.ZodTypeAny> {
30
30
  form(
31
31
  renderForm: (
32
32
  c: THSContext,
33
- { data, error }: { data?: z.infer<T>; error?: z.ZodError | Error }
33
+ { data, error }: { data?: Partial<z.infer<T>>; error?: z.ZodError | Error }
34
34
  ) => HSHtml | void | null | Promise<HSHtml | void | null>
35
35
  ): HSAction<T>;
36
36
  post(
37
37
  handler: (
38
38
  c: THSContext,
39
- { data }: { data?: z.infer<T> }
39
+ { data }: { data?: Partial<z.infer<T>> }
40
40
  ) => TActionResponse | Promise<TActionResponse>
41
41
  ): HSAction<T>;
42
42
  error(
43
43
  handler: (
44
44
  c: THSContext,
45
- { data, error }: { data?: z.infer<T>; error?: z.ZodError | Error }
45
+ { data, error }: { data?: Partial<z.infer<T>>; error?: z.ZodError | Error }
46
46
  ) => TActionResponse
47
47
  ): HSAction<T>;
48
- render(c: THSContext, props?: { data?: z.infer<T>; error?: z.ZodError | Error }): TActionResponse;
48
+ render(
49
+ c: THSContext,
50
+ props?: { data?: Partial<z.infer<T>>; error?: z.ZodError | Error }
51
+ ): TActionResponse;
49
52
  run(c: THSContext): TActionResponse | Promise<TActionResponse>;
50
53
  middleware: (
51
54
  middleware: Array<
@@ -108,7 +111,7 @@ export function unstable__createAction<T extends z.ZodTypeAny>(
108
111
  /**
109
112
  * Get form renderer method
110
113
  */
111
- render(c: THSContext, formState?: { data?: z.infer<T>; error?: z.ZodError | Error }) {
114
+ render(c: THSContext, formState?: { data?: Partial<z.infer<T>>; error?: z.ZodError | Error }) {
112
115
  const form = _form ? _form(c, formState || {}) : null;
113
116
  return form ? html`<hs-action url="${this._route}">${form}</hs-action>` : null;
114
117
  },
@@ -149,9 +152,9 @@ export function unstable__createAction<T extends z.ZodTypeAny>(
149
152
  }
150
153
 
151
154
  const formData = await c.req.formData();
152
- const jsonData = unstable__formDataToJSON(formData);
155
+ const jsonData = unstable__formDataToJSON(formData) as Partial<z.infer<T>>;
153
156
  const schemaData = schema ? schema.safeParse(jsonData) : null;
154
- const data = schemaData?.success ? (schemaData.data as z.infer<T>) : jsonData;
157
+ const data = schemaData?.success ? (schemaData.data as Partial<z.infer<T>>) : jsonData;
155
158
  let error: z.ZodError | Error | null = null;
156
159
 
157
160
  try {
@@ -110,8 +110,13 @@ window.customElements.define('hs-action', HSAction);
110
110
  const actionFormObserver = new MutationObserver((list) => {
111
111
  list.forEach((mutation) => {
112
112
  mutation.addedNodes.forEach((node) => {
113
- if (node instanceof HTMLFormElement) {
114
- bindHSActionForm(node.closest('hs-action') as HSAction, node);
113
+ if (node && ('closest' in node || node instanceof HTMLFormElement)) {
114
+ bindHSActionForm(
115
+ (node as HTMLElement).closest('hs-action') as HSAction,
116
+ node instanceof HTMLFormElement
117
+ ? node
118
+ : ((node as HTMLElement | HTMLFormElement).querySelector('form') as HTMLFormElement)
119
+ );
115
120
  }
116
121
  });
117
122
  });
@@ -127,6 +132,7 @@ function bindHSActionForm(hsActionElement: HSAction, form: HTMLFormElement) {
127
132
 
128
133
  form.setAttribute('action', hsActionElement.getAttribute('url') || '');
129
134
  const submitHandler = (e: Event) => {
135
+ e.preventDefault();
130
136
  formSubmitToRoute(e, form as HTMLFormElement, {
131
137
  afterResponse: () => bindHSActionForm(hsActionElement, form),
132
138
  });
@@ -140,10 +146,8 @@ function bindHSActionForm(hsActionElement: HSAction, form: HTMLFormElement) {
140
146
  */
141
147
  type TFormSubmitOptons = { afterResponse: () => any };
142
148
  function formSubmitToRoute(e: Event, form: HTMLFormElement, opts: TFormSubmitOptons) {
143
- e.preventDefault();
144
-
145
- const formUrl = form.getAttribute('action') || '';
146
149
  const formData = new FormData(form);
150
+ const formUrl = form.getAttribute('action') || '';
147
151
  const method = form.getAttribute('method')?.toUpperCase() || 'POST';
148
152
  const headers = {
149
153
  Accept: 'text/html',
package/src/plugins.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { assetHash, CLIENTJS_PUBLIC_PATH, clientImportMap, clientJSFiles } from './assets';
1
+ import { assetHash, CLIENTJS_PUBLIC_PATH, clientImportMap } from './assets';
2
2
  import { IS_PROD, type THSServerConfig } from './server';
3
3
 
4
4
  const CLIENT_JS_CACHE = new Map<string, string>();