@teipublisher/pb-components 3.0.0-next-4.18 → 3.0.0-next-4.19
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 +16 -0
- package/dist/demo/pb-timeline.html +1 -1
- package/dist/{focus-mixin-BovUXNGZ.js → focus-mixin-BTMHjJn_.js} +1 -1
- package/dist/pb-code-editor.js +1 -1
- package/dist/pb-components-bundle.js +284 -284
- package/dist/{pb-dialog-DDg5xSQQ.js → pb-dialog-69GQVfpQ.js} +1 -1
- package/dist/pb-edit-app.js +1 -1
- package/dist/pb-elements.json +2063 -1445
- package/dist/pb-facsimile.js +4 -4
- package/dist/{pb-i18n-UbZecobk.js → pb-i18n-DpafwkRO.js} +1 -1
- package/dist/pb-leaflet-map.js +4 -4
- package/dist/pb-mei.js +9 -9
- package/dist/{pb-mixin-B7EAqf7q.js → pb-mixin-BUnZhCew.js} +1 -1
- package/dist/pb-odd-editor.js +1 -1
- package/dist/pb-tify.js +1 -1
- package/dist/{unsafe-html-CaP8bK29.js → unsafe-html-C8JBHfUC.js} +1 -1
- package/dist/url-BIkUkuPN.js +1 -0
- package/dist/urls-D1E6DSqS.js +1 -0
- package/package.json +1 -1
- package/pb-elements.json +2063 -1445
- package/src/authority/airtable.js +1 -1
- package/src/pb-browse-docs.js +1 -1
- package/src/pb-code-highlight.js +2 -1
- package/src/pb-combo-box.js +1 -1
- package/src/pb-components.js +1 -1
- package/src/pb-facsimile.js +1 -1
- package/src/pb-leaflet-map.js +1 -1
- package/src/pb-login.js +1 -1
- package/src/pb-manage-odds.js +1 -1
- package/src/pb-mei.js +2 -1
- package/src/pb-mixin.js +47 -7
- package/src/pb-odd-model-editor.js +1 -1
- package/src/pb-odd-parameter-editor.js +1 -1
- package/src/pb-page.js +1 -1
- package/src/pb-popover.js +1 -1
- package/src/pb-print-preview.js +1 -1
- package/src/pb-table-grid.js +1 -1
- package/src/pb-tify.js +1 -1
- package/src/pb-timeline.js +2 -2
- package/src/pb-upload.js +1 -1
- package/src/pb-version.js +1 -1
- package/src/theming.js +2 -1
- package/src/urls.js +1 -1
- package/src/utils/css.js +29 -0
- package/src/{pb-events.js → utils/events.js} +1 -1
- package/src/{search-result-service.js → utils/services/search-result-service.js} +2 -2
- package/src/utils/url.js +20 -0
- package/src/utils/version.js +49 -0
- package/dist/urls-DLcxW8ou.js +0 -1
- package/src/utils.js +0 -53
- /package/src/{seed-element.js → docs/seed-element.js} +0 -0
- /package/src/{parse-date-service.js → utils/services/parse-date-service.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# [3.0.0-next-4.19](https://github.com/eeditiones/tei-publisher-components/compare/v3.0.0-next-4.18...v3.0.0-next-4.19) (2026-05-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### chore
|
|
5
|
+
|
|
6
|
+
* **events:** reorganize event and utility imports across demo and source files ([2dddd19](https://github.com/eeditiones/tei-publisher-components/commit/2dddd19ef03b38a02a8505093802c298494abf0f))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* **events:** pb-events is gone, which affects public API
|
|
12
|
+
|
|
13
|
+
- Replaced references to the deprecated pb-events.js with the new utils/events.js in multiple demo HTML files.
|
|
14
|
+
- Updated various source files to import utility functions from their new locations in utils, enhancing code organization and maintainability.
|
|
15
|
+
- Removed the obsolete utils.js file, consolidating utility functions into more specific modules for clarity.
|
|
16
|
+
|
|
1
17
|
# [3.0.0-next-4.18](https://github.com/eeditiones/tei-publisher-components/compare/v3.0.0-next-4.17...v3.0.0-next-4.18) (2026-05-12)
|
|
2
18
|
|
|
3
19
|
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
|
|
74
74
|
<script type="module">
|
|
75
75
|
// import { jsonDataDev } from './timeline-dev-data.js';
|
|
76
|
-
import {SearchResultService} from "../src/search-result-service.js";
|
|
76
|
+
import {SearchResultService} from "../src/utils/services/search-result-service.js";
|
|
77
77
|
|
|
78
78
|
/*
|
|
79
79
|
const jsonData = jsonDataDev;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{E as t,p as e,a as s,x as n,i,T as o,w as r,f as a,S as l}from"./pb-mixin-
|
|
1
|
+
import{E as t,p as e,a as s,x as n,i,T as o,w as r,f as a,S as l}from"./pb-mixin-BUnZhCew.js";import{t as c}from"./pb-dialog-69GQVfpQ.js";import{e as d,a as h,b as u,g as p,t as g}from"./pb-i18n-DpafwkRO.js";import{l as f}from"./logger-BDsEU7Z8.js";import{o as m}from"./unsafe-html-C8JBHfUC.js";const v=e=>e??t;class b extends(c(e(s))){static get properties(){return Object.assign(Object.assign({},super.properties),{},{noAnimation:{type:Boolean,attribute:"no-animation"},opened:{type:Boolean},toggles:{type:Boolean},expandIcon:{type:String,attribute:"expand-icon"},collapseIcon:{type:String,attribute:"collapse-icon"},iconSprite:{type:String,attribute:"icon-sprite"},noIcons:{type:Boolean,attribute:"no-icons"}})}constructor(){super(),this.horizontal=!1,this.noAnimation=!1,this.opened=!1,this.expandIcon="icons:expand-more",this.collapseIcon="icons:expand-less",this.noIcons=!1,this.toggles=!1}connectedCallback(){super.connectedCallback(),this.addEventListener("pb-collapse-open",()=>{this.open()}),this.toggles&&this.subscribeTo("pb-collapse-open",t=>{if(t.detail&&t.detail._source!==this){for(const e of this.querySelectorAll("pb-collapse"))if(e===t.detail._source)return;this.close()}})}updated(t){if(super.updated(t),t.has("opened")){const t=this.shadowRoot.querySelector("details");t&&(t.open=this.opened)}}open(){this.opened||(this.opened=!0,this.emitTo("pb-collapse-open",this))}close(){this.opened&&(this.opened=!1)}toggle(){this.opened=!this.opened,this.opened&&this.emitTo("pb-collapse-open",this.data)}_handleToggle(t){t.preventDefault(),this.toggle()}render(){return n`
|
|
2
2
|
<details ?open="${this.opened}" class="${this.horizontal?"horizontal":""}">
|
|
3
3
|
<summary
|
|
4
4
|
@click="${this._handleToggle}"
|
package/dist/pb-code-editor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{p as e,a as t,x as i,i as o}from"./pb-mixin-B7EAqf7q.js";import{J as n,X as s}from"./jinn-codemirror-DETLdm08.js";import{t as r}from"./pb-i18n-UbZecobk.js";class l{constructor(e){this.config=e}detectContext(e,t){const i=e.state.sliceDoc(Math.max(0,t-500),t),o=new RegExp(`${this.config.attributeName}\\s*=\\s*(["'])([^"']*)$`),n=i.match(o);if(!n)return{isInAttribute:!1,elementName:null,conditionValue:null};const s=i.substring(0,i.length-n[0].length).match(/<(\w+)([^>]*?)$/);if(!s)return{isInAttribute:!0,elementName:null,conditionValue:null};const r=s[1],l=s[2];let a=null;if(this.config.conditionAttribute){const e=new RegExp(`${this.config.conditionAttribute.name}\\s*=\\s*["']([^"']+)["']`),t=l.match(e);a=t?t[1]:null}return{isInAttribute:!0,elementName:r,conditionValue:a}}createCompletionSource(){return async e=>{const{state:t,pos:i,view:o}=e;if(!o)return null;const n=this.detectContext(o,i);if(n.elementName!==this.config.elementName||!n.isInAttribute)return null;if(this.config.conditionAttribute&&n.conditionValue!==this.config.conditionAttribute.value)return null;const s=t.sliceDoc(Math.max(0,i-100),i),r=new RegExp(`${this.config.attributeName}\\s*=\\s*(["'])([^"']*)$`),l=s.match(r);if(!l)return null;const a=l[2],d=a||"";return{from:i-a.length,to:i,options:await this.config.callback(d||void 0),filter:!1}}}}class a{}class d extends a{constructor(e=null){super(),this.baseUrl=e}createAutocomplete(){return new l({elementName:"ref",attributeName:"target",conditionAttribute:{name:"type",value:"biblio"},callback:this.createZoteroAutocompleteCallback()})}createZoteroAutocompleteCallback(){return async e=>{try{let t=`${this.baseUrl||""}/api/zotero/items/suggest`;e&&(t+=`?q=${encodeURIComponent(e)}`);const i=await fetch(t);if(!i.ok)return console.error("Failed to fetch Zotero suggestions:",i.status,i.statusText),[];const o=await i.json();let n=[];return Array.isArray(o)&&(n=o.map(e=>({displayLabel:e.tag,detail:e.title,label:`#${e.tag}`,type:"text",info:()=>{if(!e.bib)return null;const t=document.createElement("span");return t.innerHTML=e.bib,t}}))),console.log("Zotero suggestions:",n),n}catch(e){return console.error("Error fetching Zotero suggestions:",e),[]}}}}class h extends n{constructor(){super(),this.unwrap=!1,this.autocompleteProviders=[],this.schema=null,this.schemaRoot=null,this.baseUrl=null}connectedCallback(){var e;this.schema=this.getAttribute("schema"),this.schemaRoot=this.getAttribute("schema-root"),this.baseUrl=this.getAttribute("base-url"),this.unwrap=this.hasAttribute("unwrap"),this.autocompleteProviders=(null===(e=this.getAttribute("providers"))||void 0===e?void 0:e.split(",").map(e=>{if("zotero"===e)return new d(this.baseUrl);throw new Error(`Unknown autocomplete provider: ${e}`)}))||[],super.connectedCallback();const t=this.getAttribute("wrapper");if(t){const e=new DOMParser;let i=e.parseFromString(t,"application/xml"),o=i.getElementsByTagName("parsererror"),n=null;if(o.length)console.error("<jinn-xml-editor> Invalid XML for wrapper attribute: %s",(new XMLSerializer).serializeToString(i));else{if(n=i.firstElementChild,n&&this.hasAttribute("code")){const t=this.getAttribute("code")||"";i=e.parseFromString(t,"application/xml"),o=i.getElementsByTagName("parsererror"),o.length?console.error("<jinn-xml-editor> Invalid XML for code attribute: %s",(new XMLSerializer).serializeToString(i)):i.firstElementChild&&n.appendChild(i.firstElementChild)}this.setValue(n)}}}configure(){var e;const t=this.getToolbarControls(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("[name=toolbar]")),i=this.hasAttribute("check-namespace");this._config=new s(this,t,this.namespace,i,this.unwrap,this.autocompleteProviders.map(e=>e.createAutocomplete()))}emitUpdateEvent(e){if(!this.unwrap)return super.emitUpdateEvent(e);this.updateValue(),super.emitUpdateEvent(this._wrapper)}updateValue(){if(!this._wrapper)return console.log("no wrapper !!!"),null;if(this._wrapper.replaceChildren(),this._value)if(this._value instanceof NodeList)for(let t=0;t<this._value.length;t++){var e;const i=this._wrapper.ownerDocument.importNode(this._value[t],!0);null===(e=this._wrapper)||void 0===e||e.appendChild(i)}else{if(!(this._value instanceof Node))throw console.error("<xml-editor> Value is not a node"),new Error("value is not a node");var t;null===(t=this._wrapper)||void 0===t||t.appendChild(this._value)}else console.log("xml editor value is empty")}setValue(e){var t,i,o;if(!this.unwrap)return super.setValue(e);if((null===(t=this._config)||void 0===t?void 0:t.setFromValue(this._wrapper))===(null===(i=this._config)||void 0===i?void 0:i.setFromValue(e)))return!1;if(e||(this._wrapper=null),"string"==typeof e){const t=(new DOMParser).parseFromString(e,"application/xml");if(!t.firstElementChild)return!1;e=t.firstElementChild}return this._wrapper=e,this._value=null===(o=e)||void 0===o?void 0:o.childNodes,!0}getValue(){if(!this.unwrap)return super.getValue();if(!this._wrapper)return null;if(!(this._wrapper instanceof Element))throw new Error("Value is not a node");return this.updateValue(),this._wrapper}}customElements.get("jinn-xml-editor")||window.customElements.define("jinn-xml-editor",h);const c='\n :host {\n display: block;\n width: 100%;\n }\n jinn-codemirror {\n font-size: 1rem;\n display:block;\n width:100%;\n }\n jinn-codemirror[valid="true"] {\n outline: thin solid green;\n }\n jinn-codemirror[valid="false"] {\n outline: thin solid red;\n }\n #leiden-editor {\n margin-bottom:0.5rem;\n }\n [slot=toolbar] {\n display: flex;\n }\n .hidden {\n display: none;\n }\n #close-leiden {\n margin-left: .75rem;\n font-weight: bold;\n }',u=["Shift","Alt","Meta","Control","ArrowLeft","ArrowRight","ArrowDown","ArrowUp","PageDown","PageUp","Home","End"],m={leiden_plus:"Leiden+",edcs:"EDCS/EDH",default:"Petrae"};function p(e){const t=[];return Object.entries(m).forEach(([i,o])=>{t.push(`<option value="${i}" ${i===e?"selected":""}>${o}</option>`)}),`<select name="modes">${t.join("\n")}</select>`}class v extends HTMLElement{constructor(){super(),this.mode="leiden_plus",this.placeholder="",this.showLeiden=!1,this.xmlEditor=null,this.valid=!0,this.unwrap=!1,this.schema=null,this.schemaRoot=null,this.modeSelect=!1,this.attachShadow({mode:"open"})}set value(e){this.xmlEditor.value=e}get value(){return this.xmlEditor.value}connectedCallback(){var e,t,i,o;this.unwrap=this.hasAttribute("unwrap"),this.schema=this.getAttribute("schema"),this.schemaRoot=this.getAttribute("schema-root"),this.modeSelect=this.hasAttribute("mode-select"),this.mode=this.getAttribute("mode")||"leiden_plus",this.placeholder=this.getAttribute("placeholder")||"",this.showLeiden=this.hasAttribute("show-leiden"),this.shadowRoot.innerHTML=`\n <style>\n ${c}\n </style>\n <jinn-codemirror id="leiden-editor" class="${this.showLeiden?"":"hidden"}" \n mode="${this.mode}" ignore-blur>\n <div slot="header"><slot name="leiden-header"></slot></div>\n <div slot="toolbar">\n ${this.modeSelect?p(this.mode):""}\n <slot name="leiden-toolbar"></slot>\n <button part="button" id="close-leiden">Close</button>\n </div>\n </jinn-codemirror>\n <jinn-xml-editor id="xml-editor" ${this.unwrap?"unwrap":""} schema="${this.schema}"\n schema-root="${this.schemaRoot}" placeholder="${this.placeholder}" ignore-blur\n namespace="http://www.tei-c.org/ns/1.0">\n <div slot="header"><slot name="xml-header"></slot></div>\n <div slot="toolbar">\n <slot name="open-leiden" id="import" class="${this.showLeiden?"hidden":""}">\n <button part="button" title="Import from Leiden markup">Leiden Editor</button>\n </slot>\n <slot name="xml-toolbar"></slot>\n </div>\n </jinn-xml-editor>\n `,this.xmlEditor=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("#xml-editor");const n=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("#leiden-editor"),s=null===(i=this.shadowRoot)||void 0===i?void 0:i.querySelector("#import"),r=null===(o=this.shadowRoot)||void 0===o?void 0:o.querySelector("#close-leiden");if(!(this.xmlEditor&&n&&s&&r))throw new Error("One or more components were not initialized");let l=!0,a=this.showLeiden;n.addEventListener("update",e=>{e.stopPropagation(),this.showLeiden=!1,l&&(this.xmlEditor.content=e.detail.content),l=!0}),this.xmlEditor.addEventListener("keyup",e=>{if(a){if(u.indexOf(e.key)>-1)return;h()}});const d=()=>{s.classList.add("hidden"),n.classList.remove("hidden"),a=!0,n.focus()},h=()=>{var e;n.classList.add("hidden"),s.classList.remove("hidden"),a=!1,null===(e=this.xmlEditor)||void 0===e||e.focus(),l=!1,null==n||n.clear()},m=()=>{if(n.classList.contains("hidden")||this.showLeiden)if(this.xmlEditor.content.length>0){var e;if(!this.valid)return void alert("The XML contains errors. Cannot convert to Leiden+");const t=null===(e=this.xmlEditor)||void 0===e?void 0:e.value;l=!1,n.setMode("leiden_plus",!1);try{this.unwrap&&t instanceof Element?n.value=t.childNodes:n.value=t,this.xmlEditor.status="",d()}catch(e){this.xmlEditor.status=e.message,h()}}else d(),n.value="";else h()};s.addEventListener("click",()=>{m()}),r.addEventListener("click",()=>{h()}),this.xmlEditor.addEventListener("invalid",e=>{e.stopPropagation(),this.valid=!1,this.setAttribute("valid",this.valid.toString()),this.dispatchEvent(new CustomEvent("invalid",{detail:e.detail,composed:!0,bubbles:!0}))}),this.xmlEditor.addEventListener("valid",e=>{e.stopPropagation(),this.valid=!0,this.setAttribute("valid",this.valid.toString()),this.dispatchEvent(new CustomEvent("valid",{detail:e.detail,composed:!0,bubbles:!0}))}),this.xmlEditor.addEventListener("update",()=>{this.showLeiden&&m(),this.showLeiden=!1},{once:!0}),this.addEventListener("blur",e=>{e.relatedTarget&&!this.contains(e.relatedTarget)&&this.dispatchEvent(new CustomEvent("leave",{composed:!0,bubbles:!0}))})}}customElements.get("jinn-epidoc-editor")||window.customElements.define("jinn-epidoc-editor",v);class b extends(e(t)){static get properties(){return Object.assign(Object.assign({},super.properties),{},{code:{type:String,reflect:!0},mode:{type:String},label:{type:String},placeholder:{type:String},tabSize:{type:Number},linter:{attribute:!0}})}constructor(){super(),this.code="",this.mode="xml",this.placeholder="odd.editor.model.empty",this.tabSize=2,this.label="",this.linter="",this._editor=null}connectedCallback(){super.connectedCallback()}firstUpdated(){super.firstUpdated(),this._editor=this.shadowRoot.getElementById("editor")}render(){return i`
|
|
1
|
+
import{p as e,a as t,x as i,i as o}from"./pb-mixin-BUnZhCew.js";import{J as n,X as s}from"./jinn-codemirror-DETLdm08.js";import{t as r}from"./pb-i18n-DpafwkRO.js";class l{constructor(e){this.config=e}detectContext(e,t){const i=e.state.sliceDoc(Math.max(0,t-500),t),o=new RegExp(`${this.config.attributeName}\\s*=\\s*(["'])([^"']*)$`),n=i.match(o);if(!n)return{isInAttribute:!1,elementName:null,conditionValue:null};const s=i.substring(0,i.length-n[0].length).match(/<(\w+)([^>]*?)$/);if(!s)return{isInAttribute:!0,elementName:null,conditionValue:null};const r=s[1],l=s[2];let a=null;if(this.config.conditionAttribute){const e=new RegExp(`${this.config.conditionAttribute.name}\\s*=\\s*["']([^"']+)["']`),t=l.match(e);a=t?t[1]:null}return{isInAttribute:!0,elementName:r,conditionValue:a}}createCompletionSource(){return async e=>{const{state:t,pos:i,view:o}=e;if(!o)return null;const n=this.detectContext(o,i);if(n.elementName!==this.config.elementName||!n.isInAttribute)return null;if(this.config.conditionAttribute&&n.conditionValue!==this.config.conditionAttribute.value)return null;const s=t.sliceDoc(Math.max(0,i-100),i),r=new RegExp(`${this.config.attributeName}\\s*=\\s*(["'])([^"']*)$`),l=s.match(r);if(!l)return null;const a=l[2],d=a||"";return{from:i-a.length,to:i,options:await this.config.callback(d||void 0),filter:!1}}}}class a{}class d extends a{constructor(e=null){super(),this.baseUrl=e}createAutocomplete(){return new l({elementName:"ref",attributeName:"target",conditionAttribute:{name:"type",value:"biblio"},callback:this.createZoteroAutocompleteCallback()})}createZoteroAutocompleteCallback(){return async e=>{try{let t=`${this.baseUrl||""}/api/zotero/items/suggest`;e&&(t+=`?q=${encodeURIComponent(e)}`);const i=await fetch(t);if(!i.ok)return console.error("Failed to fetch Zotero suggestions:",i.status,i.statusText),[];const o=await i.json();let n=[];return Array.isArray(o)&&(n=o.map(e=>({displayLabel:e.tag,detail:e.title,label:`#${e.tag}`,type:"text",info:()=>{if(!e.bib)return null;const t=document.createElement("span");return t.innerHTML=e.bib,t}}))),console.log("Zotero suggestions:",n),n}catch(e){return console.error("Error fetching Zotero suggestions:",e),[]}}}}class h extends n{constructor(){super(),this.unwrap=!1,this.autocompleteProviders=[],this.schema=null,this.schemaRoot=null,this.baseUrl=null}connectedCallback(){var e;this.schema=this.getAttribute("schema"),this.schemaRoot=this.getAttribute("schema-root"),this.baseUrl=this.getAttribute("base-url"),this.unwrap=this.hasAttribute("unwrap"),this.autocompleteProviders=(null===(e=this.getAttribute("providers"))||void 0===e?void 0:e.split(",").map(e=>{if("zotero"===e)return new d(this.baseUrl);throw new Error(`Unknown autocomplete provider: ${e}`)}))||[],super.connectedCallback();const t=this.getAttribute("wrapper");if(t){const e=new DOMParser;let i=e.parseFromString(t,"application/xml"),o=i.getElementsByTagName("parsererror"),n=null;if(o.length)console.error("<jinn-xml-editor> Invalid XML for wrapper attribute: %s",(new XMLSerializer).serializeToString(i));else{if(n=i.firstElementChild,n&&this.hasAttribute("code")){const t=this.getAttribute("code")||"";i=e.parseFromString(t,"application/xml"),o=i.getElementsByTagName("parsererror"),o.length?console.error("<jinn-xml-editor> Invalid XML for code attribute: %s",(new XMLSerializer).serializeToString(i)):i.firstElementChild&&n.appendChild(i.firstElementChild)}this.setValue(n)}}}configure(){var e;const t=this.getToolbarControls(null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("[name=toolbar]")),i=this.hasAttribute("check-namespace");this._config=new s(this,t,this.namespace,i,this.unwrap,this.autocompleteProviders.map(e=>e.createAutocomplete()))}emitUpdateEvent(e){if(!this.unwrap)return super.emitUpdateEvent(e);this.updateValue(),super.emitUpdateEvent(this._wrapper)}updateValue(){if(!this._wrapper)return console.log("no wrapper !!!"),null;if(this._wrapper.replaceChildren(),this._value)if(this._value instanceof NodeList)for(let t=0;t<this._value.length;t++){var e;const i=this._wrapper.ownerDocument.importNode(this._value[t],!0);null===(e=this._wrapper)||void 0===e||e.appendChild(i)}else{if(!(this._value instanceof Node))throw console.error("<xml-editor> Value is not a node"),new Error("value is not a node");var t;null===(t=this._wrapper)||void 0===t||t.appendChild(this._value)}else console.log("xml editor value is empty")}setValue(e){var t,i,o;if(!this.unwrap)return super.setValue(e);if((null===(t=this._config)||void 0===t?void 0:t.setFromValue(this._wrapper))===(null===(i=this._config)||void 0===i?void 0:i.setFromValue(e)))return!1;if(e||(this._wrapper=null),"string"==typeof e){const t=(new DOMParser).parseFromString(e,"application/xml");if(!t.firstElementChild)return!1;e=t.firstElementChild}return this._wrapper=e,this._value=null===(o=e)||void 0===o?void 0:o.childNodes,!0}getValue(){if(!this.unwrap)return super.getValue();if(!this._wrapper)return null;if(!(this._wrapper instanceof Element))throw new Error("Value is not a node");return this.updateValue(),this._wrapper}}customElements.get("jinn-xml-editor")||window.customElements.define("jinn-xml-editor",h);const c='\n :host {\n display: block;\n width: 100%;\n }\n jinn-codemirror {\n font-size: 1rem;\n display:block;\n width:100%;\n }\n jinn-codemirror[valid="true"] {\n outline: thin solid green;\n }\n jinn-codemirror[valid="false"] {\n outline: thin solid red;\n }\n #leiden-editor {\n margin-bottom:0.5rem;\n }\n [slot=toolbar] {\n display: flex;\n }\n .hidden {\n display: none;\n }\n #close-leiden {\n margin-left: .75rem;\n font-weight: bold;\n }',u=["Shift","Alt","Meta","Control","ArrowLeft","ArrowRight","ArrowDown","ArrowUp","PageDown","PageUp","Home","End"],m={leiden_plus:"Leiden+",edcs:"EDCS/EDH",default:"Petrae"};function p(e){const t=[];return Object.entries(m).forEach(([i,o])=>{t.push(`<option value="${i}" ${i===e?"selected":""}>${o}</option>`)}),`<select name="modes">${t.join("\n")}</select>`}class v extends HTMLElement{constructor(){super(),this.mode="leiden_plus",this.placeholder="",this.showLeiden=!1,this.xmlEditor=null,this.valid=!0,this.unwrap=!1,this.schema=null,this.schemaRoot=null,this.modeSelect=!1,this.attachShadow({mode:"open"})}set value(e){this.xmlEditor.value=e}get value(){return this.xmlEditor.value}connectedCallback(){var e,t,i,o;this.unwrap=this.hasAttribute("unwrap"),this.schema=this.getAttribute("schema"),this.schemaRoot=this.getAttribute("schema-root"),this.modeSelect=this.hasAttribute("mode-select"),this.mode=this.getAttribute("mode")||"leiden_plus",this.placeholder=this.getAttribute("placeholder")||"",this.showLeiden=this.hasAttribute("show-leiden"),this.shadowRoot.innerHTML=`\n <style>\n ${c}\n </style>\n <jinn-codemirror id="leiden-editor" class="${this.showLeiden?"":"hidden"}" \n mode="${this.mode}" ignore-blur>\n <div slot="header"><slot name="leiden-header"></slot></div>\n <div slot="toolbar">\n ${this.modeSelect?p(this.mode):""}\n <slot name="leiden-toolbar"></slot>\n <button part="button" id="close-leiden">Close</button>\n </div>\n </jinn-codemirror>\n <jinn-xml-editor id="xml-editor" ${this.unwrap?"unwrap":""} schema="${this.schema}"\n schema-root="${this.schemaRoot}" placeholder="${this.placeholder}" ignore-blur\n namespace="http://www.tei-c.org/ns/1.0">\n <div slot="header"><slot name="xml-header"></slot></div>\n <div slot="toolbar">\n <slot name="open-leiden" id="import" class="${this.showLeiden?"hidden":""}">\n <button part="button" title="Import from Leiden markup">Leiden Editor</button>\n </slot>\n <slot name="xml-toolbar"></slot>\n </div>\n </jinn-xml-editor>\n `,this.xmlEditor=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector("#xml-editor");const n=null===(t=this.shadowRoot)||void 0===t?void 0:t.querySelector("#leiden-editor"),s=null===(i=this.shadowRoot)||void 0===i?void 0:i.querySelector("#import"),r=null===(o=this.shadowRoot)||void 0===o?void 0:o.querySelector("#close-leiden");if(!(this.xmlEditor&&n&&s&&r))throw new Error("One or more components were not initialized");let l=!0,a=this.showLeiden;n.addEventListener("update",e=>{e.stopPropagation(),this.showLeiden=!1,l&&(this.xmlEditor.content=e.detail.content),l=!0}),this.xmlEditor.addEventListener("keyup",e=>{if(a){if(u.indexOf(e.key)>-1)return;h()}});const d=()=>{s.classList.add("hidden"),n.classList.remove("hidden"),a=!0,n.focus()},h=()=>{var e;n.classList.add("hidden"),s.classList.remove("hidden"),a=!1,null===(e=this.xmlEditor)||void 0===e||e.focus(),l=!1,null==n||n.clear()},m=()=>{if(n.classList.contains("hidden")||this.showLeiden)if(this.xmlEditor.content.length>0){var e;if(!this.valid)return void alert("The XML contains errors. Cannot convert to Leiden+");const t=null===(e=this.xmlEditor)||void 0===e?void 0:e.value;l=!1,n.setMode("leiden_plus",!1);try{this.unwrap&&t instanceof Element?n.value=t.childNodes:n.value=t,this.xmlEditor.status="",d()}catch(e){this.xmlEditor.status=e.message,h()}}else d(),n.value="";else h()};s.addEventListener("click",()=>{m()}),r.addEventListener("click",()=>{h()}),this.xmlEditor.addEventListener("invalid",e=>{e.stopPropagation(),this.valid=!1,this.setAttribute("valid",this.valid.toString()),this.dispatchEvent(new CustomEvent("invalid",{detail:e.detail,composed:!0,bubbles:!0}))}),this.xmlEditor.addEventListener("valid",e=>{e.stopPropagation(),this.valid=!0,this.setAttribute("valid",this.valid.toString()),this.dispatchEvent(new CustomEvent("valid",{detail:e.detail,composed:!0,bubbles:!0}))}),this.xmlEditor.addEventListener("update",()=>{this.showLeiden&&m(),this.showLeiden=!1},{once:!0}),this.addEventListener("blur",e=>{e.relatedTarget&&!this.contains(e.relatedTarget)&&this.dispatchEvent(new CustomEvent("leave",{composed:!0,bubbles:!0}))})}}customElements.get("jinn-epidoc-editor")||window.customElements.define("jinn-epidoc-editor",v);class b extends(e(t)){static get properties(){return Object.assign(Object.assign({},super.properties),{},{code:{type:String,reflect:!0},mode:{type:String},label:{type:String},placeholder:{type:String},tabSize:{type:Number},linter:{attribute:!0}})}constructor(){super(),this.code="",this.mode="xml",this.placeholder="odd.editor.model.empty",this.tabSize=2,this.label="",this.linter="",this._editor=null}connectedCallback(){super.connectedCallback()}firstUpdated(){super.firstUpdated(),this._editor=this.shadowRoot.getElementById("editor")}render(){return i`
|
|
2
2
|
<div class="label">${this.label}</div>
|
|
3
3
|
<jinn-codemirror
|
|
4
4
|
id="editor"
|