live 0.19.0 → 0.21.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 826ca30c017f31b254c40ed89d01bf3989aef0ed660935beef1e3e4cb90c53c1
4
- data.tar.gz: 0eccc9cbf069665e895323d50e78321106a065d7d62a3e15c0a67c17a34385c7
3
+ metadata.gz: a44ac9a88c155a83cfb78b1c50cecf8a4fb8ab92017b6dfff58cbd2740e895cd
4
+ data.tar.gz: 7f53fcc3490c409817e78dedbccde8d8c7293fcbe6b1848d03127b06dcb53d5a
5
5
  SHA512:
6
- metadata.gz: 61317101fe18021fea96f836ef083ee437fcf718fc78055609fad3bf369421da3821ac8fcfde1fd80eb5fabcc05d844d64bd5de967372a7a5898bfb6e0017404
7
- data.tar.gz: e35a93dbb23f40ba34a5adbbfb6c1c61de1e199fbdc028fd9013fab288ed9099afc06e2594e3167242f678a80f7f9a4f1b9f0db4762ea5ffe8587369a8455a4a
6
+ metadata.gz: d8331910acb6be7b7accdda95bbb590e5c43d484292c5cd9837119ea8ff9771dded6bf06829d6770831f6006ad3675232c69e3d607227d39c8658a2fc89bc46b
7
+ data.tar.gz: 20759f1153809ea3e9f1827782f21b2c1efa41330814848c8607822dff154a3918d69fbbaafc24bd1b7184e22a2d2b7e17edeb180cf730dd003badeb76495af9
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/live/element.rb CHANGED
@@ -2,16 +2,20 @@
2
2
 
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2021-2026, by Samuel Williams.
5
+ # Copyright, 2026, by Matt Quinn.
5
6
 
6
7
  require "json"
7
8
  require "securerandom"
8
9
 
9
10
  module Live
11
+ # Raised when an operation requires an element to be bound to a page.
10
12
  class PageError < RuntimeError
11
13
  end
12
14
 
13
15
  # Represents a single dynamic content area on the page.
14
16
  class Element
17
+ # Generate a unique identifier for an element.
18
+ # @returns [String] The generated identifier.
15
19
  def self.unique_id
16
20
  SecureRandom.uuid
17
21
  end
@@ -63,9 +67,15 @@ module Live
63
67
  # The data associated with the element.
64
68
  attr :data
65
69
 
66
- # @attribute [Page | Nil] The page this elemenet is bound to.
70
+ # @attribute [Page | Nil] The page this element is bound to.
67
71
  attr :page
68
72
 
73
+ # A CSS selector that uniquely identifies this element.
74
+ # @returns [String]
75
+ def selector
76
+ "[id=#{JSON.dump(@id)}]"
77
+ end
78
+
69
79
  # Generate a JavaScript string which forwards the specified event to the server.
70
80
  # @parameter detail [Hash] The detail associated with the forwarded event.
71
81
  def forward_event(detail = nil)
@@ -76,6 +86,9 @@ module Live
76
86
  end
77
87
  end
78
88
 
89
+ # Generate JavaScript which forwards a form event and its form data to the server.
90
+ # @parameter detail [Hash | Nil] Additional detail associated with the forwarded event.
91
+ # @returns [String] The generated JavaScript expression.
79
92
  def forward_form_event(detail = nil)
80
93
  if detail
81
94
  "live.forwardFormEvent(#{JSON.dump(@id)}, event, #{JSON.dump(detail)})"
@@ -90,17 +103,18 @@ module Live
90
103
  @page = page
91
104
  end
92
105
 
106
+ # Detach the element from its page.
93
107
  def close
94
108
  @page = nil
95
109
  end
96
110
 
97
- # Handle a client event, typically as triggered by {#forward}.
111
+ # Handle a client event, typically as triggered by {#forward_event}.
98
112
  # @parameter event [String] The type of the event.
99
113
  def handle(event)
100
114
  end
101
115
 
102
116
  # Enqueue a remote procedure call to the currently bound page.
103
- # @parameter method [Symbol] The name of the remote functio to invoke.
117
+ # @parameter method [Symbol] The name of the remote function to invoke.
104
118
  # @parameter arguments [Array]
105
119
  def rpc(*arguments)
106
120
  if @page
@@ -112,6 +126,9 @@ module Live
112
126
  end
113
127
  end
114
128
 
129
+ # Execute JavaScript in the context of the client-side element.
130
+ # @parameter code [String] The JavaScript source code to execute.
131
+ # @parameter options [Hash] Options for the remote procedure call.
115
132
  def script(code, **options)
116
133
  rpc(:script, @id, code, options)
117
134
  end
@@ -154,6 +171,10 @@ module Live
154
171
  rpc(:remove, selector, options)
155
172
  end
156
173
 
174
+ # Dispatch an event to each client-side element matching the selector.
175
+ # @parameter selector [String] The CSS selector for the target elements.
176
+ # @parameter type [String] The event type to dispatch.
177
+ # @parameter options [Hash] The event initialization options.
157
178
  def dispatch_event(selector, type, **options)
