phoenix_live_view 1.2.0-rc.3 → 1.2.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Phoenix LiveView
2
2
 
3
- [![Actions Status](https://github.com/phoenixframework/phoenix_live_view/workflows/CI/badge.svg)](https://github.com/phoenixframework/phoenix_live_view/actions?query=workflow%3ACI) [![Hex.pm](https://img.shields.io/hexpm/v/phoenix_live_view.svg)](https://hex.pm/packages/phoenix_live_view) [![Documentation](https://img.shields.io/badge/documentation-gray)](https://hexdocs.pm/phoenix_live_view)
3
+ [![Actions Status](https://github.com/phoenixframework/phoenix_live_view/workflows/CI/badge.svg)](https://github.com/phoenixframework/phoenix_live_view/actions?query=workflow%3ACI) [![Hex.pm](https://img.shields.io/hexpm/v/phoenix_live_view.svg)](https://hex.pm/packages/phoenix_live_view) [![Documentation](https://img.shields.io/badge/documentation-gray)](https://phoenix-live-view.hexdocs.pm)
4
4
 
5
5
  Phoenix LiveView enables rich, real-time user experiences with server-rendered HTML.
6
6
 
@@ -34,7 +34,7 @@ model while keeping your code closer to your data (and ultimately your source of
34
34
 
35
35
  * **Diffs over the wire:** Instead of sending "HTML over the wire", LiveView knows exactly which parts of your templates change, sending minimal diffs over the wire after the initial render, reducing latency and bandwidth usage. The client leverages this information and optimizes the browser with 5-10x faster updates, compared to solutions that replace whole HTML fragments.
36
36
 
37
- * **Live form validation:** LiveView supports real-time form validation out of the box. Create rich user interfaces with features like uploads, nested inputs, and [specialized recovery](https://hexdocs.pm/phoenix_live_view/form-bindings.html#recovery-following-crashes-or-disconnects).
37
+ * **Live form validation:** LiveView supports real-time form validation out of the box. Create rich user interfaces with features like uploads, nested inputs, and [specialized recovery](https://phoenix-live-view.hexdocs.pm/form-bindings.html#recovery-following-crashes-or-disconnects).
38
38
 
39
39
  * **File uploads:** Real-time file uploads with progress indicators and image previews. Process your uploads on the fly or submit them to your desired cloud service.
40
40
 
@@ -52,9 +52,9 @@ model while keeping your code closer to your data (and ultimately your source of
52
52
 
53
53
  ## Learning
54
54
 
55
- Check our [comprehensive docs](https://hexdocs.pm/phoenix_live_view) to get started.
55
+ Check our [comprehensive docs](https://phoenix-live-view.hexdocs.pm) to get started.
56
56
 
57
- The Phoenix framework documentation also keeps a list of [community resources](https://hexdocs.pm/phoenix/community.html), including books, videos, and other materials, and some include LiveView too.
57
+ The Phoenix framework documentation also keeps a list of [community resources](https://phoenix.hexdocs.pm/community.html), including books, videos, and other materials, and some include LiveView too.
58
58
 
59
59
  Also follow these announcements from the Phoenix team on LiveView for more examples and rationale:
60
60
 
@@ -103,7 +103,7 @@ which provides quick times for "First Meaningful Paint", in addition to
103
103
  helping search and indexing engines.
104
104
 
105
105
  Then LiveView uses a persistent connection between client and server.
106
- This allows LiveView applications to react faster to user events as
106
+ This allows LiveView applications to react faster to user events, as
107
107
  there is less work to be done and less data to be sent compared to
108
108
  stateless requests that have to authenticate, decode, load, and encode
109
109
  data on every request.
@@ -1,3 +1,3 @@
1
1
  ## LiveView JavaScript Client
2
2
 
3
- This is the documentation for the LiveView JavaScript client. It is a more low-level API documentation for advanced users. For a higher-level overview, [see the page on JavaScript interoperability](https://hexdocs.pm/phoenix_live_view/js-interop.html) instead.
3
+ This is the documentation for the LiveView JavaScript client. It is a more low-level API documentation for advanced users. For a higher-level overview, [see the page on JavaScript interoperability](https://phoenix-live-view.hexdocs.pm/js-interop.html) instead.
@@ -1,9 +1,9 @@
1
1
  /*
2
2
  * This is the documentation for the LiveView JavaScript client.
3
3
  * It is a more low-level API documentation for advanced users.
4
- * For a higher-level overview, [see the page on JavaScript interoperability](https://hexdocs.pm/phoenix_live_view/js-interop.html) instead.
4
+ * For a higher-level overview, [see the page on JavaScript interoperability](https://phoenix-live-view.hexdocs.pm/js-interop.html) instead.
5
5
  *
6
- * The main documentation can be found at `https://hexdocs.pm/phoenix_live_view`.
6
+ * The main documentation can be found at `https://phoenix-live-view.hexdocs.pm`.
7
7
  *
8
8
  * @packageDocumentation
9
9
  */
@@ -92,7 +92,7 @@ export interface LiveSocketOptions {
92
92
  /**
93
93
  * Callbacks for LiveView hooks.
94
94
  *
95
- * See [Client hooks via `phx-hook`](https://hexdocs.pm/phoenix_live_view/js-interop.html#client-hooks-via-phx-hook) for more information.
95
+ * See [Client hooks via `phx-hook`](https://phoenix-live-view.hexdocs.pm/js-interop.html#client-hooks-via-phx-hook) for more information.
96
96
  */
97
97
  hooks?: HooksOptions;
98
98
  /** Callbacks for LiveView uploaders. */
@@ -425,7 +425,7 @@ export default class LiveSocket {
425
425
  * Enables debugging.
426
426
  *
427
427
  * When debugging is enabled, the LiveView client will log debug information to the console.
428
- * See [Debugging client events](https://hexdocs.pm/phoenix_live_view/js-interop.html#debugging-client-events) for more information.
428
+ * See [Debugging client events](https://phoenix-live-view.hexdocs.pm/js-interop.html#debugging-client-events) for more information.
429
429
  */
430
430
  enableDebug(): void {
431
431
  this.sessionStorage.setItem(PHX_LV_DEBUG, "true");
@@ -458,7 +458,7 @@ export default class LiveSocket {
458
458
  * Enables latency simulation.
459
459
  *
460
460
  * When latency simulation is enabled, the LiveView client will add a delay to requests and responses from the server.
461
- * See [Simulating Latency](https://hexdocs.pm/phoenix_live_view/js-interop.html#simulating-latency) for more information.
461
+ * See [Simulating Latency](https://phoenix-live-view.hexdocs.pm/js-interop.html#simulating-latency) for more information.
462
462
  */
463
463
  enableLatencySim(upperBoundMs: number): void {
464
464
  this.enableDebug();
@@ -547,7 +547,7 @@ export default class LiveSocket {
547
547
  /**
548
548
  * Executes an encoded JS command, targeting the given element.
549
549
  *
550
- * See [`Phoenix.LiveView.JS`](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.JS.html) for more information.
550
+ * See [`Phoenix.LiveView.JS`](https://phoenix-live-view.hexdocs.pm/Phoenix.LiveView.JS.html) for more information.
551
551
  */
552
552
  execJS(
553
553
  el: Element,
@@ -562,7 +562,7 @@ export default class LiveSocket {
562
562
  * Returns an object with methods to manipulate the DOM and execute JavaScript.
563
563
  * The applied changes integrate with server DOM patching.
564
564
  *
565
- * See [JavaScript interoperability](https://hexdocs.pm/phoenix_live_view/js-interop.html) for more information.
565
+ * See [JavaScript interoperability](https://phoenix-live-view.hexdocs.pm/js-interop.html) for more information.
566
566
  */
567
567
  js(): LiveSocketJSCommands {
568
568
  return jsCommands(this, "js");
@@ -1152,6 +1152,10 @@ export default class View {
1152
1152
  }
1153
1153
 
1154
1154
  onJoinError(resp) {
1155
+ if (resp.events) {
1156
+ this.liveSocket.dispatchEvents(resp.events);
1157
+ }
1158
+
1155
1159
  if (resp.reason === "reload") {
1156
1160
  this.log("error", () => [
1157
1161
  `failed mount with ${resp.status}. Falling back to page reload`,
@@ -84,10 +84,12 @@ export interface HookInterface<E extends HTMLElement = HTMLElement> {
84
84
  * Use the {@link pushEvent | promise-returning version} to handle errors.
85
85
  *
86
86
  * @param event - The event name.
87
- * @param payload - The payload to send to the server. Defaults to an empty object.
87
+ * @param payload - The payload to send to the server. Must be a serializable
88
+ * value (typically JSON-serializable, depends on the Socket configuration).
89
+ * Defaults to an empty object.
88
90
  * @param onReply - A callback to handle the server's reply.
89
91
  */
90
- pushEvent(event: string, payload: any, onReply: OnReply): void;
92
+ pushEvent(event: string, payload: unknown, onReply: OnReply): void;
91
93
  /**
92
94
  * Pushes an event to the server and returns a Promise that resolves with the server's reply.
93
95
  *
@@ -95,10 +97,12 @@ export interface HookInterface<E extends HTMLElement = HTMLElement> {
95
97
  * such as a disconnected state, timeout, or the server rejecting the event.
96
98
  *
97
99
  * @param event - The event name.
98
- * @param [payload] - The payload to send to the server. Defaults to an empty object.
100
+ * @param [payload] - The payload to send to the server. Must be a serializable
101
+ * value (typically JSON-serializable, depends on the Socket configuration).
102
+ * Defaults to an empty object.
99
103
  * @returns A promise that fulfills or rejects with the server's reply.
100
104
  */
101
- pushEvent(event: string, payload?: any): Promise<any>;
105
+ pushEvent(event: string, payload?: unknown): Promise<any>;
102
106
 
103
107
  /**
104
108
  * Pushes a targeted event to the server and invokes a callback with the server's reply.
@@ -115,13 +119,15 @@ export interface HookInterface<E extends HTMLElement = HTMLElement> {
115
119
  *
116
120
  * @param selectorOrTarget - The selector, element, or CID to target.
117
121
  * @param event - The event name.
118
- * @param payload - The payload to send to the server. Defaults to an empty object.
122
+ * @param payload - The payload to send to the server. Must be a serializable
123
+ * value (typically JSON-serializable, depends on the Socket configuration).
124
+ * Defaults to an empty object.
119
125
  * @param onReply - A callback to handle the server's reply.
120
126
  */
121
127
  pushEventTo(
122
128
  selectorOrTarget: PhxTarget,
123
129
  event: string,
124
- payload: object,
130
+ payload: unknown,
125
131
  onReply: OnReply,
126
132
  ): void;
127
133
  /**
@@ -142,13 +148,15 @@ export interface HookInterface<E extends HTMLElement = HTMLElement> {
142
148
  *
143
149
  * @param selectorOrTarget - The selector, element, or CID to target.
144
150
  * @param event - The event name.
145
- * @param [payload] - The payload to send to the server. Defaults to an empty object.
151
+ * @param [payload] - The payload to send to the server. Must be a serializable
152
+ * value (typically JSON-serializable, depends on the Socket configuration).
153
+ * Defaults to an empty object.
146
154
  * @returns A promise that resolves when the event has been handled by all targets.
147
155
  */
148
156
  pushEventTo(
149
157
  selectorOrTarget: PhxTarget,
150
158
  event: string,
151
- payload?: object,
159
+ payload?: unknown,
152
160
  ): Promise<PromiseSettledResult<{ reply: any; ref: number }>[]>;
153
161
 
154
162
  /**
@@ -445,11 +453,11 @@ export class ViewHook<E extends HTMLElement = HTMLElement>
445
453
  };
446
454
  }
447
455
 
448
- pushEvent(event: string, payload: any, onReply: OnReply): void;
449
- pushEvent(event: string, payload?: any): Promise<any>;
456
+ pushEvent(event: string, payload: unknown, onReply: OnReply): void;
457
+ pushEvent(event: string, payload?: unknown): Promise<any>;
450
458
  pushEvent(
451
459
  event: string,
452
- payload?: any,
460
+ payload?: unknown,
453
461
  onReply?: OnReply,
454
462
  ): Promise<any> | void {
455
463
  const promise = this.__view().pushHookEvent(
@@ -471,18 +479,18 @@ export class ViewHook<E extends HTMLElement = HTMLElement>
471
479
  pushEventTo(
472
480
  selectorOrTarget: PhxTarget,
473
481
  event: string,
474
- payload: object,
482
+ payload: unknown,
475
483
  onReply: OnReply,
476
484
  ): void;
477
485
  pushEventTo(
478
486
  selectorOrTarget: PhxTarget,
479
487
  event: string,
480
- payload?: object,
488
+ payload?: unknown,
481
489
  ): Promise<PromiseSettledResult<{ reply: any; ref: number }>[]>;
482
490
  pushEventTo(
483
491
  selectorOrTarget: PhxTarget,
484
492
  event: string,
485
- payload?: object,
493
+ payload?: unknown,
486
494
  onReply?: OnReply,
487
495
  ): Promise<PromiseSettledResult<{ reply: any; ref: number }>[]> | void {
488
496
  if (onReply === undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phoenix_live_view",
3
- "version": "1.2.0-rc.3",
3
+ "version": "1.2.0",
4
4
  "description": "The Phoenix LiveView JavaScript client.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -5021,6 +5021,9 @@ var View = class _View {
5021
5021
  });
5022
5022
  }
5023
5023
  onJoinError(resp) {
5024
+ if (resp.events) {
5025
+ this.liveSocket.dispatchEvents(resp.events);
5026
+ }
5024
5027
  if (resp.reason === "reload") {
5025
5028
  this.log("error", () => [
5026
5029
  `failed mount with ${resp.status}. Falling back to page reload`,
@@ -6086,7 +6089,7 @@ var LiveSocket = class {
6086
6089
  * Returns the version of the LiveView client.
6087
6090
  */
6088
6091
  version() {
6089
- return "1.2.0-rc.3";
6092
+ return "1.2.0";
6090
6093
  }
6091
6094
  /**
6092
6095
  * Returns true if profiling is enabled. See {@link enableProfiling} and {@link disableProfiling}.
@@ -6110,7 +6113,7 @@ var LiveSocket = class {
6110
6113
  * Enables debugging.
6111
6114
  *
6112
6115
  * When debugging is enabled, the LiveView client will log debug information to the console.
6113
- * See [Debugging client events](https://hexdocs.pm/phoenix_live_view/js-interop.html#debugging-client-events) for more information.
6116
+ * See [Debugging client events](https://phoenix-live-view.hexdocs.pm/js-interop.html#debugging-client-events) for more information.
6114
6117
  */
6115
6118
  enableDebug() {
6116
6119
  this.sessionStorage.setItem(PHX_LV_DEBUG, "true");
@@ -6139,7 +6142,7 @@ var LiveSocket = class {
6139
6142
  * Enables latency simulation.
6140
6143
  *
6141
6144
  * When latency simulation is enabled, the LiveView client will add a delay to requests and responses from the server.
6142
- * See [Simulating Latency](https://hexdocs.pm/phoenix_live_view/js-interop.html#simulating-latency) for more information.
6145
+ * See [Simulating Latency](https://phoenix-live-view.hexdocs.pm/js-interop.html#simulating-latency) for more information.
6143
6146
  */
6144
6147
  enableLatencySim(upperBoundMs) {
6145
6148
  this.enableDebug();
@@ -6214,7 +6217,7 @@ var LiveSocket = class {
6214
6217
  /**
6215
6218
  * Executes an encoded JS command, targeting the given element.
6216
6219
  *
6217
- * See [`Phoenix.LiveView.JS`](https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.JS.html) for more information.
6220
+ * See [`Phoenix.LiveView.JS`](https://phoenix-live-view.hexdocs.pm/Phoenix.LiveView.JS.html) for more information.
6218
6221
  */
6219
6222
  execJS(el, encodedJS, eventType = null) {
6220
6223
  const e = new CustomEvent("phx:exec", { detail: { sourceElement: el } });
@@ -6224,7 +6227,7 @@ var LiveSocket = class {
6224
6227
  * Returns an object with methods to manipulate the DOM and execute JavaScript.
6225
6228
  * The applied changes integrate with server DOM patching.
6226
6229
  *
6227
- * See [JavaScript interoperability](https://hexdocs.pm/phoenix_live_view/js-interop.html) for more information.
6230
+ * See [JavaScript interoperability](https://phoenix-live-view.hexdocs.pm/js-interop.html) for more information.
6228
6231
  */
6229
6232
  js() {
6230
6233
  return js_commands_default(this, "js");