kireji 0.13.0 → 0.14.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kireji",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "A web framework for stateful, entropy-perfect, multi-origin web applications. Currently in alpha. Expect breaking changes for version 0. Use with caution!",
5
5
  "files": [
6
6
  "src/",
@@ -0,0 +1 @@
1
+ return `data-onclick="${sanitizeAttr(JSON.stringify([part.host, METHOD_NAME, ...ARGS]))}"`
@@ -73,6 +73,10 @@
73
73
  "METHOD_NAME = 'point'",
74
74
  "...ARGS"
75
75
  ],
76
+ "attr-click": [
77
+ "METHOD_NAME = 'onclick'",
78
+ "...ARGS"
79
+ ],
76
80
  "manifest-resolve-owner-of": [
77
81
  "PROPERTY_KEY"
78
82
  ],
@@ -33,8 +33,10 @@ declare interface IPart<TOwner, TSubpart>
33
33
  readonly "runtimeReference": string
34
34
  /** An optional display name for the part. */
35
35
  readonly "title"?: string
36
- /** Generates the attribute string that sets up an onpointerdown listener that calls `part[METHOD_NAME](event,this,...ARGS)`. */
36
+ /** Generates the attribute string that sets up an onpointerdown listener that calls `part[METHOD_NAME](event,this,...ARGS)`. Typically, use `pointer.handle({ ... })` within that method to react to manage complex events drag-and-drop, clicks, double clicks, etc. @remarks This approach will always use the pointer events (not click, touch or mouse events). Use `clickAttr` instead of `pointAttr` to create a traditional click event handler. */
37
37
  readonly pointAttr(METHOD_NAME: string = "point", ...ARGS: any[])
38
+ /** Generates the attribute string that sets up an onclick listener that calls `part[METHOD_NAME](event,this,...ARGS)`. Using `pointAttr` with `pointer.handle({ ... })` is the preferred method of reacting to clicks but this event can be used for special cases like requesting a pointerlock, where the browser requires a proper click event. */
39
+ readonly clickAttr(METHOD_NAME: string = "onclick", ...ARGS: any[])
38
40
  /** Registers a listener that calls RECEIVER[CALLBACK_NAME](this) after the event of the given type occurs. */
39
41
  readonly attach(EVENT_TYPE: string, RECEIVER: IPartAny, CALLBACK_NAME: string): void
40
42
  /** Unregisters the listener that calls RECEIVER[CALLBACK_NAME](this) after the event of the given type occurs. */
@@ -1,4 +1,8 @@
1
+ await agent.promise
2
+
1
3
  addressBar.define({
2
4
  throttleDuration: { value: agent.isSafari ? 350 : 75 },
3
5
  throttleStartTime: { value: _.now, writable: true }
4
- })
6
+ })
7
+
8
+ debug(agent.isSafari, addressBar.throttleDuration)
@@ -61,10 +61,7 @@ logScope(0, "Finalizing Hydration", log => {
61
61
  })
62
62
 
63
63
  // Prevent normal click events to ensure the pointerdown event always takes precedence.
64
- document.addEventListener("click", pointerEvent => {
65
- pointerEvent.preventDefault()
66
- pointerEvent.stopPropagation()
67
- }, { capture: true })
64
+ document.addEventListener("click", client.blockClicks, { capture: true })
68
65
 
69
66
  log("Setting Initial State")
70
67
  // Propagate the initial state (matched to the snapshot exactly).
@@ -0,0 +1,17 @@
1
+ const clickHandler = POINTER_EVENT.target.getAttribute("data-onclick")
2
+
3
+ if (clickHandler) {
4
+
5
+ const [partHost, methodName, ...args] = JSON.parse(clickHandler)
6
+ const part = partsByHost[partHost]
7
+
8
+ if (part[methodName] && typeof part[methodName] === "function")
9
+ part[methodName](...args)
10
+ else
11
+ throw new ReferenceError(`ClickAttr Error: could not find a method called "${methodName}" on part ${partHost}.`)
12
+
13
+ return
14
+ }
15
+
16
+ POINTER_EVENT.preventDefault()
17
+ POINTER_EVENT.stopPropagation()
@@ -3,6 +3,9 @@
3
3
  "methods": {
4
4
  "loop-request": [
5
5
  "REQUEST_TIME"
6
+ ],
7
+ "clicks-block": [
8
+ "POINTER_EVENT"
6
9
  ]
7
10
  }
8
11
  }
@@ -4,6 +4,8 @@ declare interface IClient
4
4
  // Serialized Properties.
5
5
  /** Requests an animation frame that distributes the loop function throughout the ecosystem and calls itself again. @remarks Can only be run on the client. */
6
6
  readonly requestLoop(REQUEST_TIME: DOMHighResTimeStamp): void
7
+ /** The click event handler that is used globally on the client to prevent the click event from taking precedence over pointer events. */
8
+ readonly blockClicks(POINTER_EVENT: PointerEvent): void
7
9
 
8
10
  // Runtime Properties.
9
11
  /** Whether or not the server-rendered page has been fully "taken over" by the client-side framework. @remarks Can only become true in the client environment. */
@@ -62,7 +62,7 @@ const
62
62
 
63
63
  // color.device.light = !prefersDarkMode
64
64
  _.setRoute(`https://${host}${pathname}`)
65
- status = +(host in _.menuApplications ? 200 : _.applications[host].status ?? 503)
65
+ status = +(host in _.menuApplications ? 200 : _.applications[host].status ?? 200)
66
66
  const customHeaders = _.applications[host].customHeaders ?? {}
67
67
  head = { ...indexHeader, ...customHeaders }
68
68
  body = _['part.html']