statebus 7.0.7 → 7.0.10
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/client-library.js +35 -10
- package/package.json +1 -1
- package/server-library.js +5 -2
package/client-library.js
CHANGED
|
@@ -721,8 +721,8 @@
|
|
|
721
721
|
// We create special functions for INPUT and TEXTAREA, because they
|
|
722
722
|
// have to do extra work to maintain the cursor when we use statebus
|
|
723
723
|
// instead of React's setState() for state updates.
|
|
724
|
-
window.INPUT = function_for_tag(
|
|
725
|
-
window.TEXTAREA = function_for_tag(
|
|
724
|
+
window.INPUT = function_for_tag(bus.libs.react17.input)
|
|
725
|
+
window.TEXTAREA = function_for_tag(bus.libs.react17.textarea)
|
|
726
726
|
|
|
727
727
|
|
|
728
728
|
// Improve the functions ^^^ put this above
|
|
@@ -784,7 +784,9 @@
|
|
|
784
784
|
// This one is for react v17+.
|
|
785
785
|
function make_fixed_textbox (tagname) {
|
|
786
786
|
// `tagname` can be either "input" or "textarea"
|
|
787
|
-
|
|
787
|
+
|
|
788
|
+
// Create a special component
|
|
789
|
+
var component = createReactClass({
|
|
788
790
|
getInitialState: function() {
|
|
789
791
|
return {value: this.props.value}
|
|
790
792
|
},
|
|
@@ -796,19 +798,42 @@
|
|
|
796
798
|
if (this.props.value)
|
|
797
799
|
this.setState({value: e.target.value})
|
|
798
800
|
},
|
|
801
|
+
onInput: function(e) {
|
|
802
|
+
this.props.onInput && this.props.onInput(e)
|
|
803
|
+
if (this.props.value)
|
|
804
|
+
this.setState({value: e.target.value})
|
|
805
|
+
},
|
|
799
806
|
render: function() {
|
|
800
|
-
var new_props = {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
+
var new_props = {
|
|
808
|
+
...this.props,
|
|
809
|
+
ref: this.props.forwarded_ref // We had to rename ref
|
|
810
|
+
}
|
|
811
|
+
delete new_props.forwarded_ref // Delete the old name
|
|
812
|
+
|
|
813
|
+
// Now replace any onChange or onInput with our wrapper handlers
|
|
814
|
+
if (new_props.hasOwnProperty('onChange'))
|
|
815
|
+
new_props.onChange = this.onChange
|
|
816
|
+
if (new_props.hasOwnProperty('onInput'))
|
|
817
|
+
new_props.onInput = this.onInput
|
|
818
|
+
|
|
807
819
|
return React.createElement(tagname, new_props)
|
|
808
820
|
}
|
|
809
821
|
})
|
|
822
|
+
|
|
823
|
+
// But react components don't pass through the `ref` prop by default,
|
|
824
|
+
// so we have to do that with this special function and rename it to
|
|
825
|
+
// forwarded_ref temporarily:
|
|
826
|
+
return React.forwardRef((props, ref) => {
|
|
827
|
+
return React.createElement(component, {...props, forwarded_ref: ref})
|
|
828
|
+
})
|
|
810
829
|
}
|
|
811
830
|
|
|
831
|
+
// We create special functions for INPUT and TEXTAREA, because they
|
|
832
|
+
// have to do extra work to maintain the cursor when we use statebus
|
|
833
|
+
// instead of React's setState() for state updates.
|
|
834
|
+
bus.libs.react17.input = make_fixed_textbox('input')
|
|
835
|
+
bus.libs.react17.textarea = make_fixed_textbox('textarea')
|
|
836
|
+
|
|
812
837
|
function autodetect_args (func) {
|
|
813
838
|
if (func.args) return
|
|
814
839
|
|
package/package.json
CHANGED
package/server-library.js
CHANGED
|
@@ -145,8 +145,11 @@ function import_server (bus, make_statebus, options)
|
|
|
145
145
|
// If this requests knows about Braid then we presume the programmer
|
|
146
146
|
// knows that any client might make this cross-origin request.
|
|
147
147
|
if (req.headers.version || req.headers.parents || req.headers.subscribe
|
|
148
|
+
|| req.headers.peer || req.headers['put-order']
|
|
148
149
|
|| req.method === 'OPTIONS')
|
|
149
150
|
free_the_cors(req, res)
|
|
151
|
+
if (req.method === 'OPTIONS')
|
|
152
|
+
return
|
|
150
153
|
|
|
151
154
|
// Initialize new clients with an id. We put the client id on
|
|
152
155
|
// req.client, and also in a cookie for the browser to see.
|
|
@@ -258,7 +261,7 @@ function import_server (bus, make_statebus, options)
|
|
|
258
261
|
if (req.headers.peer) {
|
|
259
262
|
let peer = req.headers.peer,
|
|
260
263
|
key = obj.key
|
|
261
|
-
var cb = cbus.http_callbacks[
|
|
264
|
+
var cb = cbus.http_callbacks && cbus.http_callbacks[
|
|
262
265
|
JSON.stringify({peer, key})
|
|
263
266
|
]
|
|
264
267
|
if (cb) cb.has_seen(cbus, key, t.version)
|
|
@@ -2535,7 +2538,7 @@ function free_the_cors (req, res, next) {
|
|
|
2535
2538
|
var free_the_cors = {
|
|
2536
2539
|
"Access-Control-Allow-Origin": "*",
|
|
2537
2540
|
"Access-Control-Allow-Methods": "OPTIONS, HEAD, GET, PUT, UNSUBSCRIBE",
|
|
2538
|
-
"Access-Control-Allow-Headers": "subscribe, peer, version, parents, merge-type, content-type, patches, cache-control"
|
|
2541
|
+
"Access-Control-Allow-Headers": "subscribe, peer, version, parents, merge-type, content-type, patches, cache-control, put-order"
|
|
2539
2542
|
}
|
|
2540
2543
|
Object.entries(free_the_cors).forEach(x => res.setHeader(x[0], x[1]))
|
|
2541
2544
|
if (req.method === 'OPTIONS') {
|