Skip to content

Commit 17c868e

Browse files
remove karma; failed attempt at vitest
1 parent 8108d52 commit 17c868e

10 files changed

+2841
-654
lines changed

inst/www/react-tools/react-tools.js

-547
This file was deleted.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(function(u,c){typeof exports=="object"&&typeof module<"u"?c(require("react"),require("react-dom"),require("shiny"),require("jquery")):typeof define=="function"&&define.amd?define(["react","react-dom","shiny","jquery"],c):(u=typeof globalThis<"u"?globalThis:u||self,c(u.React,u.ReactDOM,u.Shiny,u.$))})(this,function(u,c,h,s){"use strict";function d(n,t){if(typeof t=="string")return t;if(t.name[0]===t.name[0].toUpperCase()&&!n.hasOwnProperty(t.name))throw new Error("Unknown component: "+t.name);for(let i in t.attribs)m(t.attribs[i])&&(t.attribs[i]=d(n,t.attribs[i]));for(var a=n.hasOwnProperty(t.name)?n[t.name]:t.name,r=[a,t.attribs],e=0;e<t.children.length;e++)r.push(d(n,t.children[e]));return React.createElement.apply(React,r)}const p={widthProperty:"width",heightProperty:"height",appendPx:!1,renderOnResize:!1};function w(n){var t={};for(var a in p)t[a]=p[a];for(var a in n){if(!p.hasOwnProperty(a))throw new Error("Unrecognized option: "+a);t[a]=n[a]}return t}function l(n,t){return t.appendPx?n+"px":n}function m(n){return typeof n=="object"&&n.hasOwnProperty("name")&&n.hasOwnProperty("attribs")&&n.hasOwnProperty("children")}function O(n,t,a,r){var e=w(r);window.HTMLWidgets.widget({name:n,type:t,factory:function(i,o,y){var g,x={},b=function(f){e.renderOnResize&&(typeof f.tag=="object"&&(f.tag.attribs[e.widthProperty]=l(o),f.tag.attribs[e.heightProperty]=l(y)),g=f),this.instance.component=ReactDOM.render(d(a,f.tag),i)};return{instance:x,renderValue:b,resize:function(f,R){e.renderOnResize&&(o=f,y=R,b(g))}}}})}function P(n,{configuration:t,value:a}){let r=!1;t!==void 0&&(this.setInputConfiguration(n,t),r=!0),a!==void 0&&(this.setInputValue(n,a),r=!0),r&&(this.getCallback(n)(),this.render(n))}const V={receiveMessage:P,type:!1,ratePolicy:null};function I(n,t,a,r){r=Object.assign({},V,r),h.inputBindings.register(new class extends h.InputBinding{find(e){return s(e).find(n)}getValue(e){return this.getInputValue(e)}setValue(e,i,o=!1){s(e).data("callback")!==void 0&&(this.setInputValue(e,i),this.getCallback(e)(o),this.render(e))}initialize(e){s(e).data("value",JSON.parse(s(e).next().text())),s(e).data("configuration",JSON.parse(s(e).next().next().text()))}subscribe(e,i){s(e).data("callback",i),this.render(e)}unsubscribe(e){c.render(null,e)}receiveMessage(e,i){r.receiveMessage.call(this,e,i)}getType(e){if(typeof r.type=="function")return r.type.call(this,e);if(r.type===!1||typeof r.type=="string")return r.type;throw new Error("options.type must be false, a string, or a function")}getRatePolicy(){return r.ratePolicy}getInputValue(e){return s(e).data("value")}setInputValue(e,i){s(e).data("value",i)}getInputConfiguration(e){return s(e).data("configuration")}setInputConfiguration(e,i){s(e).data("configuration",i)}getCallback(e){return s(e).data("callback")}render(e){const i=u.createElement(a,{configuration:this.getInputConfiguration(e),value:this.getValue(e),setValue:this.setValue.bind(this,e),el:e});c.render(i,e)}},t)}window.reactR={reactShinyInput:I,reactWidget:O,hydrate:d}});
1+
(function(s,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(s=typeof globalThis<"u"?globalThis:s||self,u(s.reactR={}))})(this,function(s){"use strict";function u(n,t){if(typeof t=="string")return t;if(t.name[0]===t.name[0].toUpperCase()&&!n.hasOwnProperty(t.name))throw new Error("Unknown component: "+t.name);for(let i in t.attribs)g(t.attribs[i])&&(t.attribs[i]=u(n,t.attribs[i]));for(var a=n.hasOwnProperty(t.name)?n[t.name]:t.name,r=[a,t.attribs],e=0;e<t.children.length;e++)r.push(u(n,t.children[e]));return React.createElement.apply(React,r)}const o={widthProperty:"width",heightProperty:"height",appendPx:!1,renderOnResize:!1};function y(n){var t={};for(var a in o)t[a]=o[a];for(var a in n){if(!o.hasOwnProperty(a))throw new Error("Unrecognized option: "+a);t[a]=n[a]}return t}function d(n,t){return t.appendPx?n+"px":n}function g(n){return typeof n=="object"&&n.hasOwnProperty("name")&&n.hasOwnProperty("attribs")&&n.hasOwnProperty("children")}function b(n,t,a,r){var e=y(r);window.HTMLWidgets.widget({name:n,type:t,factory:function(i,c,l){var p,P={},h=function(f){e.renderOnResize&&(typeof f.tag=="object"&&(f.tag.attribs[e.widthProperty]=d(c),f.tag.attribs[e.heightProperty]=d(l)),p=f),this.instance.component=ReactDOM.render(u(a,f.tag),i)};return{instance:P,renderValue:h,resize:function(f,V){e.renderOnResize&&(c=f,l=V,h(p))}}}})}function O(n,{configuration:t,value:a}){let r=!1;t!==void 0&&(this.setInputConfiguration(n,t),r=!0),a!==void 0&&(this.setInputValue(n,a),r=!0),r&&(this.getCallback(n)(),this.render(n))}const w={receiveMessage:O,type:!1,ratePolicy:null};function m(n,t,a,r){r=Object.assign({},w,r),Shiny.inputBindings.register(new class extends Shiny.InputBinding{find(e){return $(e).find(n)}getValue(e){return this.getInputValue(e)}setValue(e,i,c=!1){$(e).data("callback")!==void 0&&(this.setInputValue(e,i),this.getCallback(e)(c),this.render(e))}initialize(e){$(e).data("value",JSON.parse($(e).next().text())),$(e).data("configuration",JSON.parse($(e).next().next().text()))}subscribe(e,i){$(e).data("callback",i),this.render(e)}unsubscribe(e){ReactDOM.render(null,e)}receiveMessage(e,i){r.receiveMessage.call(this,e,i)}getType(e){if(typeof r.type=="function")return r.type.call(this,e);if(r.type===!1||typeof r.type=="string")return r.type;throw new Error("options.type must be false, a string, or a function")}getRatePolicy(){return r.ratePolicy}getInputValue(e){return $(e).data("value")}setInputValue(e,i){$(e).data("value",i)}getInputConfiguration(e){return $(e).data("configuration")}setInputConfiguration(e,i){$(e).data("configuration",i)}getCallback(e){return $(e).data("callback")}render(e){const i=React.createElement(a,{configuration:this.getInputConfiguration(e),value:this.getValue(e),setValue:this.setValue.bind(this,e),el:e});ReactDOM.render(i,e)}},t)}s.hydrate=u,s.reactShinyInput=m,s.reactWidget=b,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});