158
179
  rpc(:dispatchEvent, selector, type, options)
159
180
  end
@@ -164,10 +185,14 @@ module Live
164
185
  builder.text(self.class.name)
165
186
  end
166
187
 
188
+ # Append this element's markup to the specified output buffer.
189
+ # @parameter output [Object] The output buffer which receives the markup.
167
190
  def append_markup(output)
168
191
  build_markup(::XRB::Builder.new(output))
169
192
  end
170
193
 
194
+ # Build this element's markup with the specified builder.
195
+ # @parameter builder [XRB::Builder] The builder which receives the markup.
171
196
  def build_markup(builder)
172
197
  render(builder)
173
198
  end
data/lib/live/page.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2024, by Samuel Williams.
4
+ # Copyright, 2021-2026, by Samuel Williams.
5
5
 
6
6
  require_relative "element"
7
7
  require_relative "resolver"
@@ -41,6 +41,8 @@ module Live
41
41
  @attached[element.id] = element
42
42
  end
43
43
 
44
+ # Detach and close a previously attached element.
45
+ # @parameter element [Live::Element] The element to detach.
44
46
  def detach(element)
45
47
  if @attached.delete(element.id)
46
48
  element.close
@@ -71,6 +73,7 @@ module Live
71
73
  return nil
72
74
  end
73
75
 
76
+ # Close all elements bound to the page.
74
77
  def close
75
78
  @elements.each do |id, element|
76
79
  begin
@@ -81,6 +84,8 @@ module Live
81
84
  end
82
85
  end
83
86
 
87
+ # Enqueue an update to be sent to the connected client.
88
+ # @parameter update [Array] The remote procedure call to serialize and send.
84
89
  def enqueue(update)
85
90
  @updates.enqueue(::Protocol::WebSocket::TextMessage.generate(update))
86
91
  end
data/lib/live/resolver.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2021-2024, by Samuel Williams.
4
+ # Copyright, 2021-2026, by Samuel Williams.
5
5
 
6
6
  require_relative "element"
7
7
 
@@ -13,6 +13,7 @@ module Live
13
13
  self.new.allow(*arguments).freeze
14
14
  end
15
15
 
16
+ # Initialize an empty resolver.
16
17
  def initialize
17
18
  @allowed = {}
18
19
  end
@@ -20,6 +21,7 @@ module Live
20
21
  # @attribute [Hash(String, Class)] A map of allowed class names.
21
22
  attr :allowed
22
23
 
24
+ # Freeze the resolver and its map of allowed classes.
23
25
  def freeze
24
26
  return self unless frozen?
25
27
 
data/lib/live/version.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2021-2026, by Samuel Williams.
5
5
 
6
+ # @namespace
6
7
  module Live
7
- VERSION = "0.19.0"
8
+ VERSION = "0.21.0"
8
9
  end
data/lib/live/view.rb CHANGED
@@ -7,8 +7,10 @@ require_relative "element"
7
7
  require "xrb/builder"
8
8
 
9
9
  module Live
10
- # Represents a single division of content on the page an provides helpers for rendering the content.
10
+ # Represents a single division of content on the page and provides helpers for rendering the content.
11
11
  class View < Element
12
+ # Get the custom element tag name used to render the view.
13
+ # @returns [String] The custom element tag name.
12
14
  def tag_name
13
15
  "live-view"
14
16
  end
data/license.md CHANGED
@@ -3,6 +3,7 @@
3
3
  Copyright, 2021-2026, by Samuel Williams.
4
4
  Copyright, 2023, by Olle Jonsson.
5
5
  Copyright, 2024, by Tatsuhiro Ujihisa.
6
+ Copyright, 2026, by Matt Quinn.
6
7
 
7
8
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
9
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Live
2
2
 
