turbo_boost-streams 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +88 -34
- data/app/assets/builds/@turbo-boost/streams.js +2 -2
- data/app/assets/builds/@turbo-boost/streams.js.map +4 -4
- data/app/javascript/index.js +1 -3
- data/app/javascript/invoke.js +42 -40
- data/app/javascript/morph.js +3 -4
- data/lib/turbo_boost/streams/version.rb +1 -1
- metadata +3 -3
data/app/javascript/index.js
CHANGED
@@ -14,8 +14,6 @@ Turbo.StreamActions.invoke = invoke
|
|
14
14
|
self.TurboBoost = self.TurboBoost || {}
|
15
15
|
self.TurboBoost.Streams = { invoke, invokeEvents }
|
16
16
|
|
17
|
-
console.info(
|
18
|
-
'@turbo-boost/streams has initialized and registered new stream actions with Turbo.'
|
19
|
-
)
|
17
|
+
console.info('@turbo-boost/streams has initialized and registered new stream actions with Turbo.')
|
20
18
|
|
21
19
|
export default self.TurboBoost.Streams
|
data/app/javascript/invoke.js
CHANGED
@@ -7,7 +7,7 @@ export const invokeEvents = {
|
|
7
7
|
}
|
8
8
|
|
9
9
|
// Invokes the callback on a single receiver with before/after events
|
10
|
-
function withInvokeEvents
|
10
|
+
function withInvokeEvents(receiver, detail, callback) {
|
11
11
|
const { object, target } = receiver
|
12
12
|
detail = detail || {}
|
13
13
|
detail = { ...detail, object: receiver.object }
|
@@ -15,29 +15,39 @@ function withInvokeEvents (receiver, detail, callback) {
|
|
15
15
|
|
16
16
|
target.dispatchEvent(new CustomEvent(invokeEvents.before, options))
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
18
|
+
// the before event can provide invoke instructions my modifying the event detail
|
19
|
+
// For example, { delay: 1000 } will delay the invocation by 1000ms
|
20
|
+
let { delay } = detail.invoke || {}
|
21
|
+
delay = delay || 0
|
22
|
+
|
23
|
+
const execute = () => {
|
24
|
+
const result = callback(object)
|
25
|
+
options.detail.result = result
|
26
|
+
target.dispatchEvent(new CustomEvent(invokeEvents.after, options))
|
27
|
+
|
28
|
+
let promise
|
29
|
+
if (result instanceof Animation) promise = result.finished
|
30
|
+
if (result instanceof Promise) promise = result
|
31
|
+
|
32
|
+
if (promise)
|
33
|
+
promise.then(
|
34
|
+
() => {
|
35
|
+
options.detail.promise = 'fulfilled'
|
36
|
+
target.dispatchEvent(new CustomEvent(invokeEvents.finish, options))
|
37
|
+
},
|
38
|
+
() => {
|
39
|
+
options.detail.promise = 'rejected'
|
40
|
+
target.dispatchEvent(new CustomEvent(invokeEvents.finish, options))
|
41
|
+
}
|
42
|
+
)
|
43
|
+
else target.dispatchEvent(new CustomEvent(invokeEvents.finish, options))
|
44
|
+
}
|
45
|
+
|
46
|
+
if (delay > 0) setTimeout(execute, delay)
|
47
|
+
else execute()
|
38
48
|
}
|
39
49
|
|
40
|
-
function invokeDispatchEvent
|
50
|
+
function invokeDispatchEvent(method, args, receivers) {
|
41
51
|
const eventName = args[0]
|
42
52
|
const eventOptions = args[1]
|
43
53
|
const detail = { method, eventName, eventOptions }
|
@@ -48,41 +58,33 @@ function invokeDispatchEvent (method, args, receivers) {
|
|
48
58
|
)
|
49
59
|
}
|
50
60
|
|
51
|
-
function invokeMorph
|
61
|
+
function invokeMorph(method, args, receivers) {
|
52
62
|
const html = args[0]
|
53
63
|
const detail = { method, html }
|
54
|
-
receivers.forEach(receiver =>
|
55
|
-
withInvokeEvents(receiver, detail, object => morph(object, html))
|
56
|
-
)
|
64
|
+
receivers.forEach(receiver => withInvokeEvents(receiver, detail, object => morph(object, html)))
|
57
65
|
}
|
58
66
|
|
59
|
-
function invokeAssignment
|
67
|
+
function invokeAssignment(method, args, receivers) {
|
60
68
|
const property = method.slice(0, -1).trim()
|
61
69
|
const value = args[0]
|
62
70
|
const detail = { method, property, value }
|
63
|
-
receivers.forEach(receiver =>
|
64
|
-
withInvokeEvents(receiver, detail, object => (object[property] = value))
|
65
|
-
)
|
71
|
+
receivers.forEach(receiver => withInvokeEvents(receiver, detail, object => (object[property] = value)))
|
66
72
|
}
|
67
73
|
|
68
|
-
function invokeMethod
|
74
|
+
function invokeMethod(method, args, receivers) {
|
69
75
|
const detail = { method, args }
|
70
76
|
receivers.forEach(receiver =>
|
71
|
-
withInvokeEvents(receiver, detail, object =>
|
72
|
-
object[method].apply(object, args)
|
73
|
-
)
|
77
|
+
withInvokeEvents(receiver, detail, object => object[method].apply(object, args))
|
74
78
|
)
|
75
79
|
}
|
76
80
|
|
77
81
|
// Performs an invocation on all receivers for the given method and args
|
78
|
-
function performInvoke
|
82
|
+
function performInvoke(method, args, receivers) {
|
79
83
|
// dispatch ................................................................................................
|
80
|
-
if (method.match(/^dispatch(Event)?$/))
|
81
|
-
return invokeDispatchEvent(method, args, receivers)
|
84
|
+
if (method.match(/^dispatch(Event)?$/)) return invokeDispatchEvent(method, args, receivers)
|
82
85
|
|
83
86
|
// morph ...................................................................................................
|
84
|
-
if (method.match(/^morph|mutate$/))
|
85
|
-
return invokeMorph(method, args, receivers)
|
87
|
+
if (method.match(/^morph|mutate$/)) return invokeMorph(method, args, receivers)
|
86
88
|
|
87
89
|
// assignment ..............................................................................................
|
88
90
|
if (method.endsWith('=')) return invokeAssignment(method, args, receivers)
|
@@ -91,7 +93,7 @@ function performInvoke (method, args, receivers) {
|
|
91
93
|
return invokeMethod(method, args, receivers)
|
92
94
|
}
|
93
95
|
|
94
|
-
export function invoke
|
96
|
+
export function invoke() {
|
95
97
|
const payload = JSON.parse(this.templateContent.textContent)
|
96
98
|
const { id, selector, receiver, method, args, delay } = payload
|
97
99
|
let receivers = [{ object: self, target: self }]
|
data/app/javascript/morph.js
CHANGED
@@ -7,17 +7,16 @@ const input = /INPUT/i
|
|
7
7
|
const inputTypes = /date|datetime-local|email|month|number|password|range|search|tel|text|time|url|week/i
|
8
8
|
const textarea = /TEXTAREA/i
|
9
9
|
|
10
|
-
function updating
|
10
|
+
function updating(el, toEl, childrenOnly, skip) {
|
11
11
|
if (el.nodeType !== Node.ELEMENT_NODE) return
|
12
12
|
if (el !== document.activeElement) return
|
13
13
|
|
14
14
|
const protect =
|
15
|
-
el.tagName.match(textarea) ||
|
16
|
-
(el.tagName.match(input) && el.getAttribute('type').match(inputTypes))
|
15
|
+
el.tagName.match(textarea) || (el.tagName.match(input) && el.getAttribute('type').match(inputTypes))
|
17
16
|
|
18
17
|
if (protect) return skip()
|
19
18
|
}
|
20
19
|
|
21
|
-
export default function morph
|
20
|
+
export default function morph(element, html) {
|
22
21
|
alpine.morph(element, html, { updating })
|
23
22
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo_boost-streams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Hopkins (hopsoft)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -344,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
344
344
|
- !ruby/object:Gem::Version
|
345
345
|
version: '0'
|
346
346
|
requirements: []
|
347
|
-
rubygems_version: 3.
|
347
|
+
rubygems_version: 3.5.3
|
348
348
|
signing_key:
|
349
349
|
specification_version: 4
|
350
350
|
summary: Take full control of the DOM with Turbo Streams
|