live 0.19.0 → 0.20.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: 887023ca9784f151f43b3ac38a1903f2e57a3f1dfac35a661d2ef407e83d42ab
4
+ data.tar.gz: 72556c5d216c93b2be82971ab760d5ea37d581c9c44382d2c2dda5ec69131e82
5
5
  SHA512:
6
- metadata.gz: 61317101fe18021fea96f836ef083ee437fcf718fc78055609fad3bf369421da3821ac8fcfde1fd80eb5fabcc05d844d64bd5de967372a7a5898bfb6e0017404
7
- data.tar.gz: e35a93dbb23f40ba34a5adbbfb6c1c61de1e199fbdc028fd9013fab288ed9099afc06e2594e3167242f678a80f7f9a4f1b9f0db4762ea5ffe8587369a8455a4a
6
+ metadata.gz: 369384c0913a6913b60377e227ebefcf41e9175430cea1a4b8153286a0273358501bea9167f5393e2577a0d7526edbb38e9d82ac5f79ee3755e257a0fe78cf89
7
+ data.tar.gz: 746a7bfaee5b317831f9271439b28dd3e8f68de4704c07c363a4766809b734e5881553325c948413c32ee2dc8ffeb13c7ad02cb8bac6976fef7be40fe779c8e9
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,7 +67,7 @@ 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
 
69
73
  # Generate a JavaScript string which forwards the specified event to the server.
@@ -76,6 +80,9 @@ module Live
76
80
  end
77
81
  end
78
82
 
83
+ # Generate JavaScript which forwards a form event and its form data to the server.
84
+ # @parameter detail [Hash | Nil] Additional detail associated with the forwarded event.
85
+ # @returns [String] The generated JavaScript expression.
79
86
  def forward_form_event(detail = nil)
80
87
  if detail
81
88
  "live.forwardFormEvent(#{JSON.dump(@id)}, event, #{JSON.dump(detail)})"
@@ -90,17 +97,18 @@ module Live
90
97
  @page = page
91
98
  end
92
99
 
100
+ # Detach the element from its page.
93
101
  def close
94
102
  @page = nil
95
103
  end
96
104
 
97
- # Handle a client event, typically as triggered by {#forward}.
105
+ # Handle a client event, typically as triggered by {#forward_event}.
98
106
  # @parameter event [String] The type of the event.
99
107
  def handle(event)
100
108
  end
101
109
 
102
110
  # Enqueue a remote procedure call to the currently bound page.
103
- # @parameter method [Symbol] The name of the remote functio to invoke.
111
+ # @parameter method [Symbol] The name of the remote function to invoke.
104
112
  # @parameter arguments [Array]
105
113
  def rpc(*arguments)
106
114
  if @page
@@ -112,6 +120,9 @@ module Live
112
120
  end
113
121
  end
114
122
 
123
+ # Execute JavaScript in the context of the client-side element.
124
+ # @parameter code [String] The JavaScript source code to execute.
125
+ # @parameter options [Hash] Options for the remote procedure call.
115
126
  def script(code, **options)
116
127
  rpc(:script, @id, code, options)
117
128
  end
@@ -154,6 +165,10 @@ module Live
154
165
  rpc(:remove, selector, options)
155
166
  end
156
167
 
168
+ # Dispatch an event to each client-side element matching the selector.
169
+ # @parameter selector [String] The CSS selector for the target elements.
170
+ # @parameter type [String] The event type to dispatch.
171
+ # @parameter options [Hash] The event initialization options.
157
172
  def dispatch_event(selector, type, **options)
158
173
  rpc(:dispatchEvent, selector, type, options)
159
174
  end
@@ -164,10 +179,14 @@ module Live
164
179
  builder.text(self.class.name)
165
180
  end
166
181
 
182
+ # Append this element's markup to the specified output buffer.
183
+ # @parameter output [Object] The output buffer which receives the markup.
167
184
  def append_markup(output)
168
185
  build_markup(::XRB::Builder.new(output))
169
186
  end
170
187
 
188
+ # Build this element's markup with the specified builder.
189
+ # @parameter builder [XRB::Builder] The builder which receives the markup.
171
190
  def build_markup(builder)
172
191
  render(builder)
173
192
  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.20.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,13 @@ 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.
30
-
31
- ### Running Tests
32
-
33
- To run the test suite:
21
+ ## Releases
34
22
 
35
- ``` shell
36
- bundle exec sus
37
- ```
23
+ Please see the [project releases](https://socketry.github.io/live/releases/index) for all releases.
38
24
 
39
- ### Making Releases
25
+ ### v0.20.0
40
26
 
41
- Please see the [project releases](https://socketry.github.io/live/releases/index) for all releases.
27
+ - [Web Packages](https://socketry.github.io/live/releases/index#web-packages)
42
28
 
43
29
  ### v0.19.0
44
30
 
@@ -51,31 +37,46 @@ Please see the [project releases](https://socketry.github.io/live/releases/index
51
37
  - Using older versions of `live` with `live-js` v0.16.0 or later may also result in unexpected behavior or errors.
52
38
  - Updating both `live` and `live-js` to their latest versions is recommended to ensure compatibility, and requires no changes to application code.
53
39
 
54
- ### Developer Certificate of Origin
40
+ ## See Also
55
41
 
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.
42
+ - [live-js](https://github.com/socketry/live-js) The client-side JavaScript library.
43
+ - [morphdom](https://github.com/patrick-steele-idem/morphdom) – Efficiently update the client-side HTML.
44
+ - [stimulus-reflex](https://github.com/hopsoft/stimulus_reflex) — An alternative framework which provides similar functionality.
57
45
 
58
- ### Community Guidelines
46
+ ### Examples
59
47
 
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.
48
+ - [Flappy Bird](https://github.com/socketry/flappy-bird) A clone of the classic Flappy Bird game.
61
49
 
62
- ## Releases
50
+ ## Contributing
63
51
 
64
- Please see the [project releases](https://socketry.github.io/live/releases/index) for all releases.
52
+ We welcome contributions to this project.
65
53
 
66
- ### v0.18.0
54
+ 1. Fork the repository.
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
56
+ 3. Commit your changes (`git commit -am 'Add some feature.'`).
57
+ 4. Push to the branch (`git push origin my-new-feature`).
58
+ 5. Create a new pull request.
67
59
 
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.
60
+ ### Running Tests
72
61
 
73
- ## See Also
62
+ To run the test suite:
74
63
 
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.
64
+ ``` bash
65
+ $ bundle exec sus
66
+ ```
78
67
 
79
- ### Examples
68
+ ### Making Releases
80
69
 
81
- - [Flappy Bird](https://github.com/socketry/flappy-bird) A clone of the classic Flappy Bird game.
70
+ To make a new release:
71
+
72
+ ``` bash
73
+ $ bundle exec bake gem:release:patch # or minor or major
74
+ ```
75
+
76
+ ### Developer Certificate of Origin
77
+
78
+ 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.
79
+
80
+ ### Community Guidelines
81
+
82
+ 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,11 @@
1
1
  # Releases
2
2
 
3
+ ## v0.20.0
4
+
5
+ ### Web Packages
6
+
7
+ 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.
8
+
3
9
  ## v0.19.0
4
10
 
5
11
  ### 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.20.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