@pie-element/extended-text-entry 14.0.0-next.43 → 14.1.2-next.1
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/CHANGELOG.md +1027 -2523
- package/configure/CHANGELOG.md +870 -2233
- package/configure/package.json +6 -6
- package/controller/CHANGELOG.md +495 -1317
- package/controller/package.json +2 -2
- package/lib/annotation/annotation-editor.js +3 -0
- package/lib/annotation/annotation-editor.js.map +1 -1
- package/lib/main.js +6 -3
- package/lib/main.js.map +1 -1
- package/lib/print.js +2 -2
- package/lib/print.js.map +1 -1
- package/package.json +7 -7
- package/module/configure.js +0 -1
- package/module/controller.js +0 -139
- package/module/demo.js +0 -38
- package/module/element.js +0 -1
- package/module/index.html +0 -21
- package/module/manifest.json +0 -22
- package/module/print-demo.js +0 -76
- package/module/print.html +0 -18
- package/module/print.js +0 -1
package/module/demo.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import Configure from './configure.js';
|
|
2
|
-
import Element from './element.js';
|
|
3
|
-
import * as controller from './controller.js';
|
|
4
|
-
|
|
5
|
-
var generate = {};
|
|
6
|
-
|
|
7
|
-
generate.model = (id, element) => ({
|
|
8
|
-
id,
|
|
9
|
-
element,
|
|
10
|
-
customKeys: ['\\square'],
|
|
11
|
-
feedback: { type: 'default', default: 'this is default feedback' },
|
|
12
|
-
prompt: 'This is the question prompt',
|
|
13
|
-
promptEnabled: true,
|
|
14
|
-
mathInput: true,
|
|
15
|
-
playersToolbarPosition: 'bottom',
|
|
16
|
-
toolbarEditorPosition: 'bottom',
|
|
17
|
-
spellCheckEnabled: true,
|
|
18
|
-
rubricEnabled: false,
|
|
19
|
-
annotationsEnabled: false,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const { model } = generate;
|
|
23
|
-
var config = {
|
|
24
|
-
elements: {
|
|
25
|
-
'extended-text-entry': '../..',
|
|
26
|
-
},
|
|
27
|
-
models: [model('1', 'extended-text-entry')],
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
//Note: demo-el is a custom element loaded in the markup.
|
|
31
|
-
customElements.whenDefined("demo-el").then(() => {
|
|
32
|
-
config.models.forEach((m) => {
|
|
33
|
-
const de = document.createElement("demo-el");
|
|
34
|
-
document.body.appendChild(de);
|
|
35
|
-
de.def = { tagName: m.element, Element, Configure, controller };
|
|
36
|
-
de.model = m;
|
|
37
|
-
});
|
|
38
|
-
});
|
package/module/element.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_dll_react as e,_dll_prop_types as t,_dll_mui__material as n,_dll_mui__material_styles as o,_dll_lodash as i,_dll_debug as s,_dll_pie_lib__render_ui as a,_dll_react_dom as r}from"../../../@pie-lib/shared-module@^3.0.5/module/index.js";import{_dll_pie_lib__math_rendering as l}from"../../../@pie-lib/math-rendering-module@^4.0.5/module/index.js";import{_dll_pie_lib__editable_html_tip_tap as d}from"../../../@pie-lib/editable-html-module@^6.0.5/module/index.js";import{_dll_pie_lib__config_ui as c}from"../../../@pie-lib/config-module@^3.0.0/module/index.js";const h=(e,t,n)=>{const o=n||[],i=o.reduce((e,t)=>e+t.textContent.length,0);let s=!0;if(i>t)return!1;for(e&&(3===e.nodeType&&e.parentNode&&!e.parentNode.hasAttribute("data-ann-id")&&o.push(e),e=e.firstChild);e&&s;)s=h(e,t,o),e=e.nextSibling;return o},p=e=>{const{commonAncestorContainer:t,startContainer:n,endContainer:o,startOffset:i,endOffset:s}=e,a=[];let r=!1,l=!1,d="";const c=e=>{const{nodeValue:t,childNodes:h}=e;e===n&&e===o?(t&&(d+=t.substring(i,s)),r=l=!0):e===n?(t&&(d+=t.substring(i)),r=!0):e===o?(t&&(d+=t.substring(0,s)),l=!0):e&&3===e.nodeType&&e.parentNode&&!e.parentNode.hasAttribute("data-ann-id")&&t&&r&&!l&&(d+=t,a.push(e)),h.forEach(e=>{l||c(e)})};return c(t),[a,d]},m=e=>{const t=document.createElement("SPAN");return e.surroundContents(t),t},u=e=>{if(e.startContainer===e.endContainer)return[m(e)];const[t]=p(e),n=document.createRange();n.selectNodeContents(e.startContainer),n.setStart(e.startContainer,e.startOffset);const o=m(n),i=document.createRange();i.selectNode(e.endContainer),i.setEnd(e.endContainer,e.endOffset);const s=m(i);return[o,...t.map(e=>{const t=document.createElement("SPAN");return e.parentNode.insertBefore(t,e),t.appendChild(e),t}),s]},g=(e,t)=>{(e||[]).forEach(e=>{const t=e.parentNode,n=e.childNodes,o=n.length;if(o>0)for(let i=0;i<o;i++)t.insertBefore(n[0],e);else t.insertBefore(document.createTextNode(e.textContent),e);t.removeChild(e)}),t.normalize()},b=()=>{document.getSelection?(document.getSelection().removeAllRanges(),document.getSelection().addRange(document.createRange())):window.getSelection?window.getSelection().removeAllRanges?(window.getSelection().removeAllRanges(),window.getSelection().addRange(document.createRange())):window.getSelection().empty&&window.getSelection().empty():document.selection&&document.selection.empty()},f=e=>e.length>=20||-1!==e.search(/\n|\r|\r\n/),y=e=>Array.from(document.querySelectorAll(`[data-id='${e}']`)),v=e=>document.querySelector(`[data-ann-id='${e}']`),C=e,x=t,{Popover:_}=n,{TextField:E}=n,{styled:w}=o,S=w(_)(({theme:e,annotationType:t})=>({"& .MuiPaper-root":{overflowX:"unset",overflowY:"unset",marginLeft:"16px","&::before":{position:"absolute",right:"100%",top:"13px",border:"solid transparent",content:'""',height:0,width:0,pointerEvents:"none",borderWidth:"7px",borderRightColor:e.palette.grey[100]},..."negative"===t&&{"&::before":{borderRightColor:"rgb(255, 204, 238) !important"}},..."positive"===t&&{"&::before":{borderRightColor:"rgb(153, 255, 153) !important"}}}})),A=w("div")(({theme:e,annotationType:t})=>({width:"200px",overflow:"hidden",borderRadius:"4px",backgroundColor:"#ffffff",border:`4px solid ${e.palette.grey[100]}`,..."negative"===t&&{borderColor:"rgb(255, 204, 238) !important"},..."positive"===t&&{borderColor:"rgb(153, 255, 153) !important"}})),k=w("div")(({theme:e})=>({display:"flex",flexWrap:"wrap",borderTop:`2px solid ${e.palette.grey[100]}`})),R=w("div")(({theme:e,variant:t,annotationType:n})=>({flexGrow:1,width:"28%",textAlign:"center",padding:"4px",cursor:"pointer","&:not(:nth-child(3n))":{borderRight:`1px solid ${e.palette.grey[100]}`},"&:hover":{backgroundColor:e.palette.grey[100]},..."positive"===t&&{backgroundColor:"rgb(153, 255, 153) !important","&:hover":{filter:"brightness(85%)"}},..."negative"===t&&{backgroundColor:"rgb(255, 204, 238) !important","&:hover":{filter:"brightness(85%)"}},..."typeChange"===t&&"negative"===n&&{"&:hover":{backgroundColor:"rgb(153, 255, 153) !important"}},..."typeChange"===t&&"positive"===n&&{"&:hover":{backgroundColor:"rgb(255, 204, 238) !important"}}}));class T extends C.Component{static __initStatic(){this.propTypes={anchorEl:x.object,open:x.bool,offset:x.number,value:x.string,type:x.string,onClose:x.func,onDelete:x.func,onSave:x.func,onTypeChange:x.func}}constructor(e){super(e),T.prototype.__init.call(this),T.prototype.__init2.call(this),T.prototype.__init3.call(this),this.state={value:e.value}}UNSAFE_componentWillReceiveProps(e){const{value:t}=e,{value:n}=this.props;t!==n&&this.setState({value:t})}__init(){this.onValueChange=e=>this.setState({value:e.target.value})}__init2(){this.handleSave=()=>{const{value:e,onSave:t,onClose:n,onDelete:o}=this.props,{value:i}=this.state;""===i&&o(),e!==i&&t(e,i),this.setState({value:""}),n()}}__init3(){this.handleTypeChange=()=>{const{onTypeChange:e,onDelete:t}=this.props,{value:n}=this.state;""===n?t():e(n),this.setState({value:""})}}render(){const{anchorEl:e,offset:t,onDelete:n,open:o,type:i}=this.props,{value:s}=this.state;return C.createElement(S,{anchorEl:e,elevation:2,open:o,onClose:this.handleSave,annotationType:i,style:{marginTop:`${t}px`,transition:"margin-top 2s ease-out"},transitionDuration:{enter:225,exit:195},anchorOrigin:{vertical:"top",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"}},C.createElement(A,{annotationType:i},C.createElement(E,{id:"annotation-editor",style:{padding:"2px 5px",width:"95%"},autoFocus:!0,multiline:!0,rows:1,maxRows:4,value:s,onChange:this.onValueChange,InputProps:{disableUnderline:!0}}),C.createElement(k,null,C.createElement(R,{onClick:n},"Delete"),C.createElement(R,{variant:"typeChange",annotationType:i,onClick:this.handleTypeChange},"negative"===i?"Green":"Pink"),C.createElement(R,{onClick:this.handleSave},"Save"))))}}T.__initStatic();const L=e,M=t,{styled:P}=o,{Popover:I}=n,N=P(I)({"& .MuiPaper-root":{overflowX:"unset",overflowY:"unset",marginTop:"-16px","&::after":{position:"absolute",left:"calc(50% - 7px)",border:"solid transparent",content:'""',height:0,width:0,pointerEvents:"none",borderWidth:"7px",borderTopColor:"black"}}}),D=P("div")(({theme:e})=>({width:"300px",overflow:"hidden",borderRadius:"4px",backgroundColor:e.palette.common.white,border:`2px solid ${e.palette.grey[100]}`})),W=P("div")({display:"flex",flexWrap:"wrap"}),H=P("div")(({theme:e})=>({display:"flex",flexWrap:"wrap",borderTop:`2px solid ${e.palette.grey[100]}`})),z=P("div")(({theme:e,variant:t})=>({width:"22%",textAlign:"center",padding:"4px",cursor:"pointer",borderBottom:`1px solid ${e.palette.grey[100]}`,"&:not(:nth-child(4n))":{borderRight:`1px solid ${e.palette.grey[100]}`},"&:nth-child(4n)":{flexGrow:1},"&:hover":{backgroundColor:e.palette.grey[100]},..."positive"===t&&{backgroundColor:"rgb(153, 255, 153) !important","&:hover":{filter:"brightness(85%)"}},..."negative"===t&&{backgroundColor:"rgb(255, 204, 238) !important","&:hover":{filter:"brightness(85%)"}}}));class $ extends L.Component{static __initStatic(){this.propTypes={anchorEl:M.object,open:M.bool,annotations:M.array,isNewAnnotation:M.bool,onClose:M.func,onDelete:M.func,onEdit:M.func,onWrite:M.func,onAnnotate:M.func}}render(){const{anchorEl:e,annotations:t,isNewAnnotation:n,onAnnotate:o,onClose:i,onEdit:s,onDelete:a,onWrite:r,open:l}=this.props;return L.createElement(N,{anchorEl:e,open:l,onClose:i,elevation:5,transitionDuration:{enter:225,exit:195},anchorOrigin:{vertical:"top",horizontal:"center"},transformOrigin:{vertical:"bottom",horizontal:"center"}},L.createElement(D,null,L.createElement(W,null,t.map((e,t)=>L.createElement(z,{key:`annotation-${t}`,variant:e.type,onClick:()=>o(e)},e.label))),L.createElement(H,null,L.createElement(z,{onClick:i},"Cancel"),L.createElement(z,{style:{pointerEvents:"none"}}),n?L.createElement(L.Fragment,null,L.createElement(z,{variant:"positive",onClick:()=>r("positive")},"Write"),L.createElement(z,{variant:"negative",onClick:()=>r("negative")},"Write")):L.createElement(L.Fragment,null,L.createElement(z,{onClick:a},"Delete"),L.createElement(z,{onClick:s},"Edit")))))}}$.__initStatic();const O=e,{styled:j}=o,q=t,B=d,{InputContainer:K}=c,F=j("div")({padding:"10px 120px 10px 16px",backgroundColor:"rgba(0, 0, 0, 0.06)",border:"1px solid #ccc",borderRadius:"4px",overflowY:"scroll",lineHeight:"36px",whiteSpace:"pre-wrap",overflowWrap:"break-word","& p":{margin:0},"& span[data-latex]":{userSelect:"none","-webkit-user-select":"none","-moz-user-select":"none","-ms-user-select":"none"}}),U=j("div")({width:"230px"}),V=j("div")({position:"relative",overflowX:"hidden",display:"flex"}),Y=j(K)(({theme:e})=>({paddingTop:e.spacing(2),marginBottom:e.spacing(2),marginTop:e.spacing(2),width:"100%"}));if(!document.getElementById("annotation-editor-styles")){const e=document.createElement("style");e.id="annotation-editor-styles",e.textContent='\n .sideAnnotation:before {\n position: absolute;\n right: var(--before-right, 100%);\n top: var(--before-top, 5px);\n border: solid transparent;\n content: "";\n height: 0;\n width: 0;\n pointer-events: none;\n border-width: var(--before-border-width, 7px);\n border-right-color: var(--before-border-color, rgb(153, 255, 153));\n }\n',document.head.appendChild(e)}class G extends O.Component{static __initStatic(){this.propTypes={text:q.string,comment:q.string,annotations:q.array,predefinedAnnotations:q.array,onChange:q.func.isRequired,onCommentChange:q.func.isRequired,width:q.number,height:q.number,maxHeight:q.string,disabled:q.bool,disabledMath:q.bool,customKeys:q.array,keypadMode:q.string}}constructor(e){super(e),G.prototype.__init.call(this),G.prototype.__init2.call(this),G.prototype.__init3.call(this),G.prototype.__init4.call(this),G.prototype.__init5.call(this),G.prototype.__init6.call(this),G.prototype.__init7.call(this),G.prototype.__init8.call(this),G.prototype.__init9.call(this),G.prototype.__init10.call(this),G.prototype.__init11.call(this),G.prototype.__init12.call(this),G.prototype.__init13.call(this),G.prototype.__init14.call(this),G.prototype.__init15.call(this),this.state={anchorEl:null,openedMenu:!1,openedEditor:!1,selectedElems:[],labelElem:null,selectionDetails:null,annotation:null,annotationIndex:null}}componentDidMount(){const{annotations:e,text:t}=this.props;t&&e.forEach(e=>{const[t,n]=((e,t,n)=>{const o=h(n,t),i=[];let s=0;return o.forEach(n=>{const o=s+n.textContent.length;[e,t].forEach(e=>{s<=e&&e<o&&i.push({node:n,offset:e-s})}),s=o}),i})(e.start,e.end,this.textRef);if(t&&n){const o=document.createRange();o.setStart(t.node,t.offset),o.setEnd(n.node,n.offset);const i=u(o);this.createDOMAnnotation(i,e)}}),this.textRef&&(this.adjustAnnotationsPosition(),this.textRef.addEventListener("scroll",this.adjustAnnotationsPosition))}__init(){this.adjustAnnotationsPosition=()=>{if(this.textRef&&this.labelsRef){const e=this.textRef.offsetLeft+this.textRef.offsetWidth+8;Array.from(this.labelsRef.children).forEach(t=>{const n=y(t.dataset.annId),o=(n[0].offsetTop?n[0].offsetTop:n[0].offsetParent.offsetTop)-this.textRef.scrollTop-6;t.style.top=`${o}px`,t.style.left=`${e}px`})}}}__init2(){this.handleClick=e=>{const{annotations:t}=this.props,{selectionDetails:n}=this.state;if(n)return;const{id:o,annId:i}=e.target.dataset,s=o||i,a=y(s),r=v(s),l=t.findIndex(e=>e.id===s),d=r.hasAttribute("data-freeform");d&&(r.style.zIndex="10"),this.setState({anchorEl:a[0],openedMenu:!!o||!!i&&!d,openedEditor:!!i&&d,selectedElems:a,labelElem:r,annotationIndex:l,annotation:t[l],selectionDetails:null})}}__init3(){this.handleHover=e=>{const{id:t,annId:n}=e.target.dataset,o=t||n,i=y(o),s=v(o),a=s.hasAttribute("data-freeform");i.forEach(e=>{e.style.zIndex="20",e.classList.contains("positive")?e.style.backgroundColor="rgb(51, 255, 51, 0.7)":e.classList.contains("negative")&&(e.style.backgroundColor="rgba(255, 102, 204, 0.55)")}),a?(s.style.zIndex="20",s.classList.contains("positive")?(s.style.backgroundColor="rgb(128, 255, 128)",s.style.setProperty("--before-border-color","rgb(153, 255, 153)")):s.classList.contains("negative")&&(s.style.backgroundColor="rgb(255, 179, 230)",s.style.setProperty("--before-border-color","rgb(255, 179, 230)"))):(s.style.zIndex="20",s.classList.contains("positive")?s.style.color="rgb(0, 77, 0)":s.classList.contains("negative")&&(s.style.color="rgb(153, 0, 102)"))}}__init4(){this.handleCancelHover=e=>{const{id:t,annId:n}=e.target.dataset,o=t||n,i=y(o),s=v(o),a=s.hasAttribute("data-freeform");i.forEach(e=>{e.style.zIndex="",e.classList.contains("positive")?e.style.backgroundColor="rgb(51, 255, 51, 0.5)":e.classList.contains("negative")&&(e.style.backgroundColor="rgba(255, 102, 204, 0.4)")}),a?(s.style.zIndex="",s.classList.contains("positive")?(s.style.backgroundColor="rgb(153, 255, 153)",s.style.removeProperty("--before-border-color")):s.classList.contains("negative")&&(s.style.backgroundColor="rgb(255, 204, 238)",s.style.removeProperty("--before-border-color"))):(s.style.zIndex="",s.classList.contains("positive")?s.style.color="rgb(0, 128, 0)":s.classList.contains("negative")&&(s.style.color="rgb(204, 0, 136)"))}}__init5(){this.handleClose=e=>{const{selectedElems:t,labelElem:n}=this.state;t.length&&!t[0].hasAttribute("data-id")&&g(t,this.textRef),n&&(n.style.zIndex=""),this.setState({anchorEl:null,openedMenu:!1,openedEditor:!1,selectedElems:[],labelElem:null,selectionDetails:null,annotationIndex:null,annotation:null}),b()}}__init6(){this.handleSelection=e=>{const t=window.getSelection();if(e.detail>2)b();else if(t&&t.rangeCount>0){const e=t.getRangeAt(0),n=e.toString(),o=this.textRef.contains(e.commonAncestorContainer);if(!t.isCollapsed&&""!==n&&o){const t=((e,t)=>{const n=document.createRange();n.setStart(t,0),n.setEnd(e.startContainer,e.startOffset);const[,o]=p(n),[,i]=p(e),s=o.length;return{quote:i,start:s,end:s+i.length}})(e,this.textRef),n=u(e);this.setState({anchorEl:n[0],openedMenu:!0,selectedElems:n,selectionDetails:t})}}}}__init7(){this.deleteAnnotation=()=>{const{annotations:e,onChange:t}=this.props,{selectedElems:n,labelElem:o,annotationIndex:i,annotation:s}=this.state;(f(s.label)?this.labelsRef:n[0]).removeChild(o),g(n,this.textRef),e.splice(i,1),t(e),this.handleClose()}}__init8(){this.createDOMAnnotation=(e,t)=>{const{disabled:n}=this.props,{id:o,label:i,type:s}=t;(e||[]).forEach(e=>{e.dataset.id=o,e.className=`annotation ${s}`,e.style.position="relative",e.style.cursor="pointer","positive"===s?e.style.backgroundColor="rgb(51, 255, 51, 0.5)":"negative"===s&&(e.style.backgroundColor="rgba(255, 102, 204, 0.4)"),e.onclick=!n&&this.handleClick,e.onmouseover=this.handleHover,e.onmouseout=this.handleCancelHover});const a=e&&e[0]||{},r=document.createElement("SPAN");if(r.dataset.annId=o,r.innerHTML=i,r.onclick=!n&&this.handleClick,r.onmouseover=this.handleHover,r.onmouseout=this.handleCancelHover,f(i)){const e=(a.offsetTop?a.offsetTop:a.offsetParent.offsetTop)-this.textRef.scrollTop,t=this.textRef.offsetLeft+this.textRef.offsetWidth+8;r.dataset.freeform=!0,r.className=`sideAnnotation ${s}`,r.style.position="absolute",r.style.padding="4px",r.style.borderRadius="4px",r.style.marginLeft="8px",r.style.width="180px",r.style.whiteSpace="pre-wrap",r.style.wordBreak="break-word",r.style.border="2px solid #ffffff",r.style.fontSize="14px",r.style.fontStyle="normal",r.style.fontWeight="normal",r.style.top=`${e}px`,r.style.left=`${t}px`,"negative"===s?r.style.backgroundColor="rgb(255, 204, 238)":"positive"===s&&(r.style.backgroundColor="rgb(153, 255, 153)"),r.style.setProperty("--before-border-width","7px"),r.style.setProperty("--before-top","5px"),r.style.setProperty("--before-right","100%"),"negative"===s?r.style.setProperty("--before-border-color","rgb(255, 204, 238)"):"positive"===s&&r.style.setProperty("--before-border-color","rgb(153, 255, 153)"),this.labelsRef.appendChild(r)}else r.className=`annotationLabel ${s}`,r.style.backgroundColor="rgb(242, 242, 242)",r.style.padding="2px",r.style.position="absolute",r.style.userSelect="none",r.style.whiteSpace="nowrap",r.style.top="-10px",r.style.left="-2px",r.style.fontSize="12px",r.style.fontStyle="normal",r.style.fontWeight="normal",r.style.lineHeight="6px",r.style.webkitUserSelect="none",r.style.mozUserSelect="none",r.style.msUserSelect="none","positive"===s?r.style.color="rgb(0, 128, 0)":"negative"===s&&(r.style.color="rgb(204, 0, 136)"),a.appendChild(r)}}__init9(){this.createNewAnnotation=(e,t)=>{const{selectedElems:n,selectionDetails:o}=this.state,i={id:[o.start,o.end,(new Date).getTime()].join("-"),label:e,type:t,...o};return this.createDOMAnnotation(n,i),i}}__init10(){this.handleMenuClick=e=>{const{annotations:t,onChange:n}=this.props,{annotation:o,annotationIndex:i}=this.state,{type:s,text:a}=e;if(o){const e={...o,label:a,type:s},{type:n,label:r}=o;this.updateLabel(r,e,s!==n&&n),t.splice(i,1,e)}else{const e=this.createNewAnnotation(a,s);t.push(e)}n(t),this.handleClose()}}__init11(){this.editAnnotation=()=>{this.setState({openedMenu:!1,openedEditor:!0})}}__init12(){this.addAnnotation=e=>{const{annotations:t,onChange:n}=this.props,o=this.createNewAnnotation("",e),i=v(o.id);t.push(o),this.setState({openedMenu:!1,openedEditor:!0,annotationIndex:t.length-1,annotation:o,labelElem:i}),n(t)}}__init13(){this.updateLabel=(e,t,n)=>{const{selectedElems:o,labelElem:i}=this.state,{label:s,type:a}=t;f(s)&&f(e)||!f(s)&&!f(e)?(i.innerHTML=s,n&&(i.classList.remove(n),i.classList.add(a),o.forEach(e=>{e.classList.remove(n),e.classList.add(a)}))):f(s)&&!f(e)?(o[0].removeChild(i),this.createDOMAnnotation(o,t)):!f(s)&&f(e)&&(this.labelsRef.removeChild(i),this.createDOMAnnotation(o,t))}}__init14(){this.changeAnnotationType=e=>{const{annotations:t,onChange:n}=this.props,{annotationIndex:o,selectedElems:i}=this.state,{type:s,label:a}=t[o],r="positive"===s?"negative":"positive",l={...t[o],type:r,label:e};i.forEach(e=>{e.classList.remove(s),e.classList.add(r)}),this.updateLabel(a,l,s),t.splice(o,1,l),n(t),this.handleClose()}}__init15(){this.updateAnnotation=(e,t)=>{const{annotations:n,onChange:o}=this.props,{annotationIndex:i}=this.state,s={...n[i],label:t};this.updateLabel(e,s),n.splice(i,1,s),o(n)}}componentWillUnmount(){this.textRef.removeEventListener("scroll",this.adjustAnnotationsPosition)}render(){const{comment:e,customKeys:t,disabled:n,disabledMath:o,keypadMode:i,height:s,width:a,maxHeight:r,onCommentChange:l,predefinedAnnotations:d,text:c}=this.props,{anchorEl:h,annotation:p,openedMenu:m,openedEditor:u,selectionDetails:g}=this.state,f=h&&(h.offsetTop?h.offsetTop:h.offsetParent.offsetTop),y=this.textRef&&f?f-this.textRef.scrollTop-8:0;return O.createElement("div",null,O.createElement(V,null,O.createElement(F,{style:{width:a-34,minHeight:s,maxHeight:r},ref:e=>this.textRef=e,onMouseDown:n?()=>{}:b,onMouseUp:n?()=>{}:this.handleSelection,dangerouslySetInnerHTML:{__html:c}}),O.createElement(U,{ref:e=>this.labelsRef=e})),O.createElement(Y,{label:"Comment"},O.createElement(B,{className:"prompt",markup:e||"",onChange:l,width:a&&(a+104).toString(),disabled:n,pluginProps:{math:{disabled:o,customKeys:t,keypadMode:i,controlledKeypadMode:!1},video:{disabled:!0},audio:{disabled:!0},textAlign:{disabled:!0}}})),O.createElement($,{anchorEl:h,open:m&&!n,annotations:d,isNewAnnotation:!!g,onClose:this.handleClose,onDelete:this.deleteAnnotation,onEdit:this.editAnnotation,onWrite:this.addAnnotation,onAnnotate:this.handleMenuClick}),O.createElement(T,{anchorEl:this.textRef,open:u&&!n,offset:y,value:p&&p.label||"",type:p&&p.type,onClose:this.handleClose,onDelete:this.deleteAnnotation,onSave:this.updateAnnotation,onTypeChange:this.changeAnnotationType}))}}G.__initStatic();const X=e,Q=t,{debounce:J}=i,Z=s,{Typography:ee}=n,{styled:te}=o,{color:ne}=a,{Feedback:oe}=a,{Collapsible:ie}=a,{PreviewPrompt:se}=a,{UiLayout:ae}=a,re=d,le=Z("@pie-ui:extended-text-entry"),de=te(ae)({backgroundColor:ne.background(),color:ne.text()}),ce=te(ee)(({theme:e})=>({width:"100%",color:ne.text(),marginBottom:e.spacing(2),fontSize:"inherit"})),he=te("div")(({theme:e})=>({marginBottom:e.spacing(2)})),pe=te(re)(({theme:e})=>({marginBottom:e.spacing(2),borderRadius:"4px"})),me=te("h2")({position:"absolute",left:"-10000px",top:"auto",width:"1px",height:"1px",overflow:"hidden"});class ue extends X.Component{constructor(...e){super(...e),ue.prototype.__init.call(this),ue.prototype.__init2.call(this)}static __initStatic(){this.propTypes={onValueChange:Q.func.isRequired,onAnnotationsChange:Q.func.isRequired,onCommentChange:Q.func.isRequired,model:Q.object,session:Q.shape({value:Q.string,annotations:Q.array,comment:Q.string}).isRequired}}__init(){this.changeSessionValue=J(this.props.onValueChange,1500)}__init2(){this.changeSessionComment=J(this.props.onCommentChange,1500)}render(){const{model:e,session:t,onAnnotationsChange:n}=this.props,{animationsDisabled:o,annotatorMode:i,customKeys:s,dimensions:a,disabled:r,disabledAnnotator:l,equationEditor:d,extraCSSRules:c,feedback:h,mathInput:p,playersToolbarPosition:m,predefinedAnnotations:u,prompt:g,spanishInput:b,specialInput:f,spellCheckEnabled:y,teacherInstructions:v}=e,{annotations:C,comment:x,value:_}=t,{width:E,height:w}=a||{},S="40vh",A={position:"top"===m?"top":"bottom"};le("[render] disabled? ",r);const k=X.createElement(se,{defaultClassName:"teacher-instructions",prompt:v}),R=[];return b&&R.push({language:"spanish"}),f&&R.push({language:"special"}),X.createElement(de,{extraCSSRules:c,ref:e=>{this.containerRef=e}},X.createElement(me,null,"Constructed Response Question"),v&&X.createElement(he,null,o?k:X.createElement(ie,{labels:{hidden:"Show Teacher Instructions",visible:"Hide Teacher Instructions"}},k)),g&&X.createElement(ce,{component:"span"},X.createElement(se,{defaultClassName:"prompt",prompt:e.prompt})),i?X.createElement(G,{text:_||"",annotations:C||[],comment:x||"",predefinedAnnotations:u||[],onChange:n,onCommentChange:this.changeSessionComment,width:E,height:w,maxHeight:S,disabled:l,disabledMath:!p,customKeys:s,keypadMode:d}):X.createElement(pe,{className:"response-area-editor",onChange:this.changeSessionValue,markup:_||"",maxWidth:E&&E.toString(),minWidth:"100px",minHeight:w&&w.toString(),maxHeight:S,disabled:r,highlightShape:!0,toolbarOpts:A,spellCheck:y,charactersLimit:5e4,autoWidthToolbar:!0,pluginProps:{math:{disabled:!p,customKeys:this.props.model.customKeys,keypadMode:this.props.model.equationEditor,controlledKeypadMode:!1},video:{disabled:!0},audio:{disabled:!0},table:{disabled:!0},textAlign:{disabled:!0},separateParagraphs:{disabled:!1},ul_list:{disabled:!0},ol_list:{disabled:!0}},languageCharactersProps:R}),h&&X.createElement(oe,{correctness:"correct",feedback:h}))}}ue.__initStatic();var ge,be=r;ge=be.createRoot,be.hydrateRoot;var fe={};Object.defineProperty(fe,"__esModule",{value:!0});class ye extends CustomEvent{constructor(e,t,n){super(ye.TYPE,{bubbles:!0,composed:!0,detail:{complete:t,component:e,hasModel:n}}),this.component=e,this.complete=t}}ye.TYPE="model-set";var ve=fe.ModelSetEvent=ye;class Ce extends CustomEvent{constructor(e,t){super(Ce.TYPE,{bubbles:!0,composed:!0,detail:{complete:t,component:e}}),this.component=e,this.complete=t}}Ce.TYPE="session-changed";var xe=fe.SessionChangedEvent=Ce;const _e=e,Ee=s,{renderMath:we}=l,Se=Ee("@pie-elements:extended-text-entry"),Ae=void 0!==typeof window?new DOMParser:{parseFromString:e=>e};function ke(e){if("string"==typeof e)try{const t=Ae.parseFromString(e,"text/html");return t.body.textContent}catch(t){return Se("tried to parse as dom and failed",e),e}}function Re(e){const t=ke(e);return void 0!==t&&t.length>0}class Te extends HTMLElement{constructor(){super(),this._model=null,this._session=null,this._root=null}setLangAttribute(){const e=this._model&&(this._model.language,1)?this._model.language:"",t=e?e.slice(0,2):"en";this.setAttribute("lang",t)}set model(e){this._model=e,this.dispatchEvent(new ve(this.tagName.toLowerCase(),!1,!!this._model)),this.render()}set session(e){this._session=e,this.render()}get session(){return this._session}valueChange(e){this._session.value=e,this.dispatchEvent(new xe(this.tagName.toLowerCase(),Re(e))),this.render()}annotationsChange(e){this._session.annotations=e,this.dispatchEvent(new xe(this.tagName.toLowerCase(),!0)),this.render()}commentChange(e){this._session.comment=e,this.dispatchEvent(new xe(this.tagName.toLowerCase(),Re(e))),this.render()}connectedCallback(){this.setAttribute("aria-label","Written Response Question"),this.setAttribute("role","region"),this.render()}render(){if(this._model&&this._session){let e=_e.createElement(ue,{model:this._model,session:this._session,onValueChange:this.valueChange.bind(this),onAnnotationsChange:this.annotationsChange.bind(this),onCommentChange:this.commentChange.bind(this)});this.setLangAttribute(),this._root||(this._root=ge(this)),this._root.render(e),queueMicrotask(()=>{we(this)})}}disconnectedCallback(){this._root&&this._root.unmount()}}export{Te as default,Re as isComplete,ke as textContent};
|
package/module/index.html
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
<!doctype html>
|
|
3
|
-
<html>
|
|
4
|
-
<head>
|
|
5
|
-
<title>@pie-element/extended-text-entry@14.0.0-beta.1</title>
|
|
6
|
-
<script
|
|
7
|
-
type="module"
|
|
8
|
-
src="https://cdn.jsdelivr.net/npm/@pslb/demo-el@^1.0.0/dist/demo-el/demo-el.esm.js"></script>
|
|
9
|
-
|
|
10
|
-
<link
|
|
11
|
-
href="https://fonts.googleapis.com/css?family=Roboto&display=swap"
|
|
12
|
-
rel="stylesheet"
|
|
13
|
-
/>
|
|
14
|
-
<style>
|
|
15
|
-
html, body {
|
|
16
|
-
font-family: 'Roboto', sans-serif;
|
|
17
|
-
}
|
|
18
|
-
</style>
|
|
19
|
-
<script type="module" src="./demo.js"></script>
|
|
20
|
-
</head>
|
|
21
|
-
</html>
|
package/module/manifest.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pie-element/extended-text-entry",
|
|
3
|
-
"version": "14.0.0-beta.1",
|
|
4
|
-
"modules": [
|
|
5
|
-
{
|
|
6
|
-
"name": "@pie-lib/shared-module",
|
|
7
|
-
"version": "^3.0.5"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"name": "@pie-lib/math-rendering-module",
|
|
11
|
-
"version": "^4.0.5"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"name": "@pie-lib/editable-html-module",
|
|
15
|
-
"version": "^6.0.5"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"name": "@pie-lib/config-module",
|
|
19
|
-
"version": "^3.0.0"
|
|
20
|
-
}
|
|
21
|
-
]
|
|
22
|
-
}
|
package/module/print-demo.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import PrintElement from './print.js';
|
|
2
|
-
|
|
3
|
-
var generate = {};
|
|
4
|
-
|
|
5
|
-
generate.model = (id, element) => ({
|
|
6
|
-
id,
|
|
7
|
-
element,
|
|
8
|
-
customKeys: ['\\square'],
|
|
9
|
-
feedback: { type: 'default', default: 'this is default feedback' },
|
|
10
|
-
prompt: 'This is the question prompt',
|
|
11
|
-
promptEnabled: true,
|
|
12
|
-
mathInput: true,
|
|
13
|
-
playersToolbarPosition: 'bottom',
|
|
14
|
-
toolbarEditorPosition: 'bottom',
|
|
15
|
-
spellCheckEnabled: true,
|
|
16
|
-
rubricEnabled: false,
|
|
17
|
-
annotationsEnabled: false,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const { model } = generate;
|
|
21
|
-
var config = {
|
|
22
|
-
elements: {
|
|
23
|
-
'extended-text-entry': '../..',
|
|
24
|
-
},
|
|
25
|
-
models: [model('1', 'extended-text-entry')],
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// new init - just shows off print!
|
|
29
|
-
|
|
30
|
-
const init = async () => {
|
|
31
|
-
console.log('define the element...');
|
|
32
|
-
await Promise.all(
|
|
33
|
-
config.models.map(async (m) => {
|
|
34
|
-
try {
|
|
35
|
-
const printTag = `${m.element}-print`;
|
|
36
|
-
if (customElements.get(printTag)) {
|
|
37
|
-
return true;
|
|
38
|
-
} else {
|
|
39
|
-
customElements.define(printTag, PrintElement);
|
|
40
|
-
await customElements.whenDefined(printTag);
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
} catch (e) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
console.log('now apply the model...');
|
|
50
|
-
config.models.forEach((m) => {
|
|
51
|
-
const printTag = `${m.element}-print`;
|
|
52
|
-
const h3s = document.createElement('h3');
|
|
53
|
-
h3s.textContent = 'student mode';
|
|
54
|
-
document.body.appendChild(h3s);
|
|
55
|
-
const de = document.createElement(printTag);
|
|
56
|
-
document.body.appendChild(de);
|
|
57
|
-
de.options = {};
|
|
58
|
-
de.model = m;
|
|
59
|
-
|
|
60
|
-
const h3 = document.createElement('h3');
|
|
61
|
-
h3.textContent = 'instructor mode';
|
|
62
|
-
document.body.appendChild(h3);
|
|
63
|
-
const instr = document.createElement(printTag);
|
|
64
|
-
document.body.appendChild(instr);
|
|
65
|
-
instr.options = { mode: 'instructor' };
|
|
66
|
-
instr.model = JSON.parse(JSON.stringify(m));
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
init()
|
|
71
|
-
.then(() => {
|
|
72
|
-
console.log('ready');
|
|
73
|
-
})
|
|
74
|
-
.catch((e) => {
|
|
75
|
-
console.error(e);
|
|
76
|
-
});
|
package/module/print.html
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
<!doctype html>
|
|
3
|
-
<html>
|
|
4
|
-
<head>
|
|
5
|
-
<title>@pie-element/extended-text-entry@14.0.0-beta.1</title>
|
|
6
|
-
<link
|
|
7
|
-
href="https://fonts.googleapis.com/css?family=Roboto&display=swap"
|
|
8
|
-
rel="stylesheet"
|
|
9
|
-
/>
|
|
10
|
-
<style>
|
|
11
|
-
html, body {
|
|
12
|
-
font-family: 'Roboto', sans-serif;
|
|
13
|
-
}
|
|
14
|
-
</style>
|
|
15
|
-
<script type="module" src="./print-demo.js"></script>
|
|
16
|
-
</head>
|
|
17
|
-
<body></body>
|
|
18
|
-
</html>
|
package/module/print.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_dll_react_dom as e,_dll_react as t,_dll_prop_types as n,_dll_mui__material as o,_dll_mui__material_styles as i,_dll_lodash as s,_dll_debug as a,_dll_pie_lib__render_ui as r}from"../../../@pie-lib/shared-module@^3.0.5/module/index.js";import{_dll_pie_lib__math_rendering as l}from"../../../@pie-lib/math-rendering-module@^4.0.5/module/index.js";import{_dll_pie_lib__editable_html_tip_tap as d}from"../../../@pie-lib/editable-html-module@^6.0.5/module/index.js";import{_dll_pie_lib__config_ui as c}from"../../../@pie-lib/config-module@^3.0.0/module/index.js";var p,h=e;p=h.createRoot,h.hydrateRoot;const m=(e,t,n)=>{const o=n||[],i=o.reduce((e,t)=>e+t.textContent.length,0);let s=!0;if(i>t)return!1;for(e&&(3===e.nodeType&&e.parentNode&&!e.parentNode.hasAttribute("data-ann-id")&&o.push(e),e=e.firstChild);e&&s;)s=m(e,t,o),e=e.nextSibling;return o},u=e=>{const{commonAncestorContainer:t,startContainer:n,endContainer:o,startOffset:i,endOffset:s}=e,a=[];let r=!1,l=!1,d="";const c=e=>{const{nodeValue:t,childNodes:p}=e;e===n&&e===o?(t&&(d+=t.substring(i,s)),r=l=!0):e===n?(t&&(d+=t.substring(i)),r=!0):e===o?(t&&(d+=t.substring(0,s)),l=!0):e&&3===e.nodeType&&e.parentNode&&!e.parentNode.hasAttribute("data-ann-id")&&t&&r&&!l&&(d+=t,a.push(e)),p.forEach(e=>{l||c(e)})};return c(t),[a,d]},g=e=>{const t=document.createElement("SPAN");return e.surroundContents(t),t},b=e=>{if(e.startContainer===e.endContainer)return[g(e)];const[t]=u(e),n=document.createRange();n.selectNodeContents(e.startContainer),n.setStart(e.startContainer,e.startOffset);const o=g(n),i=document.createRange();i.selectNode(e.endContainer),i.setEnd(e.endContainer,e.endOffset);const s=g(i);return[o,...t.map(e=>{const t=document.createElement("SPAN");return e.parentNode.insertBefore(t,e),t.appendChild(e),t}),s]},f=(e,t)=>{(e||[]).forEach(e=>{const t=e.parentNode,n=e.childNodes,o=n.length;if(o>0)for(let i=0;i<o;i++)t.insertBefore(n[0],e);else t.insertBefore(document.createTextNode(e.textContent),e);t.removeChild(e)}),t.normalize()},y=()=>{document.getSelection?(document.getSelection().removeAllRanges(),document.getSelection().addRange(document.createRange())):window.getSelection?window.getSelection().removeAllRanges?(window.getSelection().removeAllRanges(),window.getSelection().addRange(document.createRange())):window.getSelection().empty&&window.getSelection().empty():document.selection&&document.selection.empty()},v=e=>e.length>=20||-1!==e.search(/\n|\r|\r\n/),C=e=>Array.from(document.querySelectorAll(`[data-id='${e}']`)),x=e=>document.querySelector(`[data-ann-id='${e}']`),_=t,E=n,{Popover:w}=o,{TextField:S}=o,{styled:k}=i,A=k(w)(({theme:e,annotationType:t})=>({"& .MuiPaper-root":{overflowX:"unset",overflowY:"unset",marginLeft:"16px","&::before":{position:"absolute",right:"100%",top:"13px",border:"solid transparent",content:'""',height:0,width:0,pointerEvents:"none",borderWidth:"7px",borderRightColor:e.palette.grey[100]},..."negative"===t&&{"&::before":{borderRightColor:"rgb(255, 204, 238) !important"}},..."positive"===t&&{"&::before":{borderRightColor:"rgb(153, 255, 153) !important"}}}})),R=k("div")(({theme:e,annotationType:t})=>({width:"200px",overflow:"hidden",borderRadius:"4px",backgroundColor:"#ffffff",border:`4px solid ${e.palette.grey[100]}`,..."negative"===t&&{borderColor:"rgb(255, 204, 238) !important"},..."positive"===t&&{borderColor:"rgb(153, 255, 153) !important"}})),T=k("div")(({theme:e})=>({display:"flex",flexWrap:"wrap",borderTop:`2px solid ${e.palette.grey[100]}`})),I=k("div")(({theme:e,variant:t,annotationType:n})=>({flexGrow:1,width:"28%",textAlign:"center",padding:"4px",cursor:"pointer","&:not(:nth-child(3n))":{borderRight:`1px solid ${e.palette.grey[100]}`},"&:hover":{backgroundColor:e.palette.grey[100]},..."positive"===t&&{backgroundColor:"rgb(153, 255, 153) !important","&:hover":{filter:"brightness(85%)"}},..."negative"===t&&{backgroundColor:"rgb(255, 204, 238) !important","&:hover":{filter:"brightness(85%)"}},..."typeChange"===t&&"negative"===n&&{"&:hover":{backgroundColor:"rgb(153, 255, 153) !important"}},..."typeChange"===t&&"positive"===n&&{"&:hover":{backgroundColor:"rgb(255, 204, 238) !important"}}}));class M extends _.Component{static __initStatic(){this.propTypes={anchorEl:E.object,open:E.bool,offset:E.number,value:E.string,type:E.string,onClose:E.func,onDelete:E.func,onSave:E.func,onTypeChange:E.func}}constructor(e){super(e),M.prototype.__init.call(this),M.prototype.__init2.call(this),M.prototype.__init3.call(this),this.state={value:e.value}}UNSAFE_componentWillReceiveProps(e){const{value:t}=e,{value:n}=this.props;t!==n&&this.setState({value:t})}__init(){this.onValueChange=e=>this.setState({value:e.target.value})}__init2(){this.handleSave=()=>{const{value:e,onSave:t,onClose:n,onDelete:o}=this.props,{value:i}=this.state;""===i&&o(),e!==i&&t(e,i),this.setState({value:""}),n()}}__init3(){this.handleTypeChange=()=>{const{onTypeChange:e,onDelete:t}=this.props,{value:n}=this.state;""===n?t():e(n),this.setState({value:""})}}render(){const{anchorEl:e,offset:t,onDelete:n,open:o,type:i}=this.props,{value:s}=this.state;return _.createElement(A,{anchorEl:e,elevation:2,open:o,onClose:this.handleSave,annotationType:i,style:{marginTop:`${t}px`,transition:"margin-top 2s ease-out"},transitionDuration:{enter:225,exit:195},anchorOrigin:{vertical:"top",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"}},_.createElement(R,{annotationType:i},_.createElement(S,{id:"annotation-editor",style:{padding:"2px 5px",width:"95%"},autoFocus:!0,multiline:!0,rows:1,maxRows:4,value:s,onChange:this.onValueChange,InputProps:{disableUnderline:!0}}),_.createElement(T,null,_.createElement(I,{onClick:n},"Delete"),_.createElement(I,{variant:"typeChange",annotationType:i,onClick:this.handleTypeChange},"negative"===i?"Green":"Pink"),_.createElement(I,{onClick:this.handleSave},"Save"))))}}M.__initStatic();const L=t,P=n,{styled:D}=i,{Popover:N}=o,H=D(N)({"& .MuiPaper-root":{overflowX:"unset",overflowY:"unset",marginTop:"-16px","&::after":{position:"absolute",left:"calc(50% - 7px)",border:"solid transparent",content:'""',height:0,width:0,pointerEvents:"none",borderWidth:"7px",borderTopColor:"black"}}}),W=D("div")(({theme:e})=>({width:"300px",overflow:"hidden",borderRadius:"4px",backgroundColor:e.palette.common.white,border:`2px solid ${e.palette.grey[100]}`})),z=D("div")({display:"flex",flexWrap:"wrap"}),$=D("div")(({theme:e})=>({display:"flex",flexWrap:"wrap",borderTop:`2px solid ${e.palette.grey[100]}`})),O=D("div")(({theme:e,variant:t})=>({width:"22%",textAlign:"center",padding:"4px",cursor:"pointer",borderBottom:`1px solid ${e.palette.grey[100]}`,"&:not(:nth-child(4n))":{borderRight:`1px solid ${e.palette.grey[100]}`},"&:nth-child(4n)":{flexGrow:1},"&:hover":{backgroundColor:e.palette.grey[100]},..."positive"===t&&{backgroundColor:"rgb(153, 255, 153) !important","&:hover":{filter:"brightness(85%)"}},..."negative"===t&&{backgroundColor:"rgb(255, 204, 238) !important","&:hover":{filter:"brightness(85%)"}}}));class j extends L.Component{static __initStatic(){this.propTypes={anchorEl:P.object,open:P.bool,annotations:P.array,isNewAnnotation:P.bool,onClose:P.func,onDelete:P.func,onEdit:P.func,onWrite:P.func,onAnnotate:P.func}}render(){const{anchorEl:e,annotations:t,isNewAnnotation:n,onAnnotate:o,onClose:i,onEdit:s,onDelete:a,onWrite:r,open:l}=this.props;return L.createElement(H,{anchorEl:e,open:l,onClose:i,elevation:5,transitionDuration:{enter:225,exit:195},anchorOrigin:{vertical:"top",horizontal:"center"},transformOrigin:{vertical:"bottom",horizontal:"center"}},L.createElement(W,null,L.createElement(z,null,t.map((e,t)=>L.createElement(O,{key:`annotation-${t}`,variant:e.type,onClick:()=>o(e)},e.label))),L.createElement($,null,L.createElement(O,{onClick:i},"Cancel"),L.createElement(O,{style:{pointerEvents:"none"}}),n?L.createElement(L.Fragment,null,L.createElement(O,{variant:"positive",onClick:()=>r("positive")},"Write"),L.createElement(O,{variant:"negative",onClick:()=>r("negative")},"Write")):L.createElement(L.Fragment,null,L.createElement(O,{onClick:a},"Delete"),L.createElement(O,{onClick:s},"Edit")))))}}j.__initStatic();const q=t,{styled:B}=i,K=n,U=d,{InputContainer:V}=c,F=B("div")({padding:"10px 120px 10px 16px",backgroundColor:"rgba(0, 0, 0, 0.06)",border:"1px solid #ccc",borderRadius:"4px",overflowY:"scroll",lineHeight:"36px",whiteSpace:"pre-wrap",overflowWrap:"break-word","& p":{margin:0},"& span[data-latex]":{userSelect:"none","-webkit-user-select":"none","-moz-user-select":"none","-ms-user-select":"none"}}),G=B("div")({width:"230px"}),X=B("div")({position:"relative",overflowX:"hidden",display:"flex"}),Y=B(V)(({theme:e})=>({paddingTop:e.spacing(2),marginBottom:e.spacing(2),marginTop:e.spacing(2),width:"100%"}));if(!document.getElementById("annotation-editor-styles")){const e=document.createElement("style");e.id="annotation-editor-styles",e.textContent='\n .sideAnnotation:before {\n position: absolute;\n right: var(--before-right, 100%);\n top: var(--before-top, 5px);\n border: solid transparent;\n content: "";\n height: 0;\n width: 0;\n pointer-events: none;\n border-width: var(--before-border-width, 7px);\n border-right-color: var(--before-border-color, rgb(153, 255, 153));\n }\n',document.head.appendChild(e)}class Q extends q.Component{static __initStatic(){this.propTypes={text:K.string,comment:K.string,annotations:K.array,predefinedAnnotations:K.array,onChange:K.func.isRequired,onCommentChange:K.func.isRequired,width:K.number,height:K.number,maxHeight:K.string,disabled:K.bool,disabledMath:K.bool,customKeys:K.array,keypadMode:K.string}}constructor(e){super(e),Q.prototype.__init.call(this),Q.prototype.__init2.call(this),Q.prototype.__init3.call(this),Q.prototype.__init4.call(this),Q.prototype.__init5.call(this),Q.prototype.__init6.call(this),Q.prototype.__init7.call(this),Q.prototype.__init8.call(this),Q.prototype.__init9.call(this),Q.prototype.__init10.call(this),Q.prototype.__init11.call(this),Q.prototype.__init12.call(this),Q.prototype.__init13.call(this),Q.prototype.__init14.call(this),Q.prototype.__init15.call(this),this.state={anchorEl:null,openedMenu:!1,openedEditor:!1,selectedElems:[],labelElem:null,selectionDetails:null,annotation:null,annotationIndex:null}}componentDidMount(){const{annotations:e,text:t}=this.props;t&&e.forEach(e=>{const[t,n]=((e,t,n)=>{const o=m(n,t),i=[];let s=0;return o.forEach(n=>{const o=s+n.textContent.length;[e,t].forEach(e=>{s<=e&&e<o&&i.push({node:n,offset:e-s})}),s=o}),i})(e.start,e.end,this.textRef);if(t&&n){const o=document.createRange();o.setStart(t.node,t.offset),o.setEnd(n.node,n.offset);const i=b(o);this.createDOMAnnotation(i,e)}}),this.textRef&&(this.adjustAnnotationsPosition(),this.textRef.addEventListener("scroll",this.adjustAnnotationsPosition))}__init(){this.adjustAnnotationsPosition=()=>{if(this.textRef&&this.labelsRef){const e=this.textRef.offsetLeft+this.textRef.offsetWidth+8;Array.from(this.labelsRef.children).forEach(t=>{const n=C(t.dataset.annId),o=(n[0].offsetTop?n[0].offsetTop:n[0].offsetParent.offsetTop)-this.textRef.scrollTop-6;t.style.top=`${o}px`,t.style.left=`${e}px`})}}}__init2(){this.handleClick=e=>{const{annotations:t}=this.props,{selectionDetails:n}=this.state;if(n)return;const{id:o,annId:i}=e.target.dataset,s=o||i,a=C(s),r=x(s),l=t.findIndex(e=>e.id===s),d=r.hasAttribute("data-freeform");d&&(r.style.zIndex="10"),this.setState({anchorEl:a[0],openedMenu:!!o||!!i&&!d,openedEditor:!!i&&d,selectedElems:a,labelElem:r,annotationIndex:l,annotation:t[l],selectionDetails:null})}}__init3(){this.handleHover=e=>{const{id:t,annId:n}=e.target.dataset,o=t||n,i=C(o),s=x(o),a=s.hasAttribute("data-freeform");i.forEach(e=>{e.style.zIndex="20",e.classList.contains("positive")?e.style.backgroundColor="rgb(51, 255, 51, 0.7)":e.classList.contains("negative")&&(e.style.backgroundColor="rgba(255, 102, 204, 0.55)")}),a?(s.style.zIndex="20",s.classList.contains("positive")?(s.style.backgroundColor="rgb(128, 255, 128)",s.style.setProperty("--before-border-color","rgb(153, 255, 153)")):s.classList.contains("negative")&&(s.style.backgroundColor="rgb(255, 179, 230)",s.style.setProperty("--before-border-color","rgb(255, 179, 230)"))):(s.style.zIndex="20",s.classList.contains("positive")?s.style.color="rgb(0, 77, 0)":s.classList.contains("negative")&&(s.style.color="rgb(153, 0, 102)"))}}__init4(){this.handleCancelHover=e=>{const{id:t,annId:n}=e.target.dataset,o=t||n,i=C(o),s=x(o),a=s.hasAttribute("data-freeform");i.forEach(e=>{e.style.zIndex="",e.classList.contains("positive")?e.style.backgroundColor="rgb(51, 255, 51, 0.5)":e.classList.contains("negative")&&(e.style.backgroundColor="rgba(255, 102, 204, 0.4)")}),a?(s.style.zIndex="",s.classList.contains("positive")?(s.style.backgroundColor="rgb(153, 255, 153)",s.style.removeProperty("--before-border-color")):s.classList.contains("negative")&&(s.style.backgroundColor="rgb(255, 204, 238)",s.style.removeProperty("--before-border-color"))):(s.style.zIndex="",s.classList.contains("positive")?s.style.color="rgb(0, 128, 0)":s.classList.contains("negative")&&(s.style.color="rgb(204, 0, 136)"))}}__init5(){this.handleClose=e=>{const{selectedElems:t,labelElem:n}=this.state;t.length&&!t[0].hasAttribute("data-id")&&f(t,this.textRef),n&&(n.style.zIndex=""),this.setState({anchorEl:null,openedMenu:!1,openedEditor:!1,selectedElems:[],labelElem:null,selectionDetails:null,annotationIndex:null,annotation:null}),y()}}__init6(){this.handleSelection=e=>{const t=window.getSelection();if(e.detail>2)y();else if(t&&t.rangeCount>0){const e=t.getRangeAt(0),n=e.toString(),o=this.textRef.contains(e.commonAncestorContainer);if(!t.isCollapsed&&""!==n&&o){const t=((e,t)=>{const n=document.createRange();n.setStart(t,0),n.setEnd(e.startContainer,e.startOffset);const[,o]=u(n),[,i]=u(e),s=o.length;return{quote:i,start:s,end:s+i.length}})(e,this.textRef),n=b(e);this.setState({anchorEl:n[0],openedMenu:!0,selectedElems:n,selectionDetails:t})}}}}__init7(){this.deleteAnnotation=()=>{const{annotations:e,onChange:t}=this.props,{selectedElems:n,labelElem:o,annotationIndex:i,annotation:s}=this.state;(v(s.label)?this.labelsRef:n[0]).removeChild(o),f(n,this.textRef),e.splice(i,1),t(e),this.handleClose()}}__init8(){this.createDOMAnnotation=(e,t)=>{const{disabled:n}=this.props,{id:o,label:i,type:s}=t;(e||[]).forEach(e=>{e.dataset.id=o,e.className=`annotation ${s}`,e.style.position="relative",e.style.cursor="pointer","positive"===s?e.style.backgroundColor="rgb(51, 255, 51, 0.5)":"negative"===s&&(e.style.backgroundColor="rgba(255, 102, 204, 0.4)"),e.onclick=!n&&this.handleClick,e.onmouseover=this.handleHover,e.onmouseout=this.handleCancelHover});const a=e&&e[0]||{},r=document.createElement("SPAN");if(r.dataset.annId=o,r.innerHTML=i,r.onclick=!n&&this.handleClick,r.onmouseover=this.handleHover,r.onmouseout=this.handleCancelHover,v(i)){const e=(a.offsetTop?a.offsetTop:a.offsetParent.offsetTop)-this.textRef.scrollTop,t=this.textRef.offsetLeft+this.textRef.offsetWidth+8;r.dataset.freeform=!0,r.className=`sideAnnotation ${s}`,r.style.position="absolute",r.style.padding="4px",r.style.borderRadius="4px",r.style.marginLeft="8px",r.style.width="180px",r.style.whiteSpace="pre-wrap",r.style.wordBreak="break-word",r.style.border="2px solid #ffffff",r.style.fontSize="14px",r.style.fontStyle="normal",r.style.fontWeight="normal",r.style.top=`${e}px`,r.style.left=`${t}px`,"negative"===s?r.style.backgroundColor="rgb(255, 204, 238)":"positive"===s&&(r.style.backgroundColor="rgb(153, 255, 153)"),r.style.setProperty("--before-border-width","7px"),r.style.setProperty("--before-top","5px"),r.style.setProperty("--before-right","100%"),"negative"===s?r.style.setProperty("--before-border-color","rgb(255, 204, 238)"):"positive"===s&&r.style.setProperty("--before-border-color","rgb(153, 255, 153)"),this.labelsRef.appendChild(r)}else r.className=`annotationLabel ${s}`,r.style.backgroundColor="rgb(242, 242, 242)",r.style.padding="2px",r.style.position="absolute",r.style.userSelect="none",r.style.whiteSpace="nowrap",r.style.top="-10px",r.style.left="-2px",r.style.fontSize="12px",r.style.fontStyle="normal",r.style.fontWeight="normal",r.style.lineHeight="6px",r.style.webkitUserSelect="none",r.style.mozUserSelect="none",r.style.msUserSelect="none","positive"===s?r.style.color="rgb(0, 128, 0)":"negative"===s&&(r.style.color="rgb(204, 0, 136)"),a.appendChild(r)}}__init9(){this.createNewAnnotation=(e,t)=>{const{selectedElems:n,selectionDetails:o}=this.state,i={id:[o.start,o.end,(new Date).getTime()].join("-"),label:e,type:t,...o};return this.createDOMAnnotation(n,i),i}}__init10(){this.handleMenuClick=e=>{const{annotations:t,onChange:n}=this.props,{annotation:o,annotationIndex:i}=this.state,{type:s,text:a}=e;if(o){const e={...o,label:a,type:s},{type:n,label:r}=o;this.updateLabel(r,e,s!==n&&n),t.splice(i,1,e)}else{const e=this.createNewAnnotation(a,s);t.push(e)}n(t),this.handleClose()}}__init11(){this.editAnnotation=()=>{this.setState({openedMenu:!1,openedEditor:!0})}}__init12(){this.addAnnotation=e=>{const{annotations:t,onChange:n}=this.props,o=this.createNewAnnotation("",e),i=x(o.id);t.push(o),this.setState({openedMenu:!1,openedEditor:!0,annotationIndex:t.length-1,annotation:o,labelElem:i}),n(t)}}__init13(){this.updateLabel=(e,t,n)=>{const{selectedElems:o,labelElem:i}=this.state,{label:s,type:a}=t;v(s)&&v(e)||!v(s)&&!v(e)?(i.innerHTML=s,n&&(i.classList.remove(n),i.classList.add(a),o.forEach(e=>{e.classList.remove(n),e.classList.add(a)}))):v(s)&&!v(e)?(o[0].removeChild(i),this.createDOMAnnotation(o,t)):!v(s)&&v(e)&&(this.labelsRef.removeChild(i),this.createDOMAnnotation(o,t))}}__init14(){this.changeAnnotationType=e=>{const{annotations:t,onChange:n}=this.props,{annotationIndex:o,selectedElems:i}=this.state,{type:s,label:a}=t[o],r="positive"===s?"negative":"positive",l={...t[o],type:r,label:e};i.forEach(e=>{e.classList.remove(s),e.classList.add(r)}),this.updateLabel(a,l,s),t.splice(o,1,l),n(t),this.handleClose()}}__init15(){this.updateAnnotation=(e,t)=>{const{annotations:n,onChange:o}=this.props,{annotationIndex:i}=this.state,s={...n[i],label:t};this.updateLabel(e,s),n.splice(i,1,s),o(n)}}componentWillUnmount(){this.textRef.removeEventListener("scroll",this.adjustAnnotationsPosition)}render(){const{comment:e,customKeys:t,disabled:n,disabledMath:o,keypadMode:i,height:s,width:a,maxHeight:r,onCommentChange:l,predefinedAnnotations:d,text:c}=this.props,{anchorEl:p,annotation:h,openedMenu:m,openedEditor:u,selectionDetails:g}=this.state,b=p&&(p.offsetTop?p.offsetTop:p.offsetParent.offsetTop),f=this.textRef&&b?b-this.textRef.scrollTop-8:0;return q.createElement("div",null,q.createElement(X,null,q.createElement(F,{style:{width:a-34,minHeight:s,maxHeight:r},ref:e=>this.textRef=e,onMouseDown:n?()=>{}:y,onMouseUp:n?()=>{}:this.handleSelection,dangerouslySetInnerHTML:{__html:c}}),q.createElement(G,{ref:e=>this.labelsRef=e})),q.createElement(Y,{label:"Comment"},q.createElement(U,{className:"prompt",markup:e||"",onChange:l,width:a&&(a+104).toString(),disabled:n,pluginProps:{math:{disabled:o,customKeys:t,keypadMode:i,controlledKeypadMode:!1},video:{disabled:!0},audio:{disabled:!0},textAlign:{disabled:!0}}})),q.createElement(j,{anchorEl:p,open:m&&!n,annotations:d,isNewAnnotation:!!g,onClose:this.handleClose,onDelete:this.deleteAnnotation,onEdit:this.editAnnotation,onWrite:this.addAnnotation,onAnnotate:this.handleMenuClick}),q.createElement(M,{anchorEl:this.textRef,open:u&&!n,offset:f,value:h&&h.label||"",type:h&&h.type,onClose:this.handleClose,onDelete:this.deleteAnnotation,onSave:this.updateAnnotation,onTypeChange:this.changeAnnotationType}))}}Q.__initStatic();const J=t,Z=n,{debounce:ee}=s,te=a,{Typography:ne}=o,{styled:oe}=i,{color:ie}=r,{Feedback:se}=r,{Collapsible:ae}=r,{PreviewPrompt:re}=r,{UiLayout:le}=r,de=d,ce=te("@pie-ui:extended-text-entry"),pe=oe(le)({backgroundColor:ie.background(),color:ie.text()}),he=oe(ne)(({theme:e})=>({width:"100%",color:ie.text(),marginBottom:e.spacing(2),fontSize:"inherit"})),me=oe("div")(({theme:e})=>({marginBottom:e.spacing(2)})),ue=oe(de)(({theme:e})=>({marginBottom:e.spacing(2),borderRadius:"4px"})),ge=oe("h2")({position:"absolute",left:"-10000px",top:"auto",width:"1px",height:"1px",overflow:"hidden"});class be extends J.Component{constructor(...e){super(...e),be.prototype.__init.call(this),be.prototype.__init2.call(this)}static __initStatic(){this.propTypes={onValueChange:Z.func.isRequired,onAnnotationsChange:Z.func.isRequired,onCommentChange:Z.func.isRequired,model:Z.object,session:Z.shape({value:Z.string,annotations:Z.array,comment:Z.string}).isRequired}}__init(){this.changeSessionValue=ee(this.props.onValueChange,1500)}__init2(){this.changeSessionComment=ee(this.props.onCommentChange,1500)}render(){const{model:e,session:t,onAnnotationsChange:n}=this.props,{animationsDisabled:o,annotatorMode:i,customKeys:s,dimensions:a,disabled:r,disabledAnnotator:l,equationEditor:d,extraCSSRules:c,feedback:p,mathInput:h,playersToolbarPosition:m,predefinedAnnotations:u,prompt:g,spanishInput:b,specialInput:f,spellCheckEnabled:y,teacherInstructions:v}=e,{annotations:C,comment:x,value:_}=t,{width:E,height:w}=a||{},S="40vh",k={position:"top"===m?"top":"bottom"};ce("[render] disabled? ",r);const A=J.createElement(re,{defaultClassName:"teacher-instructions",prompt:v}),R=[];return b&&R.push({language:"spanish"}),f&&R.push({language:"special"}),J.createElement(pe,{extraCSSRules:c,ref:e=>{this.containerRef=e}},J.createElement(ge,null,"Constructed Response Question"),v&&J.createElement(me,null,o?A:J.createElement(ae,{labels:{hidden:"Show Teacher Instructions",visible:"Hide Teacher Instructions"}},A)),g&&J.createElement(he,{component:"span"},J.createElement(re,{defaultClassName:"prompt",prompt:e.prompt})),i?J.createElement(Q,{text:_||"",annotations:C||[],comment:x||"",predefinedAnnotations:u||[],onChange:n,onCommentChange:this.changeSessionComment,width:E,height:w,maxHeight:S,disabled:l,disabledMath:!h,customKeys:s,keypadMode:d}):J.createElement(ue,{className:"response-area-editor",onChange:this.changeSessionValue,markup:_||"",maxWidth:E&&E.toString(),minWidth:"100px",minHeight:w&&w.toString(),maxHeight:S,disabled:r,highlightShape:!0,toolbarOpts:k,spellCheck:y,charactersLimit:5e4,autoWidthToolbar:!0,pluginProps:{math:{disabled:!h,customKeys:this.props.model.customKeys,keypadMode:this.props.model.equationEditor,controlledKeypadMode:!1},video:{disabled:!0},audio:{disabled:!0},table:{disabled:!0},textAlign:{disabled:!0},separateParagraphs:{disabled:!1},ul_list:{disabled:!0},ol_list:{disabled:!0}},languageCharactersProps:R}),p&&J.createElement(se,{correctness:"correct",feedback:p}))}}be.__initStatic();const fe=t,{debounce:ye}=s,ve=a,{renderMath:Ce}=l,xe=ve("pie-element:extended-text-entry:print");class _e extends HTMLElement{constructor(){super(),this._options=null,this._model=null,this._session=[],this._root=null,this._rerender=ye(()=>{if(this._model&&this._session){const e=((e,t)=>{const n="instructor"===t.role;return e.prompt=!1!==e.promptEnabled?e.prompt:void 0,e.teacherInstructions=n&&!1!==e.teacherInstructionsEnabled?e.teacherInstructions:void 0,e.showTeacherInstructions=n,e.mode=n?"evaluate":e.mode,e.dimensions={height:100,width:500,...e.dimensions},e.disabled=!0,e.feedback=void 0,e.animationsDisabled=!0,e})(this._model,this._options),t=this._options&&fe.createElement(be,{model:e,session:{},onChange:()=>{},onValueChange:()=>{},onAnnotationsChange:()=>{},onCommentChange:()=>{}});this._root||(this._root=p(this)),this._root.render(t),queueMicrotask(()=>{xe("render complete - render math"),Ce(this)})}else xe("skip")},50,{leading:!1,trailing:!0})}set options(e){this._options=e}set model(e){this._model=e,this._rerender()}connectedCallback(){}disconnectedCallback(){this._root&&this._root.unmount()}}export{_e as default};
|