3
- Provides bi-directional live HTML views using WebSockets for communication. You can try out a [live example](https://utopia-falcon-heroku.herokuapp.com/live/index)
3
+ Provides bi-directional live HTML views using WebSockets for communication.
4
4
 
5
5
  [![Development Status](https://github.com/socketry/live/workflows/Test/badge.svg)](https://github.com/socketry/live/actions?workflow=Test)
6
6
 
@@ -18,27 +18,17 @@ Please see the [project documentation](https://socketry.github.io/live/) for mor
18
18
 
19
19
  - [Rails Integration](https://socketry.github.io/live/guides/rails-integration/index) - This guide explains how to use the `live` gem with Ruby on Rails.
20
20
 
21
- ## Contributing
22
-
23
- We welcome contributions to this project.
24
-
25
- 1. Fork it.
26
- 2. Create your feature branch (`git checkout -b my-new-feature`).
27
- 3. Commit your changes (`git commit -am 'Add some feature'`).
28
- 4. Push to the branch (`git push origin my-new-feature`).
29
- 5. Create new Pull Request.
21
+ ## Releases
30
22
 
31
- ### Running Tests
23
+ Please see the [project releases](https://socketry.github.io/live/releases/index) for all releases.
32
24
 
33
- To run the test suite:
25
+ ### v0.21.0
34
26
 
35
- ``` shell
36
- bundle exec sus
37
- ```
27
+ - Add `Live::Element#selector` for safely targeting an element by its exact HTML identifier from CSS selector APIs.
38
28
 
39
- ### Making Releases
29
+ ### v0.20.0
40
30
 
41
- Please see the [project releases](https://socketry.github.io/live/releases/index) for all releases.
31
+ - [Web Packages](https://socketry.github.io/live/releases/index#web-packages)
42
32
 
43
33
  ### v0.19.0
44
34
 
@@ -51,31 +41,46 @@ Please see the [project releases](https://socketry.github.io/live/releases/index
51
41
  - Using older versions of `live` with `live-js` v0.16.0 or later may also result in unexpected behavior or errors.
52
42
  - Updating both `live` and `live-js` to their latest versions is recommended to ensure compatibility, and requires no changes to application code.
53
43
 
54
- ### Developer Certificate of Origin
44
+ ## See Also
55
45
 
56
- In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
46
+ - [live-js](https://github.com/socketry/live-js) The client-side JavaScript library.
47
+ - [morphdom](https://github.com/patrick-steele-idem/morphdom) – Efficiently update the client-side HTML.
48
+ - [stimulus-reflex](https://github.com/hopsoft/stimulus_reflex) — An alternative framework which provides similar functionality.
57
49
 
58
- ### Community Guidelines
50
+ ### Examples
59
51
 
60
- This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
52
+ - [Flappy Bird](https://github.com/socketry/flappy-bird) A clone of the classic Flappy Bird game.
61
53
 
62
- ## Releases
54
+ ## Contributing
63
55
 
64
- Please see the [project releases](https://socketry.github.io/live/releases/index) for all releases.
56
+ We welcome contributions to this project.
65
57
 
66
- ### v0.18.0
58
+ 1. Fork the repository.
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
60
+ 3. Commit your changes (`git commit -am 'Add some feature.'`).
61
+ 4. Push to the branch (`git push origin my-new-feature`).
62
+ 5. Create a new pull request.
67
63
 
68
- - **Breaking Change**: Live now uses Web Components for managing life-cycle events instead of observers. You will need to use `live-js` v0.16.0 or later with this version of `live`, which emits `<live-view>` elements (instead of `<div>` elements).
69
- - Using older versions of `live-js` with this version of `live` may result in unexpected behavior or errors.
70
- - Using older versions of `live` with `live-js` v0.16.0 or later may also result in unexpected behavior or errors.
71
- - Updating both `live` and `live-js` to their latest versions is recommended to ensure compatibility, and requires no changes to application code.
64
+ ### Running Tests
72
65
 
73
- ## See Also
66
+ To run the test suite:
74
67
 
75
- - [live-js](https://github.com/socketry/live-js) – The client-side JavaScript library.
76
- - [morphdom](https://github.com/patrick-steele-idem/morphdom) Efficiently update the client-side HTML.
77
- - [stimulus-reflex](https://github.com/hopsoft/stimulus_reflex) — An alternative framework which provides similar functionality.
68
+ ``` bash
69
+ $ bundle exec sus
70
+ ```
78
71
 
79
- ### Examples
72
+ ### Making Releases
80
73
 
81
- - [Flappy Bird](https://github.com/socketry/flappy-bird) A clone of the classic Flappy Bird game.
74
+ To make a new release:
75
+
76
+ ``` bash
77
+ $ bundle exec bake gem:release:patch # or minor or major
78
+ ```
79
+
80
+ ### Developer Certificate of Origin
81
+
82
+ In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
83
+
84
+ ### Community Guidelines
85
+
86
+ This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
data/releases.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Releases
2
2
 
3
+ ## v0.21.0
4
+
5
+ - Add `Live::Element#selector` for safely targeting an element by its exact HTML identifier from CSS selector APIs.
6
+
7
+ ## v0.20.0
8
+
9
+ ### Web Packages
10
+
11
+ Live now uses `web-packages` to install and project the JavaScript packages used by its browser integration tests. The generated static package manifest supplies the test page import map, while `node_modules` is treated as a disposable package-manager projection.
12
+
3
13
  ## v0.19.0
4
14
 
5
15
  ### Explicit Element Construction
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: live
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Matt Quinn
8
9
  - Olle Jonsson
9
10
  - Tatsuhiro Ujihisa
10
11
  bindir: bin
@@ -99,6 +100,8 @@ homepage: https://github.com/socketry/live
99
100
  licenses:
100
101
  - MIT
101
102
  metadata:
103
+ bug_tracker_uri: https://github.com/socketry/live/issues
104
+ changelog_uri: https://github.com/socketry/live/blob/main/releases.md
102
105
  documentation_uri: https://socketry.github.io/live/
103
106
  source_code_uri: https://github.com/socketry/live.git
104
107
  rdoc_options: []
metadata.gz.sig CHANGED
Binary file