-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
1 lines (1 loc) · 18.7 KB
/
index.js
1
!function(e){var t={};function r(s){if(t[s])return t[s].exports;var i=t[s]={i:s,l:!1,exports:{}};return e[s].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(s,i,function(t){return e[t]}.bind(null,i));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=21)}([function(e,t){t.login={},t.records=[],t.find=(e=>{const t=this.records.find(t=>t.$id.value===e);return t?JSON.parse(JSON.stringify(t)):null}),t.register=(e=>{if(e){const t=Math.max(...this.records.map(e=>e.$id.value))+1;return e.$id.value=t.toString(),this.records.push(JSON.parse(JSON.stringify(e))),t}return null}),t.update=(e=>{e&&(this.delete(e.$id.value),this.records.push(JSON.parse(JSON.stringify(e))))}),t.updateFieldById=((e,t,r)=>{const s=this.records.find(t=>t.$id.value===e);s&&(s[t].value=r)}),t.delete=(e=>{this.records=this.records.filter(t=>t.$id.value!==e)})},function(e,t){t.app={},t.views={},t.fields={},t.form={}},function(e,t,r){const s=r(1),i=r(0),n=r(3);e.exports=class extends n{constructor(e,t={}){if(super(e),!t.recordId)throw new Error("recordId option is required.");const r=i.find(t.recordId.toString());if(r){const e=JSON.parse(JSON.stringify(r));this.recordId=e.$id.value,this.record=e}}rollbackDisallowFields(){const e=["RECORD_NUMBER","CREATOR","CREATED_TIME","MODIFIER","UPDATED_TIME","STATUS","STATUS_ASSIGNEE","CALC","FILE"];this.record&&Object.keys(this.record).filter(e=>(e=>!!s.fields.properties&&Object.keys(s.fields.properties).some(t=>t===e))(e)).forEach(t=>{((t=>e.some(e=>e===s.fields.properties[t].type))(t)||(e=>"SINGLE_LINE_TEXT"===s.fields.properties[e].type&&s.fields.properties[e].expression)(t)||(e=>("SINGLE_LINE_TEXT"===s.fields.properties[e].type||"NUMBER"===s.fields.properties[e].type)&&s.fields.properties[e].lookup)(t)||(e=>{return Object.keys(s.fields.properties).filter(e=>s.fields.properties[e].lookup&&s.fields.properties[e].lookup.fieldMappings).map(e=>s.fields.properties[e].lookup.fieldMappings).some(t=>t.some(t=>t.field===e))})(t))&&(this.record[t].value=i.find(this.recordId)[t].value),"RADIO_BUTTON"===s.fields.properties[t].type&&""===this.record[t].value&&(this.record[t].value=s.fields.properties[t].defaultValue)})}}},function(e,t,r){const s=r(1);e.exports=class{constructor(e){this.appId=s.app.appId,this.type=e}}},function(e,t,r){const s=r(1);e.exports=class{constructor(e,t){this.type=e,this.data=t}getId(){const e=["app.record.detail","app.record.edit","app.record.print"];return this.data&&(()=>e.some(e=>this.type.startsWith(e)))()?this.data.$id.value:null}get(){const e=["app.record.detail","app.record.create","app.record.edit","app.record.print"];return this.data&&(()=>e.some(e=>this.type.startsWith(e)))()?JSON.parse(JSON.stringify({record:this.data})):null}set(e){const t=["app.record.create","app.record.edit"];(()=>t.some(e=>this.type.startsWith(e)))()&&(this.data=JSON.parse(JSON.stringify(e.record)))}setFieldShown(e,t){}setGroupFieldOpen(e,t){}getFieldElement(e){const t=["app.record.detail","app.record.print"];if((()=>t.some(e=>this.type.startsWith(e)))()&&s.fields.properties&&s.fields.properties[e]){const e=document.createElement("div");return document.body.appendChild(e),e}return null}getHeaderMenuSpaceElement(){return document.body}getSpaceElement(e){const t=["app.record.detail","app.record.create","app.record.edit","app.record.print"];if((()=>t.some(e=>this.type.startsWith(e)))()&&s.form.properties){if(Object.keys(s.form.properties).find(t=>{const r=s.form.properties[t];return"SPACER"===r.type&&r.elementId===e})){const e=document.createElement("div");return document.body.appendChild(e),e}}return null}}},function(e,t,r){const s=r(3);e.exports=class extends s{constructor(e,t={}){super(e,t)}}},function(e,t,r){const s=r(0),i=r(1),n=r(3);e.exports=class extends n{constructor(e,t={}){super(e);const{views:r}=i.views,n=r?Object.keys(r).map(e=>r[e]).find(e=>e.id===t.viewId):null;this.viewId=n?n.id:"20",this.viewName=n?n.name:"(すべて)",this.viewType=n?n.type.toLowerCase():"list";const o=()=>"calendar"===this.viewType;this.date=(()=>{if(!o())return null;if(t.date)return t.date;throw new Error("date option is required when selected calendar")})(),this.offset=o()?null:t.offset?t.offset:0,this.records=(()=>{if(o())return((e,t)=>JSON.parse(JSON.stringify(s.records)).filter(r=>r[e].value&&r[e].value.startsWith(t)).reduce((t,r)=>{if(r[e].value){const s=r[e].value.slice(0,10);t[s]||(t[s]=[]),t[s].push(r)}return t},{}))(n.date,this.date);const e=t.limit?t.limit:100;return JSON.parse(JSON.stringify(s.records)).slice(this.offset).slice(0,e)})(),this.size=o()?null:this.records.length}}},function(e,t,r){const s=r(0),i=r(2);e.exports=class e extends i{constructor(e,t={}){if(super(e,t),void 0===t.action)throw new Error("action option is required.");if(void 0===t.status)throw new Error("status option is required.");if(void 0===t.nextStatus)throw new Error("nextStatus option is required.");this.action={value:t.action},this.status={value:t.status},this.nextStatus={value:t.nextStatus},this.error=null,this.record&&(this.record.ステータス.value=this.nextStatus.value,s.update(this.record))}done(){!this.error&&this.record&&(this.rollbackDisallowFields(),s.update(this.record))}cancel(t){void 0!==t&&(!t.error&&t instanceof e||s.updateFieldById(this.recordId,"ステータス",this.status.value))}}},function(e,t,r){const s=r(0),i=r(2),n=e=>{const t=e.split(".");return t[t.length-1]};e.exports=class extends i{constructor(e,t={},r,i){if(super(e,t),void 0===t.value)throw new Error("value option is required.");this.changes={field:{type:r,value:t.value},row:{}},i&&this.record&&(this.record[n(this.type)].value=t.value,this.rollbackDisallowFields(),s.update(this.record))}done(){this.record&&(this.record[n(this.type)].value=this.changes.field.value,this.rollbackDisallowFields(),s.update(this.record))}static get TYPES(){return["RADIO_BUTTON","DROP_DOWN","CHECK_BOX","MULTI_SELECT","USER_SELECT","ORGANIZATION_SELECT","GROUP_SELECT","DATE","TIME","DATETIME","SINGLE_LINE_TEXT","NUMBER","SUBTABLE"]}}},function(e,t,r){const s=r(0),i=r(2);e.exports=class extends i{constructor(e,t={}){super(e,t)}done(){s.delete(this.recordId)}}},function(e,t,r){const s=r(2);e.exports=class extends s{constructor(e,t={}){super(e,t),this.url=null}}},function(e,t,r){const s=r(0),i=r(2);e.exports=class extends i{constructor(e,t={}){super(e,t)}done(){this.rollbackDisallowFields(),s.update(this.record)}}},function(e,t,r){const s=r(0),i=r(2);e.exports=class extends i{constructor(e,t={}){super(e,t),this.reuse=!1}done(){this.rollbackDisallowFields(),s.update(this.record)}}},function(e,t){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function s(e){return"function"==typeof e}function i(e){return"object"==typeof e&&null!==e}function n(e){return void 0===e}e.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!function(e){return"number"==typeof e}(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,r,o,a,c,p;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var d=new Error('Uncaught, unspecified "error" event. ('+t+")");throw d.context=t,d}if(n(r=this._events[e]))return!1;if(s(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),r.apply(this,a)}else if(i(r))for(a=Array.prototype.slice.call(arguments,1),o=(p=r.slice()).length,c=0;c<o;c++)p[c].apply(this,a);return!0},r.prototype.addListener=function(e,t){var o;if(!s(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,s(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned&&(o=n(this._maxListeners)?r.defaultMaxListeners:this._maxListeners)&&o>0&&this._events[e].length>o&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){if(!s(t))throw TypeError("listener must be a function");var r=!1;function i(){this.removeListener(e,i),r||(r=!0,t.apply(this,arguments))}return i.listener=t,this.on(e,i),this},r.prototype.removeListener=function(e,t){var r,n,o,a;if(!s(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(o=(r=this._events[e]).length,n=-1,r===t||s(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(r)){for(a=o;a-- >0;)if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}if(n<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(n,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(s(r=this._events[e]))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){return this._events&&this._events[e]?s(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(s(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},function(module,exports,__webpack_require__){const{EventEmitter:EventEmitter}=__webpack_require__(13),RecordEventObject=__webpack_require__(2),RecordEditEventObject=__webpack_require__(12),RecordEditSubmitEventObject=__webpack_require__(11),RecordEditSubmitSuccessEventObject=__webpack_require__(10),RecordDeleteEventObject=__webpack_require__(9),RecordChangeEventObject=__webpack_require__(8),RecordProcessEventObject=__webpack_require__(7),RecordsEventObject=__webpack_require__(6),ReportEventObject=__webpack_require__(5),schema=__webpack_require__(1),app={record:{index:{show:(e,t)=>new RecordsEventObject(e,t),edit:{show:(e,t)=>new RecordEventObject(e,t),submit:(e,t)=>new RecordEditSubmitEventObject(e,t),change:{}},delete:{submit:(e,t)=>new RecordDeleteEventObject(e,t)}},detail:{show:(e,t)=>new RecordEventObject(e,t),delete:{submit:(e,t)=>new RecordDeleteEventObject(e,t)},process:{proceed:(e,t)=>new RecordProcessEventObject(e,t)}},create:{show:(e,t)=>new RecordEditEventObject(e,t),submit:(e,t)=>new RecordEditSubmitEventObject(e,t),change:{}},edit:{show:(e,t)=>new RecordEditEventObject(e,t),submit:(e,t)=>new RecordEditSubmitEventObject(e,t),change:{}},print:{show:(e,t)=>new RecordEventObject(e,t)}},report:{show:(e,t)=>new ReportEventObject(e,t)}};app.record.index.edit.submit.success=((e,t)=>new RecordEditSubmitSuccessEventObject(e,t)),app.record.create.submit.success=((e,t)=>new RecordEditSubmitSuccessEventObject(e,t)),app.record.edit.submit.success=((e,t)=>new RecordEditSubmitSuccessEventObject(e,t));const appendFieldChangeEvent=event=>{const match=event.match(/^(app\.record\.(index\.edit|edit|create)\.change)\.([^.]+)$/);if(!match)return;const key=match[3];if(!schema.fields.properties||!schema.fields.properties[key])return;const{type:type}=schema.fields.properties[key];RecordChangeEventObject.TYPES.some(e=>e===type)&&(eval(`${match[1]}`)[key]=((e,t)=>new RecordChangeEventObject(e,t,type,"edit"!==match[2])))},removeFieldChangeEvent=event=>{if(event){const match=event.match(/^(app\.record\.(index\.edit|edit|create)\.change)\.([^.]+)$/);if(!match)return;const key=match[3];"function"==typeof eval(`${event}`)&&(eval(`${match[1]}`)[key]={})}else app.record.index.edit.change={},app.record.edit.change={},app.record.create.change={}},validate=event=>event.match(/^app\.(record|report)(\.(index|detail))?(\.(create|edit|delete|print))?(\.(show|change|submit|process))?(\.(success|proceed))?(\..+)?$/)?"function"==typeof eval(`${event}`)||(console.warn(`\nmissing event : ${event}`),!1):(console.warn(`\nno match event : ${event}`),!1);module.exports=class Event extends EventEmitter{emit(e,...t){const r=[];return this.listeners(e).forEach(e=>{r.push(e(...t))}),Promise.all(r)}async do(event,options){if(appendFieldChangeEvent(event),!validate(event))return null;const eventObj=eval(`${event}`)(event,options);await this.emit("event.do",event,options),await this.emit("event.type.changed",event,eventObj.record);const resolve=(await this.emit(event,eventObj)).pop();return resolve&&resolve.done&&resolve.done(),eventObj.cancel&&eventObj.cancel(resolve),resolve}off(e){e?this.removeAllListeners(e):this.removeAllListeners(),removeFieldChangeEvent(e)}}},function(e,t){const r=()=>{};r.upload=(()=>{}),e.exports=r},function(e,t){const r={app:{getConfig:()=>null,setConfig:(e,t)=>{t&&t()},getProxyConfig:()=>null,setProxyConfig:(e,t,r,s,i)=>{i&&i()},proxy(){}}};r.app.proxy.upload=(()=>{}),e.exports=r},function(e,t,r){const s=r(1),i=r(0);e.exports=class{constructor(e){this.params=e}do(e,t,r){"GET"===e?this.get(t,r):"POST"===e?this.post(t,r):"PUT"===e?this.put(t,r):r({message:`Invalid method [${e}]`})}get(e,t){if((()=>this.params.app&&this.params.app.toString()===s.app.appId&&this.params.id&&Number(this.params.id))()){const t=i.find(this.params.id.toString());if(t)return void e({record:t})}t({message:"Invalid params"})}post(e,t){if((()=>this.params.app&&this.params.app.toString()===s.app.appId&&this.params.record)()){return this.params.record.$id={type:"__ID__",value:""},this.params.record.$revision={type:"__REVISION__",value:""},Object.keys(s.fields.properties).filter(e=>{const t=s.fields.properties[e];return!("enabled"in t)||t.enabled}).forEach(e=>{if(!(e in this.params.record)){const t=s.fields.properties[e];this.params.record[e]={type:t.type,value:"CREATOR"===t.type||"MODIFIER"===t.type?{code:"",name:""}:"defaultValue"in t?t.defaultValue:""}}}),void e({id:i.register(this.params.record).toString(),revision:"1"})}t({message:"Invalid params"})}put(e,t){const r=()=>{if(this.params.id)return i.find(this.params.id.toString());const{field:e}=this.params.updateKey,{value:t}=this.params.updateKey,r=i.records.find(r=>r[e].value===t);return i.find(r.$id.value)};if((()=>!(!this.params.app&&this.params.app.toString()!==s.app.appId||this.params.revision&&"-1"!==this.params.revision.toString()&&this.params.revision.toString()!==r().$revision.value||!(!this.params.updateKey||s.fields.properties[this.params.updateKey.field]&&s.fields.properties[this.params.updateKey.field].unique)))()){const t=r();return this.params.record&&(Object.keys(this.params.record).forEach(e=>{i.updateFieldById(t.$id.value,e,this.params.record[e].value)}),t.$revision.value=(Number(t.$revision.value)+1).toString()),void e({revision:t.$revision.value})}t({message:"Invalid params"})}}},function(e,t,r){const s=r(17),i=(e,t,r,i,n)=>{const o="/k/v1/record"===e?new s(r):null,a=(e,r)=>o?o.do(t,e,r):r({message:"Invalid pathOrUrl"});return i&&n?a(i,n):new Promise((e,t)=>a(e,t))};i.url=((e,t=!1)=>t?`https://dummy.cybozu.com/k/guest/1${e.replace(/\/k/,"")}.json`:`https://dummy.cybozu.com${e}.json`),i.urlForGet=((e,t,r=!1)=>{const s=e=>Object.keys(e).reduce((t,r)=>(Array.isArray(e[r])?t.push(...e[r].map((e,t)=>`${r}[${t}]=${e}`)):e[r]instanceof Object?t.push(s(e[r]).map(e=>`${r}.${e}`)):t.push(`${r}=${e[r].toString()}`),t),[]),i=s(t).toString().replace(/,/g,"&");return r?`https://dummy.cybozu.com/k/guest/1${e.replace(/\/k/,"")}.json?${i}`:`https://dummy.cybozu.com${e}.json?${i}`}),i.getConcurrencyLimit=(()=>new Promise(e=>e({limit:0,running:0}))),e.exports=i},function(e,t,r){const s=r(4),i=r(1),n=r(0),o=e=>{try{return void 0!==e()}catch(e){return!1}};e.exports=class{constructor(){this.record=new s}getId(){return i.app.appId||null}getFieldElements(){}static FieldElements(e){return["app.record.index"].some(t=>e.startsWith(t))&&i.fields.properties?0===n.records.length?e=>[]:e=>{if(!i.fields.properties[e])return null;return[...function*(){for(let e=0;e<n.records.length;e+=1){const e=document.createElement("div");document.body.appendChild(e),yield e}}()]}:e=>null}getHeaderSpaceElement(){}getHeaderMenuSpaceElement(){}static HeaderSpaceElement(e){return["app.record.index"].some(t=>e.startsWith(t))?()=>document.body:()=>null}getLookupTargetAppId(e){return o(()=>i.fields.properties[e].lookup.relatedApp.app)?i.fields.properties[e].lookup.relatedApp.app:null}getRelatedRecordsTargetAppId(e){return o(()=>i.fields.properties[e].referenceTable.relatedApp.app)?i.fields.properties[e].referenceTable.relatedApp.app:null}getQuery(){}getQueryCondition(){}static QueryCondition(e,t){if(!["app.record.index","app.report"].some(t=>e.startsWith(t)))return()=>null;const{views:r}=i.views,s=r?Object.keys(r).map(e=>r[e]).find(e=>e.id===t):null;return()=>s?s.filterCond:""}}},function(e,t){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){(function(e){const t=r(19),s=r(18),i=r(4),n=r(16),o=r(15),a=r(14),c=r(1),p=r(0),d=(e,t={})=>{try{return JSON.parse(e)}catch(e){return t}};e.kintone=new class{constructor(){this.app=new t,this.api=s,this.plugin=n,this.proxy=o,this.events=new a,this.Promise=Promise,this.events.on("event.do",(e,r)=>{this.app.getFieldElements=t.FieldElements(e),this.app.getHeaderSpaceElement=t.HeaderSpaceElement(e),this.app.getHeaderMenuSpaceElement=t.HeaderSpaceElement(e),this.app.getQuery=t.QueryCondition(e,r?r.viewId:null),this.app.getQueryCondition=t.QueryCondition(e,r?r.viewId:null)}),this.events.on("event.type.changed",(e,t)=>{this.app.record=new i(e,t)}),this.schema={app:{set:e=>{c.app=d(e)}},fields:{set:e=>{c.fields=d(e)}},form:{set:e=>{c.form=d(e)}},views:{set:e=>{c.views=d(e)}}},this.fixture={login:{set:e=>{p.login=d(e)}},records:{set:e=>{p.records=d(e,[])}}}}getLoginUser(){return p.login}getUiVersion(){return 2}}}).call(this,r(20))}]);