@teipublisher/pb-components 1.28.2 → 1.30.2

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.
@@ -9743,6 +9743,11 @@
9743
9743
  "type": "boolean",
9744
9744
  "default": "false"
9745
9745
  },
9746
+ {
9747
+ "name": "before-update-event",
9748
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
9749
+ "type": "string"
9750
+ },
9746
9751
  {
9747
9752
  "name": "subscribe",
9748
9753
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -9932,6 +9937,12 @@
9932
9937
  "type": "boolean",
9933
9938
  "default": "false"
9934
9939
  },
9940
+ {
9941
+ "name": "beforeUpdate",
9942
+ "attribute": "before-update-event",
9943
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
9944
+ "type": "string"
9945
+ },
9935
9946
  {
9936
9947
  "name": "subscribe",
9937
9948
  "attribute": "subscribe",
@@ -10183,6 +10194,11 @@
10183
10194
  "type": "boolean",
10184
10195
  "default": "false"
10185
10196
  },
10197
+ {
10198
+ "name": "before-update-event",
10199
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
10200
+ "type": "string"
10201
+ },
10186
10202
  {
10187
10203
  "name": "subscribe",
10188
10204
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -10355,6 +10371,12 @@
10355
10371
  "type": "boolean",
10356
10372
  "default": "false"
10357
10373
  },
