1 line
6.9 KiB
JavaScript
1 line
6.9 KiB
JavaScript
|
(()=>{"use strict";var t,e={4870:(t,e,i)=>{var s=i(9408);class n{constructor(t,e,i,s,n,a){var r=':input[name="'+e+'"]';this.input=t.find(r).addBack(r),this.idForLabel=i,this.setState(s),this.parentCapabilities=n||new Map,this.options=a}getValue(){return this.input.val()}getState(){return this.input.val()}setState(t){this.input.val(t)}getTextLabel(t){const e=this.getValue();if("string"!=typeof e)return null;const i=t&&t.maxLength;return i&&e.length>i?e.substring(0,i-1)+"…":e}focus(){this.input.focus()}setCapabilityOptions(t,e){Object.assign(this.parentCapabilities.get(t),e)}}class a{constructor(t,e){this.html=t,this.idPattern=e}boundWidgetClass=n;render(t,e,i,s,n,a={}){var r=this.html.replace(/__NAME__/g,e).replace(/__ID__/g,i),o=this.idPattern.replace(/__ID__/g,i),l=$(r);return"object"==typeof a?.attributes&&Object.entries(a.attributes).forEach((([t,e])=>{l.attr(t,e)})),$(t).replaceWith(l),new this.boundWidgetClass(l,e,o,s,n,a)}}window.telepath.register("wagtail.widgets.Widget",a);class r extends n{getValue(){return this.input.is(":checked")}getState(){return this.input.is(":checked")}setState(t){this.input.attr("checked",t||null)}}window.telepath.register("wagtail.widgets.CheckboxInput",class extends a{boundWidgetClass=r});class o{constructor(t,e,i,s){this.element=t,this.name=e,this.idForLabel=i,this.selector='input[name="'+e+'"]:checked',this.setState(s)}getValue(){return this.element.find(this.selector).val()}getState(){return this.element.find(this.selector).val()}setState(t){this.element.find('input[name="'+this.name+'"]').val([t])}focus(){this.element.find('input[name="'+this.name+'"]').focus()}}window.telepath.register("wagtail.widgets.RadioSelect",class extends a{boundWidgetClass=o});class l extends n{getTextLabel(){return this.input.find(":selected").text()}}window.telepath.register("wagtail.widgets.Select",class extends a{boundWidgetClass=l});class c{constructor(t,e,i,s){this.widget=t,this.blockDef=e,this.addSibling=i,this.split=s,this.blockMax=i.getBlockMax(e.name),this.icon=e.meta.icon,this.description=e.meta.label,this.type=e.name}render({option:t}){const e="number"==typeof blockMax?` (${this.addSibling.getBlockCount(this.blockDef.name)}/${this.blockMax})`:"";return`${t.description}${e}`}onSelect({editorState:t}){const e=window.draftail.splitState(window.draftail.DraftUtils.removeCommandPalettePrompt(t));e.stateAfter.getCurrentContent().hasText()?setTimeout((()=>{e&&this.split.fn(e.stateBefore,e.stateAfter,e.shouldMoveCommentFn),setTimeout((()=>{this.addSibling.fn({type:this.blockDef.name})}),20)}),50):(this.widget.setState(e.stateBefore),setTimeout((()=>{this.addSibling.fn({type:this.blockDef.name})}),20))}}class d{constructor(t,e){this.widget=t,this.split=e,this.description=(0,s.ih)("Split block")}icon="cut";type="split";onSelect({editorState:t}){const e=window.draftail.splitState(window.draftail.DraftUtils.removeCommandPalettePrompt(t));setTimeout((()=>{e&&this.split.fn(e.stateBefore,e.stateAfter,e.shouldMoveCommentFn)}),50)}}class u{constructor(t,e,i){this.input=t,this.capabilities=new Map(i),this.options=e;const[,s]=draftail.initEditor("#"+this.input.id,this.getFullOptions(),document.currentScript);this.setDraftailOptions=s}getValue(){return this.input.value}getState(){return this.input.draftailEditor.getEditorState()}setState(t){this.input.draftailEditor.onChange(t)}getTextLabel(t){const e=t&&t.maxLength;if(!this.input.value)return"";const i=JSON.parse(this.input.value);if(!i||!i.blocks)return"";let s="";for(const t of i.blocks)if(t.text&&(s+=s?" "+t.text:t.text,e&&s.length>e))return s.substring(0,e-1)+"…";return s}focus(){setTimeout((()=>{this.input.draftailEditor.focus()}),50)}setCapabilityOptions(t,e){const i=Object.assign(this.capabilities.get(t),e);this.capabilities.set(t,i),this.setDraftailOptions(this.getFullOptions())}getCapabilityOptions(t){const e={},i=t,n=i.get("split"),a=i.get("addSibling");let r=[];return n&&(r=(a&&a.enabled&&n.enabled?a.blockGroups:[]).map((([t,e])=>{const i=e.map((t=>new c(this,t,a,n)));return{label:t||(0,s.ih)("Blocks"),type:`streamfield-${t}`,items:i}})),n.enabled
|