js-tests/js-tests.jsx renamed to js-tests/react-tools.test.jsx

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import React from 'react';
2-
import ReactDOM from 'react';
3-
import { renderToString, renderToStaticMarkup } from 'react-dom/server';
4-
import parseXml from '@rgrove/parse-xml';
5-
import ReactHtmlParser from 'react-html-parser';
1+
import { assert, describe, it } from 'vitest'
2+
import React from 'react'
3+
import ReactDOM from 'react'
4+
import { renderToString } from 'react-dom/server'
5+
import { parseXml } from '@rgrove/parse-xml'
6+
import { parse } from 'html-react-parser'
7+
import { hydrate } from '../srcjs/react-tools'
68

79
/**
810
* Needed by react-tools.js
911
* In normal operation, these are added to the page as htmlDependencies.
1012
*/
11-
window.React = React;
12-
window.ReactDOM = ReactDOM;
13+
global.React = React;
14+
global.ReactDOM = ReactDOM;
1315

1416
class Shout extends React.Component {
1517
render() {
@@ -71,22 +73,22 @@ describe('window.reactR', () => {
7173
it('hydrates an HTML5 component with a text child', () => {
7274
const markup = '<h1>Hello</h1>';
7375
assert.equal(
74-
renderToString(ReactHtmlParser(markup)),
75-
renderToString(reactR.hydrate({}, stringToTag(markup)))
76+
renderToString(parse(markup)),
77+
renderToString(hydrate({}, stringToTag(markup)))
7678
)
7779
})
7880
it('hydrates nested HTML5 components', () => {
7981
const markup = '<div><h1>Hello</h1><p>Oh, hello.</p></div>'
8082
assert.equal(
81-
renderToString(ReactHtmlParser(markup)),
82-
renderToString(reactR.hydrate({}, stringToTag(markup)))
83+
renderToString(parse(markup)),
84+
renderToString(hydrate({}, stringToTag(markup)))
8385
)
8486
})
8587
});
8688
describe('#hydrate() with Components', () => {
8789
it('should throw an exception with an unknown component', () => {
8890
assert.throws(() => {
89-
reactR.hydrate({ Shout: Shout }, stringToTag('<Bar/>'))
91+
hydrate({ Shout: Shout }, stringToTag('<Bar/>'))
9092
}, Error, /Unknown component/);
9193
});
9294
})

karma.conf.js

-37
This file was deleted.

0 commit comments

Comments
 (0)