10374
+ {
10375
+ "name": "beforeUpdate",
10376
+ "attribute": "before-update-event",
10377
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
10378
+ "type": "string"
10379
+ },
10358
10380
  {
10359
10381
  "name": "subscribe",
10360
10382
  "attribute": "subscribe",
@@ -12,7 +12,7 @@ import{h as e,o as t,F as o,D as i,E as s,H as r,l as a,f as n,t as d,g as l}fro
12
12
  * subject to an additional IP rights grant found at
13
13
  * http://polymer.github.io/PATENTS.txt
14
14
  */
15
- const S=(e,t)=>{const o=e.startNode.parentNode,i=void 0===t?e.endNode:t.startNode,s=o.insertBefore(g(),i);o.insertBefore(g(),i);const r=new b(e.options);return r.insertAfterNode(s),r},C=(e,t)=>(e.setValue(t),e.commit(),e),k=(e,t,o)=>{const i=e.startNode.parentNode,s=o?o.startNode:e.endNode,r=t.endNode.nextSibling;r!==s&&v(i,t.startNode,r,s)},A=e=>{f(e.startNode.parentNode,e.startNode,e.endNode.nextSibling)},M=(e,t,o)=>{const i=new Map;for(let s=t;s<=o;s++)i.set(e[s],s);return i},R=new WeakMap,I=new WeakMap,B=u((e,t,o)=>{let i;return void 0===o?o=t:void 0!==t&&(i=t),t=>{if(!(t instanceof b))throw new Error("repeat can only be used in text bindings");const s=R.get(t)||[],r=I.get(t)||[],a=[],n=[],d=[];let l,c,p=0;for(const t of e)d[p]=i?i(t,p):p,n[p]=o(t,p),p++;let h=0,m=s.length-1,u=0,g=n.length-1;for(;h<=m&&u<=g;)if(null===s[h])h++;else if(null===s[m])m--;else if(r[h]===d[u])a[u]=C(s[h],n[u]),h++,u++;else if(r[m]===d[g])a[g]=C(s[m],n[g]),m--,g--;else if(r[h]===d[g])a[g]=C(s[h],n[g]),k(t,s[h],a[g+1]),h++,g--;else if(r[m]===d[u])a[u]=C(s[m],n[u]),k(t,s[m],s[h]),m--,u++;else if(void 0===l&&(l=M(d,u,g),c=M(r,h,m)),l.has(r[h]))if(l.has(r[m])){const e=c.get(d[u]),o=void 0!==e?s[e]:null;if(null===o){const e=S(t,s[h]);C(e,n[u]),a[u]=e}else a[u]=C(o,n[u]),k(t,o,s[h]),s[e]=null;u++}else A(s[m]),m--;else A(s[h]),h++;for(;u<=g;){const e=S(t,a[g+1]);C(e,n[u]),a[u++]=e}for(;h<=m;){const e=s[h++];null!==e&&A(e)}R.set(t,a),I.set(t,d)}}),P=new WeakMap,T=u(e=>t=>{const o=P.get(t);if(void 0===e&&t instanceof w){if(void 0!==o||!P.has(t)){const e=t.committer.name;t.committer.element.removeAttribute(e)}}else e!==o&&t.setValue(e);P.set(t,e)}),z=e`<dom-module id="lumo-tab" theme-for="vaadin-tab">
15
+ const S=(e,t)=>{const o=e.startNode.parentNode,i=void 0===t?e.endNode:t.startNode,s=o.insertBefore(g(),i);o.insertBefore(g(),i);const r=new b(e.options);return r.insertAfterNode(s),r},C=(e,t)=>(e.setValue(t),e.commit(),e),k=(e,t,o)=>{const i=e.startNode.parentNode,s=o?o.startNode:e.endNode,r=t.endNode.nextSibling;r!==s&&v(i,t.startNode,r,s)},A=e=>{f(e.startNode.parentNode,e.startNode,e.endNode.nextSibling)},M=(e,t,o)=>{const i=new Map;for(let s=t;s<=o;s++)i.set(e[s],s);return i},R=new WeakMap,I=new WeakMap,B=u((e,t,o)=>{let i;return void 0===o?o=t:void 0!==t&&(i=t),t=>{if(!(t instanceof b))throw new Error("repeat can only be used in text bindings");const s=R.get(t)||[],r=I.get(t)||[],a=[],n=[],d=[];let l,c,p=0;for(const t of e)d[p]=i?i(t,p):p,n[p]=o(t,p),p++;let h=0,m=s.length-1,u=0,g=n.length-1;for(;h<=m&&u<=g;)if(null===s[h])h++;else if(null===s[m])m--;else if(r[h]===d[u])a[u]=C(s[h],n[u]),h++,u++;else if(r[m]===d[g])a[g]=C(s[m],n[g]),m--,g--;else if(r[h]===d[g])a[g]=C(s[h],n[g]),k(t,s[h],a[g+1]),h++,g--;else if(r[m]===d[u])a[u]=C(s[m],n[u]),k(t,s[m],s[h]),m--,u++;else if(void 0===l&&(l=M(d,u,g),c=M(r,h,m)),l.has(r[h]))if(l.has(r[m])){const e=c.get(d[u]),o=void 0!==e?s[e]:null;if(null===o){const e=S(t,s[h]);C(e,n[u]),a[u]=e}else a[u]=C(o,n[u]),k(t,o,s[h]),s[e]=null;u++}else A(s[m]),m--;else A(s[h]),h++;for(;u<=g;){const e=S(t,a[g+1]);C(e,n[u]),a[u++]=e}for(;h<=m;){const e=s[h++];null!==e&&A(e)}R.set(t,a),I.set(t,d)}}),P=new WeakMap,z=u(e=>t=>{const o=P.get(t);if(void 0===e&&t instanceof w){if(void 0!==o||!P.has(t)){const e=t.committer.name;t.committer.element.removeAttribute(e)}}else e!==o&&t.setValue(e);P.set(t,e)}),T=e`<dom-module id="lumo-tab" theme-for="vaadin-tab">
16
16
  <template>
17
17
  <style>
18
18
  :host {
@@ -234,7 +234,7 @@ const S=(e,t)=>{const o=e.startNode.parentNode,i=void 0===t?e.endNode:t.startNod
234
234
  }
235
235
  </style>
236
236
  </template>
237
- </dom-module>`;document.head.appendChild(z.content);
237
+ </dom-module>`;document.head.appendChild(T.content);
238
238
  /**
239
239
  @license
240
240
  Copyright (c) 2017 Vaadin Ltd.
@@ -645,7 +645,7 @@ This program is available under Apache License Version 2.0, available at https:/
645
645
  code="${this.value}"
646
646
  linter="${this.endpoint}/${$(this.apiVersion,"1.0.0")?"modules/editor.xql":"api/lint"}"
647
647
  apiVersion="${this.apiVersion}"></pb-code-editor>
648
- <paper-checkbox id="set" ?checked="${this.setParam}" @change="${this._handleCodeChange}">set</paper-checkbox>
648
+ <paper-checkbox id="set" ?checked="${this.setParam}" @change="${this._handleCodeChange}">${d("odd.editor.model.set-param")}</paper-checkbox>
649
649
  <paper-icon-button @click="${this._delete}" icon="delete" title="delete this parameter"></paper-icon-button>
650
650
  </div>
651
651
 
@@ -830,6 +830,16 @@ This program is available under Apache License Version 2.0, available at https:/
830
830
  pb-code-editor {
831
831
  margin-bottom: 20px;
832
832
  }
833
+
834
+ .horizontal {
835
+ display: flex;
836
+ flex-wrap: wrap;
837
+ justify-content: space-between;
838
+ }
839
+
840
+ #mode {
841
+ min-width: 18em;
842
+ }
833
843
  `}static get properties(){return{behaviour:{type:String},predicate:{type:String,reflect:!0,converter:(e,t)=>"null"===e.toLowerCase()?"":e},type:{type:String,reflect:!0},template:{type:String,reflect:!0,converter:(e,t)=>"null"===e.toLowerCase()?"":e},output:{type:String,reflect:!0,converter:(e,t)=>"null"===e.toLowerCase()?"":e},css:{type:String,converter:(e,t)=>"null"===e.toLowerCase()?"":e},mode:{type:String},model:{type:Object},models:{type:Array},parameters:{type:Array},renditions:{type:Array},desc:{type:String,converter:(e,t)=>"null"===e.toLowerCase()?"":e},sourcerend:{type:String},show:{type:Boolean,reflect:!0},outputs:{type:Array},behaviours:{type:Array},icon:{type:String},open:{type:String},hasCustomBehaviour:{type:Boolean},endpoint:{type:String},apiVersion:{type:String}}}constructor(){super(),this.behaviour="inline",this.predicate="",this.type="",this.template="",this.output="",this.css="",this.mode="",this.model={},this.model.models=[],this.parameters=[],this.renditions=[],this.desc="",this.sourcerend="",this.show=!1,this.outputs=["","web","print","epub","fo","latex","plain"],this.parentModel=[],this.behaviours=["alternate","anchor","block","body","break","cell","cit","document","figure","graphic","heading","inline","link","list","listItem","metadata","note","omit","paragraph","pass-through","row","section","table","text","title","webcomponent"],this.icon="expand-more",this.hasCustomBehaviour=!1}render(){return x`
834
844
  <form>
835
845
  <header>
@@ -874,17 +884,22 @@ This program is available under Apache License Version 2.0, available at https:/
874
884
  </p>
875
885
  </header>
876
886
  <iron-collapse id="details" ?opened="${this.show}" class="details">
877
- <paper-dropdown-menu class="selectOutput" label="Output">
878
- <paper-listbox id="output" slot="dropdown-content" attr-for-selected="value"
879
- selected="${this.output}" @iron-select="${this._selectOutput}">
887
+ <div class="horizontal">
888
+ <paper-dropdown-menu class="selectOutput" label="Output">
889
+ <paper-listbox id="output" slot="dropdown-content" attr-for-selected="value"
890
+ selected="${this.output}" @iron-select="${this._selectOutput}">
880
891
 
881
- ${this.outputs.map(e=>x`
882
- <paper-item value="${e}">${e}</paper-item>
883
- `)}
884
-
885
- </paper-listbox>
886
- </paper-dropdown-menu>
892
+ ${this.outputs.map(e=>x`
893
+ <paper-item value="${e}">${e}</paper-item>
894
+ `)}
887
895
 
896
+ </paper-listbox>
897
+ </paper-dropdown-menu>
898
+ <paper-input id="mode" .value="${this.mode}"
899
+ placeholder="${d("odd.editor.model.mode-placeholder")}"
900
+ label="Mode"
901
+ @change="${this._inputMode}"></paper-input>
902
+ </div>
888
903
  <paper-input id="desc" .value="${this.desc}" placeholder="${d("odd.editor.model.description-placeholder")}"
889
904
  label="Description" @change="${this._inputDesc}"></paper-input>
890
905
 
@@ -919,11 +934,6 @@ This program is available under Apache License Version 2.0, available at https:/
919
934
  placeholder="${d("odd.editor.model.css-class-placeholder")}"
920
935
  label="CSS Class"
921
936
  @change="${this._inputCss}"></paper-input>
922
-
923
- <paper-input id="mode" .value="${this.mode}"
924
- placeholder="${d("odd.editor.model.mode-placeholder")}"
925
- label="Mode"
926
- @change="${this._inputMode}"></paper-input>
927
937
 
928
938
  <pb-code-editor id="template"
929
939
  code="${this.template}"
@@ -1007,7 +1017,7 @@ This program is available under Apache License Version 2.0, available at https:/
1007
1017
  </div>
1008
1018
  </form>
1009
1019
  <pb-message id="dialog"></pb-message>
1010
- `}firstUpdated(){super.firstUpdated(),this.hasCustomBehaviour=this.behaviours.indexOf(this.behaviour)<0,this.hasCustomBehaviour&&(this.shadowRoot.getElementById("custombehaviour").value=this.behaviour)}updated(e){e.has("show")&&this.show&&this.refreshEditors()}refreshEditors(){if(console.log("refreshEditors"),this.shadowRoot.getElementById("predicate").refresh(),this._isGroupOrSequence())return console.log("asfdfa");this.shadowRoot.getElementById("template").refresh();const e=this.shadowRoot.querySelectorAll("pb-odd-model-editor");for(let t=0;t<e.length;t++)e[t].refreshEditors();const t=this.shadowRoot.querySelectorAll("pb-odd-rendition-editor");for(let e=0;e<t.length;e++)t[e].refreshEditor();const o=this.shadowRoot.querySelectorAll("pb-odd-parameter-editor");for(let e=0;e<o.length;e++)o[e].refreshEditor()}toggle(e){this.show=!this.show,this.toggleButtonIcon();const t=this.model,o=Object.assign({},t,{show:this.show});this.model=o,this.refreshEditors(),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:t,newModel:o}}))}toggleButtonIcon(){this.show?this.icon="expand-less":this.icon="expand-more"}_isModel(){return"model"===this.type}_isGroupOrSequence(){return"model"!==this.type}static _templateMode(e){switch(e){case"latex":return"latex";case"web":default:return"xml"}}_changeSelection(e){if(e.detail.target==this)return;e.preventDefault(),e.stopPropagation(),null!=this.currentSelection&&this.currentSelection.removeAttribute("currentselection");const t=e.detail.target;t.setAttribute("currentselection","true"),this.currentSelection=t}_requestRemoval(e){e.preventDefault(),this.dispatchEvent(new CustomEvent("model-remove"))}_moveDown(e){e.preventDefault(),e.stopPropagation(),this.dispatchEvent(new CustomEvent("model-move-down",{composed:!0,bubbles:!0,detail:{model:this}}))}_moveUp(e){e.preventDefault(),e.stopPropagation(),this.dispatchEvent(new CustomEvent("model-move-up"))}_addNested(e){const t={behaviour:"inline",css:"",desc:"",predicate:"",type:e.detail.item.getAttribute("value"),output:"",sourcerend:!1,models:[],parameters:[],renditions:[],template:"",show:!0},o=this.model,i=Array.from(this.model.models);i.unshift(t),this.model=Object.assign({},o,{models:i});this.shadowRoot.querySelector("#modelType").select(""),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:o,newModel:this.model}}))}_removeModel(e){console.log("_removeModel ",e),e.stopPropagation();const{model:t}=e.target,o=this.model.models.indexOf(t);this.shadowRoot.getElementById("dialog").confirm(l("odd.editor.model.delete-model-label"),l("odd.editor.model.delete-model-message")).then(()=>{const e=this.model,t=Array.from(this.model.models);t.splice(o,1),this.model=Object.assign({},e,{models:t}),this.models=t,this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:e,newModel:this.model}}))},()=>null)}_moveModelDown(e){console.log("MODEL._moveModelDown ",e),e.stopPropagation();const{model:t}=e.target,o=this.model.models.indexOf(t);if(o===this.model.models.length)return;const i=this.model,s=Array.from(this.model.models);s.splice(o,1),s.splice(o+1,0,t),this.model=Object.assign({},i,{models:s});const r=this.shadowRoot.querySelectorAll("pb-odd-model-editor")[o+1];this._setCurrentSelection(o+1,r),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:i,newModel:this.model}})),this.requestUpdate()}_moveModelUp(e){e.stopPropagation();const{model:t}=e.target,o=this.model.models.indexOf(t);if(0===o)return;const i=this.model,s=Array.from(this.model.models);s.splice(o,1),s.splice(o-1,0,t),this.model=Object.assign({},i,{models:s});const r=this.shadowRoot.querySelectorAll("pb-odd-model-editor")[o-1];this._setCurrentSelection(o-1,r),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:i,newModel:this.model}}))}handleModelChanged(e){console.log("handleModelChanged ",e,this),e.stopPropagation();const t=this.model,o=this.model.models.indexOf(e.detail.oldModel),i=Array.from(this.model.models);i.splice(o,1,e.detail.newModel),this.model=Object.assign({},t,{models:i}),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:t,newModel:this.model}}))}setCurrentSelection(e,t){e.preventDefault(),e.stopPropagation(),this._setCurrentSelection(t,e.target)}_setCurrentSelection(e,t){const o=this.shadowRoot.querySelectorAll("pb-odd-model-editor")[e];o&&(o.hasAttribute("currentselection")||(this.dispatchEvent(new CustomEvent("current-changed",{composed:!0,bubbles:!0,detail:{target:t}})),this.requestUpdate()))}_inputDesc(e){this.desc=e.composedPath()[0].value,this._fireModelChanged("desc",this.desc)}_selectOutput(e){this.output=e.composedPath()[0].selected,this._fireModelChanged("output",this.output)}_updatePredicate(e){this.predicate=this.shadowRoot.getElementById("predicate").getSource(),console.log("_updatePredicate ",this.predicate),this._fireModelChanged("predicate",this.predicate)}_selectBehaviour(e){this.behaviour=e.composedPath()[0].selected,this._fireModelChanged("behaviour",this.behaviour)}_inputCss(e){this.css=e.composedPath()[0].value,this._fireModelChanged("css",this.css)}_inputMode(e){this.mode=e.composedPath()[0].value,this._fireModelChanged("mode",this.mode)}_updateTemplate(e){this.template=this.shadowRoot.getElementById("template").getSource(),this._fireModelChanged("template",this.template)}_addParameter(e){this.parameters.push({name:"",value:""}),this._fireModelChanged("parameters",this.parameters)}_updateParam(e,t){this.parameters[t].name=e.detail.name,this.parameters[t].value=e.detail.value,this.parameters[t].set=e.detail.set,this._fireModelChanged("parameters",this.parameters)}_removeParam(e,t){this.parameters.splice(t,1),this._fireModelChanged("parameters",this.parameters)}_addRendition(e){this.renditions.push({scope:"",css:""}),this._fireModelChanged("renditions",this.renditions)}_updateRendition(e,t){this.renditions[t].css=e.detail.css,this.renditions[t].scope=e.detail.scope,this._fireModelChanged("renditions",this.renditions)}_removeRendition(e,t){this.renditions.splice(t,1),this._fireModelChanged("renditions",this.renditions)}_fireModelChanged(e,t){const o=this.model;this.model=Object.assign({},this.model,{[e]:t}),console.log("model changed for %s: %o - %o",e,t,this.model),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:o,newModel:this.model}})),this.requestUpdate()}_copy(e){e.preventDefault(),e.stopPropagation(),console.log("odd-model.copy ",e),console.log("odd-model.copy data",this.model),this.dispatchEvent(new CustomEvent("odd-copy",{composed:!0,bubbles:!0,detail:{model:this.model}}))}_paste(e){console.log("model _paste ",e),this.dispatchEvent(new CustomEvent("odd-paste",{composed:!0,bubbles:!0,detail:{target:this}}))}_handleCustomBehaviour(e){this.behaviour=e.composedPath()[0].value,this._fireModelChanged("behaviour",this.behaviour),""===this.behaviour?(this.behaviour="inline",this.hasCustomBehaviour=!1):this.hasCustomBehaviour=!0,this.requestUpdate()}}customElements.define("pb-odd-model-editor",F);class H extends y{static get styles(){return _`
1020
+ `}firstUpdated(){super.firstUpdated(),this.hasCustomBehaviour=this.behaviours.indexOf(this.behaviour)<0,this.hasCustomBehaviour&&(this.shadowRoot.getElementById("custombehaviour").value=this.behaviour)}updated(e){e.has("show")&&this.show&&this.refreshEditors()}refreshEditors(){if(console.log("refreshEditors"),this.shadowRoot.getElementById("predicate").refresh(),this._isGroupOrSequence())return console.log("asfdfa");this.shadowRoot.getElementById("template").refresh();const e=this.shadowRoot.querySelectorAll("pb-odd-model-editor");for(let t=0;t<e.length;t++)e[t].refreshEditors();const t=this.shadowRoot.querySelectorAll("pb-odd-rendition-editor");for(let e=0;e<t.length;e++)t[e].refreshEditor();const o=this.shadowRoot.querySelectorAll("pb-odd-parameter-editor");for(let e=0;e<o.length;e++)o[e].refreshEditor()}toggle(e){this.show=!this.show,this.toggleButtonIcon();const t=this.model,o=Object.assign({},t,{show:this.show});this.model=o,this.refreshEditors(),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:t,newModel:o}}))}toggleButtonIcon(){this.show?this.icon="expand-less":this.icon="expand-more"}_isModel(){return"model"===this.type}_isGroupOrSequence(){return"model"!==this.type}static _templateMode(e){switch(e){case"latex":return"latex";case"web":default:return"xml"}}_changeSelection(e){if(e.detail.target==this)return;e.preventDefault(),e.stopPropagation(),null!=this.currentSelection&&this.currentSelection.removeAttribute("currentselection");const t=e.detail.target;t.setAttribute("currentselection","true"),this.currentSelection=t}_requestRemoval(e){e.preventDefault(),this.dispatchEvent(new CustomEvent("model-remove"))}_moveDown(e){e.preventDefault(),e.stopPropagation(),this.dispatchEvent(new CustomEvent("model-move-down",{composed:!0,bubbles:!0,detail:{model:this}}))}_moveUp(e){e.preventDefault(),e.stopPropagation(),this.dispatchEvent(new CustomEvent("model-move-up"))}_addNested(e){const t={behaviour:"inline",css:"",desc:"",predicate:"",type:e.detail.item.getAttribute("value"),output:"",sourcerend:!1,models:[],mode:"",parameters:[],renditions:[],template:"",show:!0},o=this.model,i=Array.from(this.model.models);i.unshift(t),this.model=Object.assign({},o,{models:i});this.shadowRoot.querySelector("#modelType").select(""),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:o,newModel:this.model}}))}_removeModel(e){console.log("_removeModel ",e),e.stopPropagation();const{model:t}=e.target,o=this.model.models.indexOf(t);this.shadowRoot.getElementById("dialog").confirm(l("odd.editor.model.delete-model-label"),l("odd.editor.model.delete-model-message")).then(()=>{const e=this.model,t=Array.from(this.model.models);t.splice(o,1),this.model=Object.assign({},e,{models:t}),this.models=t,this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:e,newModel:this.model}}))},()=>null)}_moveModelDown(e){console.log("MODEL._moveModelDown ",e),e.stopPropagation();const{model:t}=e.target,o=this.model.models.indexOf(t);if(o===this.model.models.length)return;const i=this.model,s=Array.from(this.model.models);s.splice(o,1),s.splice(o+1,0,t),this.model=Object.assign({},i,{models:s});const r=this.shadowRoot.querySelectorAll("pb-odd-model-editor")[o+1];this._setCurrentSelection(o+1,r),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:i,newModel:this.model}})),this.requestUpdate()}_moveModelUp(e){e.stopPropagation();const{model:t}=e.target,o=this.model.models.indexOf(t);if(0===o)return;const i=this.model,s=Array.from(this.model.models);s.splice(o,1),s.splice(o-1,0,t),this.model=Object.assign({},i,{models:s});const r=this.shadowRoot.querySelectorAll("pb-odd-model-editor")[o-1];this._setCurrentSelection(o-1,r),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:i,newModel:this.model}}))}handleModelChanged(e){console.log("handleModelChanged ",e,this),e.stopPropagation();const t=this.model,o=this.model.models.indexOf(e.detail.oldModel),i=Array.from(this.model.models);i.splice(o,1,e.detail.newModel),this.model=Object.assign({},t,{models:i}),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:t,newModel:this.model}}))}setCurrentSelection(e,t){e.preventDefault(),e.stopPropagation(),this._setCurrentSelection(t,e.target)}_setCurrentSelection(e,t){const o=this.shadowRoot.querySelectorAll("pb-odd-model-editor")[e];o&&(o.hasAttribute("currentselection")||(this.dispatchEvent(new CustomEvent("current-changed",{composed:!0,bubbles:!0,detail:{target:t}})),this.requestUpdate()))}_inputDesc(e){this.desc=e.composedPath()[0].value,this._fireModelChanged("desc",this.desc)}_selectOutput(e){this.output=e.composedPath()[0].selected,this._fireModelChanged("output",this.output)}_updatePredicate(e){this.predicate=this.shadowRoot.getElementById("predicate").getSource(),console.log("_updatePredicate ",this.predicate),this._fireModelChanged("predicate",this.predicate)}_selectBehaviour(e){this.behaviour=e.composedPath()[0].selected,this._fireModelChanged("behaviour",this.behaviour)}_inputCss(e){this.css=e.composedPath()[0].value,this._fireModelChanged("css",this.css)}_inputMode(e){this.mode=e.composedPath()[0].value,this._fireModelChanged("mode",this.mode)}_updateTemplate(e){this.template=this.shadowRoot.getElementById("template").getSource(),this._fireModelChanged("template",this.template)}_addParameter(e){this.parameters.push({name:"",value:""}),this._fireModelChanged("parameters",this.parameters)}_updateParam(e,t){this.parameters[t].name=e.detail.name,this.parameters[t].value=e.detail.value,this.parameters[t].set=e.detail.set,this._fireModelChanged("parameters",this.parameters)}_removeParam(e,t){this.parameters.splice(t,1),this._fireModelChanged("parameters",this.parameters)}_addRendition(e){this.renditions.push({scope:"",css:""}),this._fireModelChanged("renditions",this.renditions)}_updateRendition(e,t){this.renditions[t].css=e.detail.css,this.renditions[t].scope=e.detail.scope,this._fireModelChanged("renditions",this.renditions)}_removeRendition(e,t){this.renditions.splice(t,1),this._fireModelChanged("renditions",this.renditions)}_fireModelChanged(e,t){const o=this.model;this.model=Object.assign({},this.model,{[e]:t}),console.log("model changed for %s: %o - %o",e,t,this.model),this.dispatchEvent(new CustomEvent("model-changed",{composed:!0,bubbles:!0,detail:{oldModel:o,newModel:this.model}})),this.requestUpdate()}_copy(e){e.preventDefault(),e.stopPropagation(),console.log("odd-model.copy ",e),console.log("odd-model.copy data",this.model),this.dispatchEvent(new CustomEvent("odd-copy",{composed:!0,bubbles:!0,detail:{model:this.model}}))}_paste(e){console.log("model _paste ",e),this.dispatchEvent(new CustomEvent("odd-paste",{composed:!0,bubbles:!0,detail:{target:this}}))}_handleCustomBehaviour(e){this.behaviour=e.composedPath()[0].value,this._fireModelChanged("behaviour",this.behaviour),""===this.behaviour?(this.behaviour="inline",this.hasCustomBehaviour=!1):this.hasCustomBehaviour=!0,this.requestUpdate()}}customElements.define("pb-odd-model-editor",F);class H extends y{static get styles(){return _`
1011
1021
  :host {
1012
1022
  display: block;
1013
1023
  padding: 4px 10px;
@@ -1325,7 +1335,7 @@ This program is available under Apache License Version 2.0, available at https:/
1325
1335
  <paper-input id="titleShort" name="short-title" .value="${this.titleShort}" label="${d("odd.editor.title-short")}"
1326
1336
  placeholder="[${d("odd.editor.title-short-placeholder")}]"
1327
1337
  @change="${e=>this.titleShort=e.composedPath()[0].value}"></paper-input>
1328
- <paper-input id="description" name="description" .value="${T(this.description)}" label="${d("odd.editor.description-label")}"
1338
+ <paper-input id="description" name="description" .value="${z(this.description)}" label="${d("odd.editor.description-label")}"
1329
1339
  placeholder="[${d("odd.editor.description-placeholder")}]"
1330
1340
  @change="${e=>this.description=e.composedPath()[0].value}"></paper-input>
1331
1341
  <paper-input id="source" name="source" ?value="${this.source}" label="${d("odd.editor.source-label")}"
@@ -162,7 +162,9 @@
162
162
  "custom-behaviour-placeholder": "[Selbstdefiniertes Behaviour]",
163
163
  "template-placeholder": "[Code Vorlage für den Inhalt angeben]",
164
164
  "param-name-placeholder": "[Name des Parameters]",
165
- "empty": "[Leer]"
165
+ "empty": "[Leer]",
166
+ "mode-placeholder": "[Modus setzen für nachfolgende Modelle]",
167
+ "set-param": "setze"
166
168
  },
167
169
  "css-source": "CSS Datei öffnen"
168
170
  }
@@ -163,7 +163,8 @@
163
163
  "template-placeholder": "[Define code template to apply to content]",
164
164
  "param-name-placeholder": "[Param name]",
165
165
  "empty": "[Empty]",
166
- "mode-placeholder": "Processing mode - passed to subsequent models"
166
+ "mode-placeholder": "[Processing mode - passed to subsequent models]",
167
+ "set-param": "set"
167
168
  },
168
169
  "css-source": "Open CSS file"
169
170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teipublisher/pb-components",
3
- "version": "1.28.2",
3
+ "version": "1.30.2",
4
4
  "description": "Collection of webcomponents underlying TEI Publisher",
5
5
  "repository": "https://github.com/eeditiones/tei-publisher-components.git",
6
6
  "main": "index.html",
package/pb-elements.json CHANGED
@@ -9743,6 +9743,11 @@
9743
9743
  "type": "boolean",
9744
9744
  "default": "false"
9745
9745
  },
9746
+ {
9747
+ "name": "before-update-event",
9748
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
9749
+ "type": "string"
9750
+ },
9746
9751
  {
9747
9752
  "name": "subscribe",
9748
9753
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -9932,6 +9937,12 @@
9932
9937
  "type": "boolean",
9933
9938
  "default": "false"
9934
9939
  },
9940
+ {
9941
+ "name": "beforeUpdate",
9942
+ "attribute": "before-update-event",
9943
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
9944
+ "type": "string"
9945
+ },
9935
9946
  {
9936
9947
  "name": "subscribe",
9937
9948
  "attribute": "subscribe",
@@ -10183,6 +10194,11 @@
10183
10194
  "type": "boolean",
10184
10195
  "default": "false"
10185
10196
  },
10197
+ {
10198
+ "name": "before-update-event",
10199
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
10200
+ "type": "string"
10201
+ },
10186
10202
  {
10187
10203
  "name": "subscribe",
10188
10204
  "description": "The name of the channel to subscribe to. Only events on a channel corresponding\nto this property are listened to.",
@@ -10355,6 +10371,12 @@
10355
10371
  "type": "boolean",
10356
10372
  "default": "false"
10357
10373
  },
10374
+ {
10375
+ "name": "beforeUpdate",
10376
+ "attribute": "before-update-event",
10377
+ "description": "If set to the name of an event, the content of the pb-view will not be replaced\nimmediately upon updates. Instead, an event is emitted, which contains the new content\nin property `root`. An event handler intercepting the event can thus modify the content.\nOnce it is done, it should pass the modified content to the callback function provided\nin the event detail under the name `render`. See the demo for an example.",
10378
+ "type": "string"
10379
+ },
10358
10380
  {
10359
10381
  "name": "subscribe",
10360
10382
  "attribute": "subscribe",
@@ -214,6 +214,16 @@ export class PbOddModelEditor extends LitElement {
214
214
  pb-code-editor {
215
215
  margin-bottom: 20px;
216
216
  }
217
+
218
+ .horizontal {
219
+ display: flex;
220
+ flex-wrap: wrap;
221
+ justify-content: space-between;
222
+ }
223
+
224
+ #mode {
225
+ min-width: 18em;
226
+ }
217
227
  `;
218
228
  }
219
229
 
@@ -435,18 +445,23 @@ export class PbOddModelEditor extends LitElement {
435
445
  </p>
436
446
  </header>
437
447
  <iron-collapse id="details" ?opened="${this.show}" class="details">
438
- <paper-dropdown-menu class="selectOutput" label="Output">
439
- <paper-listbox id="output" slot="dropdown-content" attr-for-selected="value"
440
- selected="${this.output}" @iron-select="${this._selectOutput}">
441
-
442
- ${this.outputs.map((item) =>
443
- html`
444
- <paper-item value="${item}">${item}</paper-item>
445
- `)}
448
+ <div class="horizontal">
449
+ <paper-dropdown-menu class="selectOutput" label="Output">
450
+ <paper-listbox id="output" slot="dropdown-content" attr-for-selected="value"
451
+ selected="${this.output}" @iron-select="${this._selectOutput}">
446
452
 
447
- </paper-listbox>
448
- </paper-dropdown-menu>
453
+ ${this.outputs.map((item) =>
454
+ html`
455
+ <paper-item value="${item}">${item}</paper-item>
456
+ `)}
449
457
 
458
+ </paper-listbox>
459
+ </paper-dropdown-menu>
460
+ <paper-input id="mode" .value="${this.mode}"
461
+ placeholder="${translate('odd.editor.model.mode-placeholder')}"
462
+ label="Mode"
463
+ @change="${this._inputMode}"></paper-input>
464
+ </div>
450
465
  <paper-input id="desc" .value="${this.desc}" placeholder="${translate('odd.editor.model.description-placeholder')}"
451
466
  label="Description" @change="${this._inputDesc}"></paper-input>
452
467
 
@@ -483,11 +498,6 @@ export class PbOddModelEditor extends LitElement {
483
498
  placeholder="${translate('odd.editor.model.css-class-placeholder')}"
484
499
  label="CSS Class"
485
500
  @change="${this._inputCss}"></paper-input>
486
-
487
- <paper-input id="mode" .value="${this.mode}"
488
- placeholder="${translate('odd.editor.model.mode-placeholder')}"
489
- label="Mode"
490
- @change="${this._inputMode}"></paper-input>
491
501
 
492
502
  <pb-code-editor id="template"
493
503
  code="${this.template}"
@@ -708,6 +718,7 @@ export class PbOddModelEditor extends LitElement {
708
718
  output: '',
709
719
  sourcerend: false,
710
720
  models: [],
721
+ mode: '',
711
722
  parameters: [],
712
723
  renditions: [],
713
724
  template: '',
@@ -57,7 +57,7 @@ export class PbOddParameterEditor extends LitElement {
57
57
  code="${this.value}"
58
58
  linter="${this.endpoint}/${cmpVersion(this.apiVersion, '1.0.0') ? 'modules/editor.xql' : 'api/lint'}"
59
59
  apiVersion="${this.apiVersion}"></pb-code-editor>
60
- <paper-checkbox id="set" ?checked="${this.setParam}" @change="${this._handleCodeChange}">set</paper-checkbox>
60
+ <paper-checkbox id="set" ?checked="${this.setParam}" @change="${this._handleCodeChange}">${translate('odd.editor.model.set-param')}</paper-checkbox>
61
61
  <paper-icon-button @click="${this._delete}" icon="delete" title="delete this parameter"></paper-icon-button>
62
62
  </div>
63
63
 
@@ -112,12 +112,13 @@ function ancestors(node, selector) {
112
112
  * @param {Node} node the current node
113
113
  * @returns next text node or the current node if none is found
114
114
  */
115
- function nextTextNode(node) {
116
- let next = node.nextSibling;
117
- while (next.hasChildNodes()) {
118
- next = next.firstChild;
115
+ function nextTextNode(context, node) {
116
+ const walker = document.createTreeWalker(context, NodeFilter.SHOW_TEXT);
117
+ walker.currentNode = node;
118
+ if (walker.nextNode()) {
119
+ return walker.currentNode;
119
120
  }
120
- return next.nodeType === Node.TEXT_NODE ? next : node;
121
+ return node;
121
122
  }
122
123
 
123
124
  /**
@@ -322,7 +323,7 @@ class PbViewAnnotate extends PbView {
322
323
 
323
324
  set annotations(annoData) {
324
325
  this._ranges = annoData;
325
- this.updateAnnotations();
326
+ this.updateAnnotations(true);
326
327
  this._initAnnotationColors();
327
328
  this._annotationStyles();
328
329
  }
@@ -412,7 +413,7 @@ class PbViewAnnotate extends PbView {
412
413
  }, 300));
413
414
  }
414
415
 
415
- _updateAnnotation(teiRange, batch = false) {
416
+ _updateAnnotation(teiRange, silent = false, batch = false) {
416
417
  const view = this.shadowRoot.getElementById('view');
417
418
  const context = Array.from(view.querySelectorAll(`[data-tei="${teiRange.context}"]`)).filter(
418
419
  node => node.closest('pb-popover') === null && node.getAttribute('rel') !== 'footnote',
@@ -433,12 +434,16 @@ class PbViewAnnotate extends PbView {
433
434
 
434
435
  console.log('<pb-view-annotate> Range before adjust: %o %o', startPoint, endPoint);
435
436
  if (startPoint[1] === startPoint[0].textContent.length) {
436
- const nextNode = nextTextNode(startPoint[0]);
437
+ // try to find the next text node
438
+ const nextNode = nextTextNode(context, startPoint[0]);
437
439
  // next text node is the endpoint: start there
438
440
  if (nextNode === endPoint[0]) {
439
441
  range.setStart(nextNode, 0);
442
+ // adjust startPoint for check below
443
+ startPoint[0] = nextNode;
444
+ startPoint[1] = 0;
440
445
  } else {
441
- range.setStartBefore(startPoint[0].nextSibling);
446
+ range.setStartBefore(startPoint[0].nextSibling || nextNode);
442
447
  }
443
448
  } else if (startPoint[0] !== endPoint[0] && startPoint[1] === 0) {
444
449
  range.setStartBefore(extendRange(startPoint[0], context));
@@ -462,6 +467,9 @@ class PbViewAnnotate extends PbView {
462
467
  try {
463
468
  range.surroundContents(span);
464
469
  } catch (e) {
470
+ if (silent) {
471
+ return null;
472
+ }
465
473
  throw new Error('An error occurred. The annotation may not be displayed. You should consider saving and reloading the document.');
466
474
  }
467
475
  this._rangesMap.set(span, teiRange);
@@ -473,7 +481,7 @@ class PbViewAnnotate extends PbView {
473
481
  return span;
474
482
  }
475
483
 
476
- updateAnnotations() {
484
+ updateAnnotations(silent = false) {
477
485
  this._ranges.forEach((teiRange) => {
478
486
  let span;
479
487
  switch (teiRange.type) {
@@ -490,7 +498,7 @@ class PbViewAnnotate extends PbView {
490
498
  span.dataset.annotation = JSON.stringify(teiRange.properties);
491
499
  break;
492
500
  default:
493
- this._updateAnnotation(teiRange, true);
501
+ this._updateAnnotation(teiRange, silent, true);
494
502
  break;
495
503
  }
496
504
  });
@@ -980,6 +988,7 @@ class PbViewAnnotate extends PbView {
980
988
  lightness: [30, 60]
981
989
  }));
982
990
  });
991
+ this.emitTo('pb-annotation-colors', { colors: this._annotationColors });
983
992
  }
984
993
 
985
994
  _checkAnnotationColor(type) {
@@ -992,6 +1001,7 @@ class PbViewAnnotate extends PbView {
992
1001
  lightness: [30, 60]
993
1002
  }));
994
1003
  this._annotationStyles();
1004
+ this.emitTo('pb-annotation-colors', { colors: this._annotationColors });
995
1005
  }
996
1006
 
997
1007
  _annotationStyles() {
package/src/pb-view.js CHANGED
@@ -272,6 +272,17 @@ export class PbView extends pbMixin(LitElement) {
272
272
  type: Boolean,
273
273
  attribute: 'disable-history'
274
274
  },
275
+ /**
276
+ * If set to the name of an event, the content of the pb-view will not be replaced
277
+ * immediately upon updates. Instead, an event is emitted, which contains the new content
278
+ * in property `root`. An event handler intercepting the event can thus modify the content.
279
+ * Once it is done, it should pass the modified content to the callback function provided
280
+ * in the event detail under the name `render`. See the demo for an example.
281
+ */
282
+ beforeUpdate: {
283
+ type: String,
284
+ attribute: 'before-update-event'
285
+ },
275
286
  _features: {
276
287
  type: Object
277
288
  },
@@ -312,6 +323,7 @@ export class PbView extends pbMixin(LitElement) {
312
323
  this.highlight = false;
313
324
  this.infiniteScrollMax = 10;
314
325
  this.disableHistory = false;
326
+ this.beforeUpdate = null;
315
327
  this._features = {};
316
328
  this._selector = new Map();
317
329
  this._chunks = [];
@@ -696,6 +708,22 @@ export class PbView extends pbMixin(LitElement) {
696
708
  fragment.appendChild(elem);
697
709
  elem.innerHTML = resp.content;
698
710
 
711
+ // if before-update-event is set, we do not replace the content immediately,
712
+ // but emit an event
713
+ if (this.beforeUpdate) {
714
+ this.emitTo(this.beforeUpdate, {
715
+ data: resp,
716
+ root: elem,
717
+ render: (content) => {
718
+ this._doReplaceContent(content, resp, direction);
719
+ }
720
+ });
721
+ } else {
722
+ this._doReplaceContent(elem, resp, direction);
723
+ }
724
+ }
725
+
726
+ _doReplaceContent(elem, resp, direction) {
699
727
  if (this.columnSeparator) {
700
728
  this._replaceColumns(elem);
701
729
  this._loading = false;