statebus 7.0.4 → 7.0.5
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/{clients.js → client-library.js} +256 -126
- package/extras/tests.js +58 -58
- package/package.json +3 -3
- package/{servers.js → server-library.js} +116 -84
- package/statebus.js +78 -58
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
var websocket_prefix = (clientjs_option('websocket_path')
|
|
3
3
|
|| '_connect_to_statebus_')
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
5
|
+
var react_render = ReactDOM.render
|
|
6
|
+
// make_client_statebus_maker()
|
|
7
|
+
window.bus = window.statebus()
|
|
8
|
+
bus.label = 'bus'
|
|
9
|
+
|
|
10
|
+
bus.libs = {}
|
|
11
|
+
bus.libs.react12 = {}
|
|
12
|
+
bus.libs.react17 = {}
|
|
14
13
|
|
|
15
14
|
// ****************
|
|
16
15
|
// Connecting over the Network
|
|
@@ -61,7 +60,7 @@
|
|
|
61
60
|
return {clientid: me.client}
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
bus.libs.http_out = (prefix, url) => {
|
|
65
64
|
var preprefix = prefix.slice(0,-1)
|
|
66
65
|
var has_prefix = new RegExp('^' + preprefix)
|
|
67
66
|
var is_absolute = /^https?:\/\//
|
|
@@ -126,7 +125,7 @@
|
|
|
126
125
|
})
|
|
127
126
|
}
|
|
128
127
|
|
|
129
|
-
bus(prefix).
|
|
128
|
+
bus(prefix).setter = function (obj, t) {
|
|
130
129
|
bus.set.fire(obj)
|
|
131
130
|
|
|
132
131
|
var put = {
|
|
@@ -141,7 +140,7 @@
|
|
|
141
140
|
send_put(put_id)
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
bus(prefix).
|
|
143
|
+
bus(prefix).getter = function (key, t) {
|
|
145
144
|
// Subscription can be in states:
|
|
146
145
|
// - connecting
|
|
147
146
|
// - connected
|
|
@@ -219,7 +218,7 @@
|
|
|
219
218
|
}
|
|
220
219
|
}
|
|
221
220
|
}
|
|
222
|
-
bus(prefix).
|
|
221
|
+
bus(prefix).forgetter = function (key) {
|
|
223
222
|
subscriptions[key].status = 'aborted'
|
|
224
223
|
subscriptions[key].aborter.abort()
|
|
225
224
|
}
|
|
@@ -236,7 +235,7 @@
|
|
|
236
235
|
bus.route = function (key, method, arg, t) {
|
|
237
236
|
var d = get_domain(key)
|
|
238
237
|
if (d && !connections[d]) {
|
|
239
|
-
|
|
238
|
+
bus.libs.http_out(d + '/*', d + '/')
|
|
240
239
|
connections[d] = true
|
|
241
240
|
}
|
|
242
241
|
|
|
@@ -247,7 +246,7 @@
|
|
|
247
246
|
|
|
248
247
|
// ****************
|
|
249
248
|
// Manipulate Localstorage
|
|
250
|
-
|
|
249
|
+
bus.libs.localstorage = (prefix) => {
|
|
251
250
|
try { localStorage } catch (e) { return }
|
|
252
251
|
|
|
253
252
|
// Sets are queued up, to store values with a delay, in batch
|
|
@@ -261,11 +260,11 @@
|
|
|
261
260
|
sets_are_pending = false
|
|
262
261
|
}
|
|
263
262
|
|
|
264
|
-
bus(prefix).
|
|
263
|
+
bus(prefix).getter = function (key) {
|
|
265
264
|
var result = localStorage.getItem(key)
|
|
266
265
|
return result ? JSON.parse(result) : {key: key}
|
|
267
266
|
}
|
|
268
|
-
bus(prefix).
|
|
267
|
+
bus(prefix).setter = function (obj) {
|
|
269
268
|
// Do I need to make this recurse into the object?
|
|
270
269
|
bus.log('localStore: on_set:', obj.key)
|
|
271
270
|
pending_sets[obj.key] = obj
|
|
@@ -276,7 +275,7 @@
|
|
|
276
275
|
bus.set.fire(obj)
|
|
277
276
|
return obj
|
|
278
277
|
}
|
|
279
|
-
bus(prefix).
|
|
278
|
+
bus(prefix).deleter = function (key) { localStorage.removeItem(key) }
|
|
280
279
|
|
|
281
280
|
|
|
282
281
|
// Hm... this update stuff doesn't seem to work on file:/// urls in chrome
|
|
@@ -309,7 +308,7 @@
|
|
|
309
308
|
// - Change the key prefix
|
|
310
309
|
// - Set this into the cache
|
|
311
310
|
|
|
312
|
-
bus(prefix).
|
|
311
|
+
bus(prefix).setter = function (obj) {
|
|
313
312
|
window.history.replaceState(
|
|
314
313
|
'',
|
|
315
314
|
'',
|
|
@@ -487,24 +486,19 @@
|
|
|
487
486
|
// ### Full-featured single-file app methods
|
|
488
487
|
// ###
|
|
489
488
|
|
|
490
|
-
function make_client_statebus_maker () {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function load_scripts () {
|
|
506
|
-
scripts_ready()
|
|
507
|
-
}
|
|
489
|
+
// function make_client_statebus_maker () {
|
|
490
|
+
// var extra_stuff = ['make_websocket client_creds',
|
|
491
|
+
// 'url_store components'].join(' ').split(' ')
|
|
492
|
+
// if (window.statebus) {
|
|
493
|
+
// var orig_statebus = statebus
|
|
494
|
+
// window.statebus = function make_client_bus () {
|
|
495
|
+
// var bus = orig_statebus()
|
|
496
|
+
// for (var i=0; i<extra_stuff.length; i++)
|
|
497
|
+
// bus[extra_stuff[i]] = eval(extra_stuff[i])
|
|
498
|
+
// return bus
|
|
499
|
+
// }
|
|
500
|
+
// }
|
|
501
|
+
// }
|
|
508
502
|
|
|
509
503
|
function clientjs_option (option_name) {
|
|
510
504
|
// This function must be copy/paste synchronized with statebus.js. Be
|
|
@@ -516,82 +510,35 @@
|
|
|
516
510
|
|
|
517
511
|
// Todo: remove this global
|
|
518
512
|
window.statebus_server = clientjs_option('server')
|
|
519
|
-
var react_render
|
|
520
|
-
function scripts_ready () {
|
|
521
|
-
react_render = ReactDOM.render
|
|
522
|
-
// make_client_statebus_maker()
|
|
523
|
-
window.bus = window.statebus()
|
|
524
|
-
bus.label = 'bus'
|
|
525
|
-
|
|
526
|
-
// improve_react()
|
|
527
|
-
// statebus.ignore_flashbacks = false
|
|
528
|
-
bus.libs = {}
|
|
529
|
-
bus.libs.http_out = http_mount
|
|
530
|
-
bus.libs.react_class = create_react_class
|
|
531
|
-
bus.libs.input = make_better_input_17()
|
|
532
|
-
bus.libs.localstorage = localstorage_client
|
|
533
|
-
|
|
534
|
-
// if (statebus_server !== 'none') {
|
|
535
|
-
// if (clientjs_option('braid_mode')) {
|
|
536
|
-
// console.log('Using Braid-HTTP!')
|
|
537
|
-
// http_mount ('/*', statebus_server)
|
|
538
|
-
// } else {
|
|
539
|
-
// bus.ws_mount ('/*', statebus_server)
|
|
540
|
-
// }
|
|
541
|
-
// }
|
|
542
513
|
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
514
|
+
function is_css_prop (name) {
|
|
515
|
+
if (!is_css_prop.memoized) {
|
|
516
|
+
// Precompute all the css props
|
|
517
|
+
is_css_prop.memoized = {}
|
|
547
518
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
519
|
+
// We used to get all_css_props like this:
|
|
520
|
+
//
|
|
521
|
+
// var all_css_props = Object.keys(document.body.style)
|
|
522
|
+
// if (all_css_props.length < 100) // Firefox
|
|
523
|
+
// all_css_props = Object.keys(document.body.style.__proto__)
|
|
524
|
+
//
|
|
525
|
+
// But now I've hard-coded them:
|
|
526
|
+
var all_css_props = ["alignContent","alignItems","alignSelf","alignmentBaseline","all","animation","animationDelay","animationDirection","animationDuration","animationFillMode","animationIterationCount","animationName","animationPlayState","animationTimingFunction","backfaceVisibility","background","backgroundAttachment","backgroundBlendMode","backgroundClip","backgroundColor","backgroundImage","backgroundOrigin","backgroundPosition","backgroundPositionX","backgroundPositionY","backgroundRepeat","backgroundRepeatX","backgroundRepeatY","backgroundSize","baselineShift","blockSize","border","borderBottom","borderBottomColor","borderBottomLeftRadius","borderBottomRightRadius","borderBottomStyle","borderBottomWidth","borderCollapse","borderColor","borderImage","borderImageOutset","borderImageRepeat","borderImageSlice","borderImageSource","borderImageWidth","borderLeft","borderLeftColor","borderLeftStyle","borderLeftWidth","borderRadius","borderRight","borderRightColor","borderRightStyle","borderRightWidth","borderSpacing","borderStyle","borderTop","borderTopColor","borderTopLeftRadius","borderTopRightRadius","borderTopStyle","borderTopWidth","borderWidth","bottom","boxShadow","boxSizing","breakAfter","breakBefore","breakInside","bufferedRendering","captionSide","caretColor","clear","clip","clipPath","clipRule","color","colorInterpolation","colorInterpolationFilters","colorRendering","columnCount","columnFill","columnGap","columnRule","columnRuleColor","columnRuleStyle","columnRuleWidth","columnSpan","columnWidth","columns","contain","content","counterIncrement","counterReset","cursor","cx","cy","d","direction","display","dominantBaseline","emptyCells","fill","fillOpacity","fillRule","filter","flex","flexBasis","flexDirection","flexFlow","flexGrow","flexShrink","flexWrap","float","floodColor","floodOpacity","font","fontDisplay","fontFamily","fontFeatureSettings","fontKerning","fontSize","fontStretch","fontStyle","fontVariant","fontVariantCaps","fontVariantEastAsian","fontVariantLigatures","fontVariantNumeric","fontVariationSettings","fontWeight","gap","grid","gridArea","gridAutoColumns","gridAutoFlow","gridAutoRows","gridColumn","gridColumnEnd","gridColumnGap","gridColumnStart","gridGap","gridRow","gridRowEnd","gridRowGap","gridRowStart","gridTemplate","gridTemplateAreas","gridTemplateColumns","gridTemplateRows","height","hyphens","imageRendering","inlineSize","isolation","justifyContent","justifyItems","justifySelf","left","letterSpacing","lightingColor","lineBreak","lineHeight","listStyle","listStyleImage","listStylePosition","listStyleType","margin","marginBottom","marginLeft","marginRight","marginTop","marker","markerEnd","markerMid","markerStart","mask","maskType","maxBlockSize","maxHeight","maxInlineSize","maxWidth","maxZoom","minBlockSize","minHeight","minInlineSize","minWidth","minZoom","mixBlendMode","objectFit","objectPosition","offset","offsetDistance","offsetPath","offsetRotate","opacity","order","orientation","orphans","outline","outlineColor","outlineOffset","outlineStyle","outlineWidth","overflow","overflowAnchor","overflowWrap","overflowX","overflowY","overscrollBehavior","overscrollBehaviorX","overscrollBehaviorY","padding","paddingBottom","paddingLeft","paddingRight","paddingTop","page","pageBreakAfter","pageBreakBefore","pageBreakInside","paintOrder","perspective","perspectiveOrigin","placeContent","placeItems","placeSelf","pointerEvents","position","quotes","r","resize","right","rowGap","rx","ry","scrollBehavior","shapeImageThreshold","shapeMargin","shapeOutside","shapeRendering","size","speak","src","stopColor","stopOpacity","stroke","strokeDasharray","strokeDashoffset","strokeLinecap","strokeLinejoin","strokeMiterlimit","strokeOpacity","strokeWidth","tabSize","tableLayout","textAlign","textAlignLast","textAnchor","textCombineUpright","textDecoration","textDecorationColor","textDecorationLine","textDecorationSkipInk","textDecorationStyle","textIndent","textOrientation","textOverflow","textRendering","textShadow","textSizeAdjust","textTransform","textUnderlinePosition","top","touchAction","transform","transformBox","transformOrigin","transformStyle","transition","transitionDelay","transitionDuration","transitionProperty","transitionTimingFunction","unicodeBidi","unicodeRange","userSelect","userZoom","vectorEffect","verticalAlign","visibility","webkitAlignContent","webkitAlignItems","webkitAlignSelf","webkitAnimation","webkitAnimationDelay","webkitAnimationDirection","webkitAnimationDuration","webkitAnimationFillMode","webkitAnimationIterationCount","webkitAnimationName","webkitAnimationPlayState","webkitAnimationTimingFunction","webkitAppRegion","webkitAppearance","webkitBackfaceVisibility","webkitBackgroundClip","webkitBackgroundOrigin","webkitBackgroundSize","webkitBorderAfter","webkitBorderAfterColor","webkitBorderAfterStyle","webkitBorderAfterWidth","webkitBorderBefore","webkitBorderBeforeColor","webkitBorderBeforeStyle","webkitBorderBeforeWidth","webkitBorderBottomLeftRadius","webkitBorderBottomRightRadius","webkitBorderEnd","webkitBorderEndColor","webkitBorderEndStyle","webkitBorderEndWidth","webkitBorderHorizontalSpacing","webkitBorderImage","webkitBorderRadius","webkitBorderStart","webkitBorderStartColor","webkitBorderStartStyle","webkitBorderStartWidth","webkitBorderTopLeftRadius","webkitBorderTopRightRadius","webkitBorderVerticalSpacing","webkitBoxAlign","webkitBoxDecorationBreak","webkitBoxDirection","webkitBoxFlex","webkitBoxOrdinalGroup","webkitBoxOrient","webkitBoxPack","webkitBoxReflect","webkitBoxShadow","webkitBoxSizing","webkitClipPath","webkitColumnBreakAfter","webkitColumnBreakBefore","webkitColumnBreakInside","webkitColumnCount","webkitColumnGap","webkitColumnRule","webkitColumnRuleColor","webkitColumnRuleStyle","webkitColumnRuleWidth","webkitColumnSpan","webkitColumnWidth","webkitColumns","webkitFilter","webkitFlex","webkitFlexBasis","webkitFlexDirection","webkitFlexFlow","webkitFlexGrow","webkitFlexShrink","webkitFlexWrap","webkitFontFeatureSettings","webkitFontSizeDelta","webkitFontSmoothing","webkitHighlight","webkitHyphenateCharacter","webkitJustifyContent","webkitLineBreak","webkitLineClamp","webkitLocale","webkitLogicalHeight","webkitLogicalWidth","webkitMarginAfter","webkitMarginAfterCollapse","webkitMarginBefore","webkitMarginBeforeCollapse","webkitMarginBottomCollapse","webkitMarginCollapse","webkitMarginEnd","webkitMarginStart","webkitMarginTopCollapse","webkitMask","webkitMaskBoxImage","webkitMaskBoxImageOutset","webkitMaskBoxImageRepeat","webkitMaskBoxImageSlice","webkitMaskBoxImageSource","webkitMaskBoxImageWidth","webkitMaskClip","webkitMaskComposite","webkitMaskImage","webkitMaskOrigin","webkitMaskPosition","webkitMaskPositionX","webkitMaskPositionY","webkitMaskRepeat","webkitMaskRepeatX","webkitMaskRepeatY","webkitMaskSize","webkitMaxLogicalHeight","webkitMaxLogicalWidth","webkitMinLogicalHeight","webkitMinLogicalWidth","webkitOpacity","webkitOrder","webkitPaddingAfter","webkitPaddingBefore","webkitPaddingEnd","webkitPaddingStart","webkitPerspective","webkitPerspectiveOrigin","webkitPerspectiveOriginX","webkitPerspectiveOriginY","webkitPrintColorAdjust","webkitRtlOrdering","webkitRubyPosition","webkitShapeImageThreshold","webkitShapeMargin","webkitShapeOutside","webkitTapHighlightColor","webkitTextCombine","webkitTextDecorationsInEffect","webkitTextEmphasis","webkitTextEmphasisColor","webkitTextEmphasisPosition","webkitTextEmphasisStyle","webkitTextFillColor","webkitTextOrientation","webkitTextSecurity","webkitTextSizeAdjust","webkitTextStroke","webkitTextStrokeColor","webkitTextStrokeWidth","webkitTransform","webkitTransformOrigin","webkitTransformOriginX","webkitTransformOriginY","webkitTransformOriginZ","webkitTransformStyle","webkitTransition","webkitTransitionDelay","webkitTransitionDuration","webkitTransitionProperty","webkitTransitionTimingFunction","webkitUserDrag","webkitUserModify","webkitUserSelect","webkitWritingMode","whiteSpace","widows","width","willChange","wordBreak","wordSpacing","wordWrap","writingMode","x","y","zIndex","zoom"]
|
|
551
527
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
var globals = ['get', 'set', 'state']
|
|
528
|
+
var ignore = {d:1, cx:1, cy:1, rx:1, ry:1, x:1, y:1,
|
|
529
|
+
content:1, fill:1, stroke:1, src:1}
|
|
555
530
|
|
|
556
|
-
for (var i=0; i<
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
window[globals[i]] = eval('bus.' + globals[i])
|
|
560
|
-
}
|
|
531
|
+
for (var i=0; i<all_css_props.length; i++)
|
|
532
|
+
if (!ignore[all_css_props[i]])
|
|
533
|
+
is_css_prop.memoized[all_css_props[i]] = true
|
|
561
534
|
}
|
|
562
|
-
|
|
563
|
-
document.addEventListener('DOMContentLoaded', function () {
|
|
564
|
-
if (window.statebus_ready)
|
|
565
|
-
for (var i=0; i<statebus_ready.length; i++)
|
|
566
|
-
statebus_ready[i]()
|
|
567
|
-
}, false)
|
|
568
|
-
|
|
569
|
-
// document.addEventListener('DOMContentLoaded', load_widgets, false)
|
|
570
|
-
|
|
571
|
-
// if (dom.Body || dom.body || dom.BODY)
|
|
572
|
-
// react_render((window.Body || window.body || window.BODY)(), document.body)
|
|
535
|
+
return is_css_prop.memoized[name]
|
|
573
536
|
}
|
|
574
537
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
// We used to get all_css_props like this:
|
|
581
|
-
//
|
|
582
|
-
// var all_css_props = Object.keys(document.body.style)
|
|
583
|
-
// if (all_css_props.length < 100) // Firefox
|
|
584
|
-
// all_css_props = Object.keys(document.body.style.__proto__)
|
|
585
|
-
//
|
|
586
|
-
// But now I've hard-coded them:
|
|
587
|
-
var all_css_props = ["alignContent","alignItems","alignSelf","alignmentBaseline","all","animation","animationDelay","animationDirection","animationDuration","animationFillMode","animationIterationCount","animationName","animationPlayState","animationTimingFunction","backfaceVisibility","background","backgroundAttachment","backgroundBlendMode","backgroundClip","backgroundColor","backgroundImage","backgroundOrigin","backgroundPosition","backgroundPositionX","backgroundPositionY","backgroundRepeat","backgroundRepeatX","backgroundRepeatY","backgroundSize","baselineShift","blockSize","border","borderBottom","borderBottomColor","borderBottomLeftRadius","borderBottomRightRadius","borderBottomStyle","borderBottomWidth","borderCollapse","borderColor","borderImage","borderImageOutset","borderImageRepeat","borderImageSlice","borderImageSource","borderImageWidth","borderLeft","borderLeftColor","borderLeftStyle","borderLeftWidth","borderRadius","borderRight","borderRightColor","borderRightStyle","borderRightWidth","borderSpacing","borderStyle","borderTop","borderTopColor","borderTopLeftRadius","borderTopRightRadius","borderTopStyle","borderTopWidth","borderWidth","bottom","boxShadow","boxSizing","breakAfter","breakBefore","breakInside","bufferedRendering","captionSide","caretColor","clear","clip","clipPath","clipRule","color","colorInterpolation","colorInterpolationFilters","colorRendering","columnCount","columnFill","columnGap","columnRule","columnRuleColor","columnRuleStyle","columnRuleWidth","columnSpan","columnWidth","columns","contain","content","counterIncrement","counterReset","cursor","cx","cy","d","direction","display","dominantBaseline","emptyCells","fill","fillOpacity","fillRule","filter","flex","flexBasis","flexDirection","flexFlow","flexGrow","flexShrink","flexWrap","float","floodColor","floodOpacity","font","fontDisplay","fontFamily","fontFeatureSettings","fontKerning","fontSize","fontStretch","fontStyle","fontVariant","fontVariantCaps","fontVariantEastAsian","fontVariantLigatures","fontVariantNumeric","fontVariationSettings","fontWeight","gap","grid","gridArea","gridAutoColumns","gridAutoFlow","gridAutoRows","gridColumn","gridColumnEnd","gridColumnGap","gridColumnStart","gridGap","gridRow","gridRowEnd","gridRowGap","gridRowStart","gridTemplate","gridTemplateAreas","gridTemplateColumns","gridTemplateRows","height","hyphens","imageRendering","inlineSize","isolation","justifyContent","justifyItems","justifySelf","left","letterSpacing","lightingColor","lineBreak","lineHeight","listStyle","listStyleImage","listStylePosition","listStyleType","margin","marginBottom","marginLeft","marginRight","marginTop","marker","markerEnd","markerMid","markerStart","mask","maskType","maxBlockSize","maxHeight","maxInlineSize","maxWidth","maxZoom","minBlockSize","minHeight","minInlineSize","minWidth","minZoom","mixBlendMode","objectFit","objectPosition","offset","offsetDistance","offsetPath","offsetRotate","opacity","order","orientation","orphans","outline","outlineColor","outlineOffset","outlineStyle","outlineWidth","overflow","overflowAnchor","overflowWrap","overflowX","overflowY","overscrollBehavior","overscrollBehaviorX","overscrollBehaviorY","padding","paddingBottom","paddingLeft","paddingRight","paddingTop","page","pageBreakAfter","pageBreakBefore","pageBreakInside","paintOrder","perspective","perspectiveOrigin","placeContent","placeItems","placeSelf","pointerEvents","position","quotes","r","resize","right","rowGap","rx","ry","scrollBehavior","shapeImageThreshold","shapeMargin","shapeOutside","shapeRendering","size","speak","src","stopColor","stopOpacity","stroke","strokeDasharray","strokeDashoffset","strokeLinecap","strokeLinejoin","strokeMiterlimit","strokeOpacity","strokeWidth","tabSize","tableLayout","textAlign","textAlignLast","textAnchor","textCombineUpright","textDecoration","textDecorationColor","textDecorationLine","textDecorationSkipInk","textDecorationStyle","textIndent","textOrientation","textOverflow","textRendering","textShadow","textSizeAdjust","textTransform","textUnderlinePosition","top","touchAction","transform","transformBox","transformOrigin","transformStyle","transition","transitionDelay","transitionDuration","transitionProperty","transitionTimingFunction","unicodeBidi","unicodeRange","userSelect","userZoom","vectorEffect","verticalAlign","visibility","webkitAlignContent","webkitAlignItems","webkitAlignSelf","webkitAnimation","webkitAnimationDelay","webkitAnimationDirection","webkitAnimationDuration","webkitAnimationFillMode","webkitAnimationIterationCount","webkitAnimationName","webkitAnimationPlayState","webkitAnimationTimingFunction","webkitAppRegion","webkitAppearance","webkitBackfaceVisibility","webkitBackgroundClip","webkitBackgroundOrigin","webkitBackgroundSize","webkitBorderAfter","webkitBorderAfterColor","webkitBorderAfterStyle","webkitBorderAfterWidth","webkitBorderBefore","webkitBorderBeforeColor","webkitBorderBeforeStyle","webkitBorderBeforeWidth","webkitBorderBottomLeftRadius","webkitBorderBottomRightRadius","webkitBorderEnd","webkitBorderEndColor","webkitBorderEndStyle","webkitBorderEndWidth","webkitBorderHorizontalSpacing","webkitBorderImage","webkitBorderRadius","webkitBorderStart","webkitBorderStartColor","webkitBorderStartStyle","webkitBorderStartWidth","webkitBorderTopLeftRadius","webkitBorderTopRightRadius","webkitBorderVerticalSpacing","webkitBoxAlign","webkitBoxDecorationBreak","webkitBoxDirection","webkitBoxFlex","webkitBoxOrdinalGroup","webkitBoxOrient","webkitBoxPack","webkitBoxReflect","webkitBoxShadow","webkitBoxSizing","webkitClipPath","webkitColumnBreakAfter","webkitColumnBreakBefore","webkitColumnBreakInside","webkitColumnCount","webkitColumnGap","webkitColumnRule","webkitColumnRuleColor","webkitColumnRuleStyle","webkitColumnRuleWidth","webkitColumnSpan","webkitColumnWidth","webkitColumns","webkitFilter","webkitFlex","webkitFlexBasis","webkitFlexDirection","webkitFlexFlow","webkitFlexGrow","webkitFlexShrink","webkitFlexWrap","webkitFontFeatureSettings","webkitFontSizeDelta","webkitFontSmoothing","webkitHighlight","webkitHyphenateCharacter","webkitJustifyContent","webkitLineBreak","webkitLineClamp","webkitLocale","webkitLogicalHeight","webkitLogicalWidth","webkitMarginAfter","webkitMarginAfterCollapse","webkitMarginBefore","webkitMarginBeforeCollapse","webkitMarginBottomCollapse","webkitMarginCollapse","webkitMarginEnd","webkitMarginStart","webkitMarginTopCollapse","webkitMask","webkitMaskBoxImage","webkitMaskBoxImageOutset","webkitMaskBoxImageRepeat","webkitMaskBoxImageSlice","webkitMaskBoxImageSource","webkitMaskBoxImageWidth","webkitMaskClip","webkitMaskComposite","webkitMaskImage","webkitMaskOrigin","webkitMaskPosition","webkitMaskPositionX","webkitMaskPositionY","webkitMaskRepeat","webkitMaskRepeatX","webkitMaskRepeatY","webkitMaskSize","webkitMaxLogicalHeight","webkitMaxLogicalWidth","webkitMinLogicalHeight","webkitMinLogicalWidth","webkitOpacity","webkitOrder","webkitPaddingAfter","webkitPaddingBefore","webkitPaddingEnd","webkitPaddingStart","webkitPerspective","webkitPerspectiveOrigin","webkitPerspectiveOriginX","webkitPerspectiveOriginY","webkitPrintColorAdjust","webkitRtlOrdering","webkitRubyPosition","webkitShapeImageThreshold","webkitShapeMargin","webkitShapeOutside","webkitTapHighlightColor","webkitTextCombine","webkitTextDecorationsInEffect","webkitTextEmphasis","webkitTextEmphasisColor","webkitTextEmphasisPosition","webkitTextEmphasisStyle","webkitTextFillColor","webkitTextOrientation","webkitTextSecurity","webkitTextSizeAdjust","webkitTextStroke","webkitTextStrokeColor","webkitTextStrokeWidth","webkitTransform","webkitTransformOrigin","webkitTransformOriginX","webkitTransformOriginY","webkitTransformOriginZ","webkitTransformStyle","webkitTransition","webkitTransitionDelay","webkitTransitionDuration","webkitTransitionProperty","webkitTransitionTimingFunction","webkitUserDrag","webkitUserModify","webkitUserSelect","webkitWritingMode","whiteSpace","widows","width","willChange","wordBreak","wordSpacing","wordWrap","writingMode","x","y","zIndex","zoom"]
|
|
588
|
-
|
|
589
|
-
var ignore = {d:1, cx:1, cy:1, rx:1, ry:1, x:1, y:1,
|
|
590
|
-
content:1, fill:1, stroke:1, src:1}
|
|
591
|
-
var is_css_prop = {}
|
|
592
|
-
for (var i=0; i<all_css_props.length; i++)
|
|
593
|
-
if (!ignore[all_css_props[i]])
|
|
594
|
-
is_css_prop[all_css_props[i]] = true
|
|
538
|
+
// ================================================================
|
|
539
|
+
// React v12 Support
|
|
540
|
+
|
|
541
|
+
bus.libs.react12.improve_react = () => {
|
|
595
542
|
|
|
596
543
|
function better_element(el) {
|
|
597
544
|
// To do:
|
|
@@ -620,7 +567,7 @@
|
|
|
620
567
|
// Styles get redirected to the style field
|
|
621
568
|
else if (arg instanceof Object)
|
|
622
569
|
for (var k in arg)
|
|
623
|
-
if (is_css_prop
|
|
570
|
+
if (is_css_prop(k)
|
|
624
571
|
&& !(k in {width:1,height:1,size:1}
|
|
625
572
|
&& el in {canvas:1, input:1, embed:1, object:1}))
|
|
626
573
|
attrs.style[k] = arg[k] // Merge styles
|
|
@@ -643,6 +590,13 @@
|
|
|
643
590
|
for (var el in React.DOM)
|
|
644
591
|
window[el.toUpperCase()] = better_element(el)
|
|
645
592
|
|
|
593
|
+
// Fixes React controlled textarea widgets so they can work with state
|
|
594
|
+
// updates triggered by forceUpdate, rather than just setState(),
|
|
595
|
+
// because statebus keeps its own state outside of React's setState(),
|
|
596
|
+
// but react doesn't know how to preserve the cursor (and selection)
|
|
597
|
+
// position for updates unless they go through setState(). So this
|
|
598
|
+
// function just wraps input widgets with a component that uses
|
|
599
|
+
// setState().
|
|
646
600
|
function make_better_input (name, element) {
|
|
647
601
|
window[name] = React.createFactory(React.createClass({
|
|
648
602
|
getInitialState: function() {
|
|
@@ -700,24 +654,141 @@
|
|
|
700
654
|
}
|
|
701
655
|
}
|
|
702
656
|
|
|
703
|
-
|
|
704
|
-
|
|
657
|
+
bus.libs.react17.reactive_dom = () => {
|
|
658
|
+
// The window.dom object lets the user define new react components as
|
|
659
|
+
// functions
|
|
660
|
+
window.dom = window.dom || new Proxy({}, {
|
|
661
|
+
get: function (o, k) { return o[k] },
|
|
662
|
+
set: function (o, k, v) {
|
|
663
|
+
o[k] = v
|
|
664
|
+
make_component(k, v)
|
|
665
|
+
return true
|
|
666
|
+
}
|
|
667
|
+
})
|
|
705
668
|
|
|
706
|
-
//
|
|
707
|
-
var
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
669
|
+
// We'll define functions for all HTML tags...
|
|
670
|
+
var function_for_tag = (tag) =>
|
|
671
|
+
(...arguments) => {
|
|
672
|
+
var children = []
|
|
673
|
+
var attrs = {style: {}}
|
|
674
|
+
|
|
675
|
+
for (var i=0; i<arguments.length; i++) {
|
|
676
|
+
var arg = arguments[i]
|
|
677
|
+
|
|
678
|
+
if (arg === undefined)
|
|
679
|
+
continue
|
|
680
|
+
|
|
681
|
+
// Strings, DOM nodes, and arrays become children
|
|
682
|
+
else if (typeof arg === 'string' // For "foo"
|
|
683
|
+
|| arg instanceof String // For new String()
|
|
684
|
+
|| arg && React.isValidElement(arg)
|
|
685
|
+
|| arg instanceof Array)
|
|
686
|
+
children.push(arg)
|
|
687
|
+
|
|
688
|
+
// // Arrays append onto the children
|
|
689
|
+
// else if (arg instanceof Array)
|
|
690
|
+
// Array.prototype.push.apply(children, arg)
|
|
691
|
+
|
|
692
|
+
// Pure objects get merged into object city
|
|
693
|
+
// Styles get redirected to the style field
|
|
694
|
+
else if (arg instanceof Object)
|
|
695
|
+
for (var k in arg)
|
|
696
|
+
if (is_css_prop(k)
|
|
697
|
+
&& !(k in {width:1,height:1,size:1}
|
|
698
|
+
&& tag in {canvas:1, input:1, embed:1, object:1}))
|
|
699
|
+
attrs.style[k] = arg[k] // Merge styles
|
|
700
|
+
else if (k === 'style') // Merge insides of style tags
|
|
701
|
+
for (var k2 in arg[k])
|
|
702
|
+
attrs.style[k2] = arg[k][k2]
|
|
703
|
+
else
|
|
704
|
+
attrs[k] = arg[k] // Or be normal.
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// Now call React.createElement(tag, attrs, children...)
|
|
708
|
+
return React.createElement.apply(
|
|
709
|
+
null,
|
|
710
|
+
[tag, attrs].concat(children)
|
|
711
|
+
)
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// ... or at least most of them -- there are just a few missing from
|
|
715
|
+
// this list.
|
|
716
|
+
var all_tags = 'a,abbr,address,area,article,aside,audio,b,base,bdi,bdo,blockquote,body,br,button,canvas,caption,cite,code,col,colgroup,data,datalist,dd,del,details,dfn,dialog,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,ins,kbd,label,legend,li,link,main,map,mark,menu,meta,meter,nav,noscript,object,ol,optgroup,option,output,p,param,picture,pre,progress,q,s,samp,script,section,select,slot,small,source,span,strong,style,sub,summary,sup,table,tbody,td,template,tfoot,th,thead,title,tr,u,ul,video,input'.split(',')
|
|
717
|
+
all_tags.forEach((tagname) => {
|
|
718
|
+
window[tagname.toUpperCase()] = function_for_tag(tagname)
|
|
719
|
+
})
|
|
720
|
+
|
|
721
|
+
// We create special functions for INPUT and TEXTAREA, because they
|
|
722
|
+
// have to do extra work to maintain the cursor when we use statebus
|
|
723
|
+
// instead of React's setState() for state updates.
|
|
724
|
+
window.INPUT = function_for_tag(make_fixed_textbox('input'))
|
|
725
|
+
window.TEXTAREA = function_for_tag(make_fixed_textbox('textarea'))
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
// Improve the functions ^^^ put this above
|
|
729
|
+
function better_element(el) {
|
|
730
|
+
// To do:
|
|
731
|
+
// - Don't put all args into a children array, cause react thinks
|
|
732
|
+
// that means they need a key.
|
|
712
733
|
|
|
734
|
+
return function () {
|
|
735
|
+
var children = []
|
|
736
|
+
var attrs = {style: {}}
|
|
737
|
+
|
|
738
|
+
for (var i=0; i<arguments.length; i++) {
|
|
739
|
+
var arg = arguments[i]
|
|
740
|
+
|
|
741
|
+
// Strings and DOM nodes and undefined become children
|
|
742
|
+
if (typeof arg === 'string' // For "foo"
|
|
743
|
+
|| arg instanceof String // For new String()
|
|
744
|
+
|| arg && React.isValidElement(arg)
|
|
745
|
+
|| arg === undefined)
|
|
746
|
+
children.push(arg)
|
|
747
|
+
|
|
748
|
+
// Arrays append onto the children
|
|
749
|
+
else if (arg instanceof Array)
|
|
750
|
+
Array.prototype.push.apply(children, arg)
|
|
713
751
|
|
|
714
|
-
|
|
715
|
-
|
|
752
|
+
// Pure objects get merged into object city
|
|
753
|
+
// Styles get redirected to the style field
|
|
754
|
+
else if (arg instanceof Object)
|
|
755
|
+
for (var k in arg)
|
|
756
|
+
if (is_css_prop(k)
|
|
757
|
+
&& !(k in {width:1,height:1,size:1}
|
|
758
|
+
&& el in {canvas:1, input:1, embed:1, object:1}))
|
|
759
|
+
attrs.style[k] = arg[k] // Merge styles
|
|
760
|
+
else if (k === 'style') // Merge insides of style tags
|
|
761
|
+
for (var k2 in arg[k])
|
|
762
|
+
attrs.style[k2] = arg[k][k2]
|
|
763
|
+
else {
|
|
764
|
+
attrs[k] = arg[k] // Or be normal.
|
|
765
|
+
|
|
766
|
+
if (k === 'key')
|
|
767
|
+
attrs['data-key'] = arg[k]
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
if (children.length === 0) children = undefined
|
|
771
|
+
return React.DOM[el](attrs, children)
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// Fixes React controlled textarea widgets so they can work with state
|
|
777
|
+
// updates triggered by forceUpdate, rather than just setState(),
|
|
778
|
+
// because statebus keeps its own state outside of React's setState(),
|
|
779
|
+
// but react doesn't know how to preserve the cursor (and selection)
|
|
780
|
+
// position for updates unless they go through setState(). So this
|
|
781
|
+
// function just wraps input widgets with a component that uses
|
|
782
|
+
// setState().
|
|
783
|
+
//
|
|
784
|
+
// This one is for react v17+.
|
|
785
|
+
function make_fixed_textbox (tagname) {
|
|
786
|
+
// `tagname` can be either "input" or "textarea"
|
|
716
787
|
return createReactClass({
|
|
717
788
|
getInitialState: function() {
|
|
718
789
|
return {value: this.props.value}
|
|
719
790
|
},
|
|
720
|
-
|
|
791
|
+
UNSAFE_componentWillReceiveProps: function(new_props) {
|
|
721
792
|
this.setState({value: new_props.value})
|
|
722
793
|
},
|
|
723
794
|
onChange: function(e) {
|
|
@@ -730,19 +801,30 @@
|
|
|
730
801
|
for (var k in this.props)
|
|
731
802
|
if (this.props.hasOwnProperty(k))
|
|
732
803
|
new_props[k] = this.props[k]
|
|
733
|
-
if (this.state.value)
|
|
804
|
+
if (this.state.hasOwnProperty('value'))
|
|
805
|
+
new_props.value = this.state.value
|
|
734
806
|
new_props.onChange = this.onChange
|
|
735
|
-
return React.createElement(
|
|
807
|
+
return React.createElement(tagname, new_props)
|
|
736
808
|
}
|
|
737
809
|
})
|
|
738
810
|
}
|
|
739
811
|
|
|
812
|
+
function autodetect_args (func) {
|
|
813
|
+
if (func.args) return
|
|
814
|
+
|
|
815
|
+
// Get an array of the func's params
|
|
816
|
+
var comments = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg,
|
|
817
|
+
params = /([^\s,]+)/g,
|
|
818
|
+
s = func.toString().replace(comments, '')
|
|
819
|
+
func.args = s.slice(s.indexOf('(')+1, s.indexOf(')')).match(params) || []
|
|
820
|
+
}
|
|
821
|
+
|
|
740
822
|
// Load the components
|
|
741
823
|
var users_widgets = {}
|
|
742
824
|
function make_component(name, func) {
|
|
743
825
|
// Define the component
|
|
744
826
|
|
|
745
|
-
window[name] = users_widgets[name] =
|
|
827
|
+
window[name] = users_widgets[name] = create_react_class({
|
|
746
828
|
displayName: name,
|
|
747
829
|
render: function () {
|
|
748
830
|
var args = []
|
|
@@ -765,10 +847,10 @@
|
|
|
765
847
|
}
|
|
766
848
|
|
|
767
849
|
// Wrap plain JS values with SPAN, so react doesn't complain
|
|
768
|
-
if (!React.isValidElement(vdom))
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
850
|
+
// if (!React.isValidElement(vdom))
|
|
851
|
+
// // To do: should arrays be flattened into a SPAN's arguments?
|
|
852
|
+
// vdom = React.DOM.span(null, (typeof vdom === 'string')
|
|
853
|
+
// ? vdom : JSON.stringify(vdom))
|
|
772
854
|
return vdom
|
|
773
855
|
},
|
|
774
856
|
componentDidMount: function () {
|
|
@@ -885,5 +967,53 @@
|
|
|
885
967
|
// }
|
|
886
968
|
// }
|
|
887
969
|
|
|
888
|
-
|
|
970
|
+
|
|
971
|
+
bus.libs.react17.react_class = create_react_class
|
|
972
|
+
bus.libs.react17.coffreact = () => {
|
|
973
|
+
bus.libs.react17.reactive_dom()
|
|
974
|
+
load_coffee()
|
|
975
|
+
if (dom.BODY)
|
|
976
|
+
document.addEventListener(
|
|
977
|
+
'DOMContentLoaded',
|
|
978
|
+
() => {
|
|
979
|
+
var root = document.createElement('root')
|
|
980
|
+
document.body.appendChild(root)
|
|
981
|
+
ReactDOM.render(BODY(), root)
|
|
982
|
+
},
|
|
983
|
+
false
|
|
984
|
+
)
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// if (statebus_server !== 'none') {
|
|
988
|
+
// if (clientjs_option('braid_mode')) {
|
|
989
|
+
// console.log('Using Braid-HTTP!')
|
|
990
|
+
// bus.libs.http_out ('/*', statebus_server)
|
|
991
|
+
// } else {
|
|
992
|
+
// bus.ws_mount ('/*', statebus_server)
|
|
993
|
+
// }
|
|
994
|
+
// }
|
|
995
|
+
|
|
996
|
+
http_automount()
|
|
997
|
+
|
|
998
|
+
statebus.compile_coffee = compile_coffee
|
|
999
|
+
statebus.load_client_code = load_client_code
|
|
1000
|
+
|
|
1001
|
+
// if (clientjs_option('globals')) {
|
|
1002
|
+
// // Setup globals
|
|
1003
|
+
// var globals = ['get', 'set', 'state']
|
|
1004
|
+
|
|
1005
|
+
// for (var i=0; i<globals.length; i++) {
|
|
1006
|
+
// console.log('globalizing', globals[i], 'as',
|
|
1007
|
+
// eval('bus.' + globals[i]))
|
|
1008
|
+
// window[globals[i]] = eval('bus.' + globals[i])
|
|
1009
|
+
// }
|
|
1010
|
+
// }
|
|
1011
|
+
|
|
1012
|
+
document.addEventListener('DOMContentLoaded', function () {
|
|
1013
|
+
if (window.statebus_ready)
|
|
1014
|
+
for (var i=0; i<statebus_ready.length; i++)
|
|
1015
|
+
statebus_ready[i]()
|
|
1016
|
+
}, false)
|
|
1017
|
+
|
|
1018
|
+
// document.addEventListener('DOMContentLoaded', load_widgets, false)
|
|
889
1019
|
})()
|