electron-react-titlebar
Advanced tools
Comparing version 1.0.0-beta.4 to 1.0.0
@@ -1,2 +0,2 @@ | ||
(()=>{"use strict";var e={d:(n,o)=>{for(var r in o)e.o(o,r)&&!e.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:o[r]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};e.r(n),e.d(n,{initialize:()=>r});const o=require("electron");var r=function(){o.ipcMain.on("electron-react-titlebar/initialize",(function(e,n){console.log(n);var r=n?o.BrowserWindow.fromId(n):o.BrowserWindow.fromWebContents(e.sender);console.log(r);var i=function(){return null==r?void 0:r.webContents.send("electron-react-titlebar/maximunize/change",r.isMaximized())};null==r||r.on("maximize",i),null==r||r.on("unmaximize",i)})),o.ipcMain.on("electron-react-titlebar/maximumize/set",(function(e,n){var r=n?o.BrowserWindow.fromId(n):o.BrowserWindow.fromWebContents(e.sender);null!=r&&r.isMaximizable()&&(r.isMaximized()?r.unmaximize():r.maximize())})),o.ipcMain.on("electron-react-titlebar/minimumize/set",(function(e,n){var r=n?o.BrowserWindow.fromId(n):o.BrowserWindow.fromWebContents(e.sender);null==r||r.minimize()})),o.ipcMain.on("electron-react-titlebar/close",(function(e,n){var r=n?o.BrowserWindow.fromId(n):o.BrowserWindow.fromWebContents(e.sender);null==r||r.close()}))};module.exports=n})(); | ||
(()=>{"use strict";var e={d:(n,r)=>{for(var i in r)e.o(r,i)&&!e.o(n,i)&&Object.defineProperty(n,i,{enumerable:!0,get:r[i]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};e.r(n),e.d(n,{initialize:()=>i});const r=require("electron");var i=function(){r.ipcMain.on("electron-react-titlebar/initialize",(function(e,n){var i=n?r.BrowserWindow.fromId(n):r.BrowserWindow.fromWebContents(e.sender);i&&(function(e,n){e.addListener("maximize",(function(){n.send("electron-react-titlebar/maximunize/change",!0,e.id)})),e.addListener("unmaximize",(function(){n.send("electron-react-titlebar/maximunize/change",!1,e.id)}))}(i,e.sender),e.sender.send("electron-react-titlebar/browser-window-id",i.id))})),r.ipcMain.on("electron-react-titlebar/maximumize/set",(function(e,n){var i=n?r.BrowserWindow.fromId(n):r.BrowserWindow.fromWebContents(e.sender);null!=i&&i.isMaximizable()&&(i.isMaximized()?i.unmaximize():i.maximize())})),r.ipcMain.on("electron-react-titlebar/minimumize/set",(function(e,n){var i=n?r.BrowserWindow.fromId(n):r.BrowserWindow.fromWebContents(e.sender);null==i||i.minimize()})),r.ipcMain.on("electron-react-titlebar/close",(function(e,n){var i=n?r.BrowserWindow.fromId(n):r.BrowserWindow.fromWebContents(e.sender);null==i||i.close()}))};module.exports=n})(); | ||
//# sourceMappingURL=main.js.map |
@@ -1,2 +0,2 @@ | ||
(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{MenuBarProps:()=>o.MenuBarProps,MenuItemT:()=>n.MenuItemT,MenuListItemProps:()=>n.MenuListItemProps,MenuListProps:()=>a.MenuListProps,MenuT:()=>o.MenuT,TitleBar:()=>L,TitleBarProps:()=>i.TitleBarProps,WindowControlsProps:()=>r.WindowControlsProps});var r={};e.r(r),e.d(r,{h:()=>m});var n={};e.r(n),e.d(n,{M:()=>C});var a={};e.r(a),e.d(a,{q:()=>N});var o={};e.r(o),e.d(o,{j:()=>D});var i={};e.r(i),e.d(i,{T:()=>L});const l=require("react");var c=e.n(l);const u=require("electron");function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var m=function(e){var t,r,n=e.disableMaximize,a=e.disableMinimize,o=e.browserWindowId,i=(t=(0,l.useState)(!1),r=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o=[],i=!0,l=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);i=!0);}catch(e){l=!0,a=e}finally{try{i||null==r.return||r.return()}finally{if(l)throw a}}return o}}(t,r)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),m=i[0],d=i[1];(0,l.useEffect)((function(){return u.ipcRenderer.on("electron-react-titlebar/maximunize/change",(function(e,t){console.log(),d(t)})),u.ipcRenderer.send("electron-react-titlebar/initialize",o),function(){u.ipcRenderer.removeAllListeners("electron-react-titlebar/maximunize/change"),u.ipcRenderer.send("electron-react-titlebar/deinitialize",o)}}),[o]);var f=(0,l.useCallback)((function(){u.ipcRenderer.send("electron-react-titlebar/maximumize/set",o)}),[o]),b=(0,l.useCallback)((function(){u.ipcRenderer.send("electron-react-titlebar/minimumize/set",o)}),[o]),p=(0,l.useCallback)((function(){u.ipcRenderer.send("electron-react-titlebar/close",o)}),[o]);return c().createElement("div",{className:"window-controls"},c().createElement("button",{"aria-label":"minimize",tabIndex:-1,className:"window-control window-minimize",disabled:a,onClick:b},c().createElement("svg",{"aria-hidden":"true",version:"1.1",width:"10",height:"10"},c().createElement("path",{d:"M 0,5 10,5 10,6 0,6 Z"}))),c().createElement("button",{"aria-label":"maximize",tabIndex:-1,className:"window-control window-maximize",disabled:n,onClick:f},c().createElement("svg",{"aria-hidden":"true",version:"1.1",width:"10",height:"10"},c().createElement("path",{d:m?"m 2,1e-5 0,2 -2,0 0,8 8,0 0,-2 2,0 0,-8 z m 1,1 6,0 0,6 -1,0 0,-5 -5,0 z m -2,2 6,0 0,6 -6,0 z":"M 0,0 0,10 10,10 10,0 Z M 1,1 9,1 9,9 1,9 Z"}))),c().createElement("button",{"aria-label":"close",tabIndex:-1,className:"window-control window-close",onClick:p},c().createElement("svg",{"aria-hidden":"true",version:"1.1",width:"10",height:"10"},c().createElement("path",{d:"M 0,0 0,0.7 4.3,5 0,9.3 0,10 0.7,10 5,5.7 9.3,10 10,10 10,9.3 5.7,5 10,0.7 10,0 9.3,0 5,4.3 0.7,0 Z"}))))};const d=require("classnames");var f=e.n(d);const b=require("lodash");function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){h(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function h(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function v(e){return function(e){if(Array.isArray(e))return g(e)}(e)||E(e)||w(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(e,t){if(e){if("string"==typeof e)return g(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(e,t):void 0}}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function E(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function O(e,t,r){var n,a,o=function(e){if(Array.isArray(e))return e}(a=t)||E(a)||w(a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),i=o[0],l=o.slice(1);if(void 0===i)return(0,b.isEqual)(e,r)?e:r;var c=O(n=i in e?e[i]:{},l,r);return c!==n?Array.isArray(e)?[].concat(v(e.slice(0,i)),[c],v(e.slice(i+1,e.length))):y(y({},e),{},h({},i,c)):e}const j=require("react-virtualized");function S(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function x(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?S(Object(r),!0).forEach((function(t){k(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):S(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function k(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function I(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var M=c().createElement("svg",{width:"1792",height:"1792",viewBox:"0 0 1792 1792",xmlns:"http://www.w3.org/2000/svg"},c().createElement("path",{d:"M1671 566q0 40-28 68l-724 724-136 136q-28 28-68 28t-68-28l-136-136-362-362q-28-28-28-68t28-68l136-136q28-28 68-28t68 28l294 295 656-657q28-28 68-28t68 28l136 136q28 28 28 68z"})),A=c().createElement("span",null),P=c().createElement("svg",{width:"1792",height:"1792",viewBox:"0 0 1792 1792",xmlns:"http://www.w3.org/2000/svg"},c().createElement("path",{d:"M896 352q-148 0-273 73t-198 198-73 273 73 273 198 198 273 73 273-73 198-198 73-273-73-273-198-198-273-73zm768 544q0 209-103 385.5t-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103 385.5 103 279.5 279.5 103 385.5z"})),z=c().createElement("svg",{width:"1792",height:"1792",viewBox:"0 0 1792 1792",xmlns:"http://www.w3.org/2000/svg"},c().createElement("path",{d:"M1152 896q0 106-75 181t-181 75-181-75-75-181 75-181 181-75 181 75 75 181zm-256-544q-148 0-273 73t-198 198-73 273 73 273 198 198 273 73 273-73 198-198 73-273-73-273-198-198-273-73zm768 544q0 209-103 385.5t-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103 385.5 103 279.5 279.5 103 385.5z"})),C=function(e){var t,r,n=e.mainIndex,a=e.subIndex,o=e.curItem,i=e.style,u=e.changeCheckState,s=(t=(0,l.useState)(!1),r=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o=[],i=!0,l=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);i=!0);}catch(e){l=!0,a=e}finally{try{i||null==r.return||r.return()}finally{if(l)throw a}}return o}}(t,r)||function(e,t){if(e){if("string"==typeof e)return I(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?I(e,t):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),m=s[0],d=s[1],b=(0,l.useCallback)((function(e){if("separator"!==o.type&&!1!==o.enabled)if("checkbox"===o.type){e.persist();var t=x(x({},o),{},{checked:!o.checked});o.click(t,e),u(n,a,!o.checked)}else if("radio"===o.type){var r=x(x({},o),{},{checked:!0});o.click(r,e),o.checked||u(n,a,!0,!0)}else e.persist(),o.click(o,e);else e.stopPropagation()}),[]);if(0==o.visiable)return c().createElement("div",null);var p=f()("list-item",{selected:m&&"separator"!==o.type&&!1!==o.enabled}),y=f()("menu-item",{disabled:"separator"!==o.type&&!1===o.enabled}),h="separator"===o.type?c().createElement("hr",null):c().createElement("div",{className:y,onClick:b},c().createElement("div",{className:"status-icon"},"radio"===o.type?o.checked?z:P:o.checked&&"checkbox"===o.type?M:A),c().createElement("div",{className:"menu-label"},c().createElement("span",null,o.label)),o.accelerator&&c().createElement("div",{className:"accelerator"},o.accelerator));return c().createElement("div",{role:"menuitem",className:p,style:i,tabIndex:-1,onMouseOver:function(){return d(!0)},onMouseLeave:function(){return d(!1)}},h)},N=function(e){var t=e.rect,r=e.mainIndex,n=e.menulist,a=e.changeCheckState,o=(0,l.useCallback)((function(e){var t=e.index,r=n[t];return!1===r.visiable?0:"separator"===r.type?10:30}),[n]),i=(0,l.useCallback)((function(e){var t=e.key,o=e.rowIndex,i=e.style;return c().createElement(C,{key:t,curItem:n[o],style:i,changeCheckState:a,mainIndex:r,subIndex:o})}),[n,a,r]),u=n.map((function(e,t){return o({index:t})})).reduce((function(e,t){return e+t}),0);return c().createElement("div",{id:"foldout-container",style:{position:"absolute",top:t.bottom,left:0,width:"100%",height:"calc(100% - ".concat(t.bottom,"px)")}},c().createElement("div",{className:"overlay",tabIndex:-1}),c().createElement("div",{className:"foldout",style:{position:"absolute",marginLeft:t.left,maxWidth:"calc(100% - ".concat(t.left,"px)"),height:"100%",overflow:"hidden",top:0}},c().createElement("div",{id:"app-menu-foldout"},c().createElement("div",{className:"menu-pane",style:{height:u,maxHeight:"100%"}},c().createElement("div",{className:"list",role:"menu"},c().createElement(j.Grid,{cellRenderer:i,columnCount:1,rowCount:n.length,columnWidth:240,height:u,rowHeight:o,width:240})),c().createElement("div",{className:"menu-pane menu-endblock"})))))};function q(e){return function(e){if(Array.isArray(e))return B(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||R(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function T(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o=[],i=!0,l=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);i=!0);}catch(e){l=!0,a=e}finally{try{i||null==r.return||r.return()}finally{if(l)throw a}}return o}}(e,t)||R(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function R(e,t){if(e){if("string"==typeof e)return B(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?B(e,t):void 0}}function B(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var D=function(e){var t=e.menu,r=T((0,l.useState)(!1),2),n=r[0],a=r[1],o=T((0,l.useState)(0),2),i=o[0],u=o[1],s=T((0,l.useState)(t),2),m=s[0],d=s[1],b=(0,l.useRef)(!1),p=(0,l.useRef)({}),y=(0,l.useCallback)((function(e){n&&u(e)}),[n]),h=(0,l.useCallback)((function(e){b.current?b.current=!1:a(!(i===e&&n))}),[n,i]),v=(0,l.useCallback)((function(e){e!==i&&n&&(b.current=!0)}),[n,i]);(0,l.useEffect)((function(){d(t)}),[t]);var w=function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(n){for(var a=q(m),o=m[e].submenu.length,i=0;i<o;i++)"radio"===m[e].submenu[i].type&&(a=O(a,[e,"submenu",i,"checked"],i===t));d(a)}else d(O(m,[e,"submenu",t,"checked"],r))};return c().createElement("div",{id:"app-menu-bar",role:"menubar","aria-label":"Application menu"},m.map((function(e,t){var r;return c().createElement("div",{key:t,onMouseOver:function(){return y(t)},onClick:function(){return h(t)},onTouchStart:function(){return v(t)},onMouseMove:function(){return function(e){u(e)}(t)},ref:function(e){return e&&function(e,t){p.current[t]=e}(e,t)},className:f()("toolbar-dropdown",{open:n&&t===i,closed:!n||t!==i})},n&&t===i&&c().createElement(N,{rect:null===(r=p.current[t])||void 0===r?void 0:r.getBoundingClientRect(),menulist:e.submenu,changeCheckState:w,mainIndex:t}),c().createElement("div",{className:"toolbar-button"},c().createElement("button",{className:"button-component",type:"button",tabIndex:-1},c().createElement("div",{className:"menu-item"},c().createElement("div",{className:"menu-label"},c().createElement("span",{"aria-label":"View"},c().createElement("span",{"aria-hidden":"true"},e.label)))))))})))},L=function(e){var t=e.children,r=e.icon,n=e.menu,a=e.disableMinimize,o=e.disableMaximize,i=e.className,l=e.browserWindowId;return c().createElement("div",{id:"electron-app-title-bar",className:"electron-app-title-bar ".concat(i||"")},c().createElement("div",{className:"resize-handle resize-handle-top"}),c().createElement("div",{className:"resize-handle resize-handle-left"}),!!r&&c().createElement("img",{className:"icon",src:r}),!!n&&c().createElement(D,{menu:n}),t,c().createElement(m,{disableMinimize:a,disableMaximize:o,browserWindowId:l}))};module.exports=t})(); | ||
(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{MenuBarProps:()=>o.MenuBarProps,MenuItemT:()=>n.MenuItemT,MenuListItemProps:()=>n.MenuListItemProps,MenuListProps:()=>a.MenuListProps,MenuT:()=>o.MenuT,TitleBar:()=>L,TitleBarProps:()=>i.TitleBarProps,WindowControlsProps:()=>r.WindowControlsProps});var r={};e.r(r),e.d(r,{h:()=>m});var n={};e.r(n),e.d(n,{M:()=>C});var a={};e.r(a),e.d(a,{q:()=>N});var o={};e.r(o),e.d(o,{j:()=>D});var i={};e.r(i),e.d(i,{T:()=>L});const l=require("react");var c=e.n(l);const u=require("electron");function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var m=function(e){var t,r,n=e.disableMaximize,a=e.disableMinimize,o=e.browserWindowId,i=(t=(0,l.useState)(!1),r=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o=[],i=!0,l=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);i=!0);}catch(e){l=!0,a=e}finally{try{i||null==r.return||r.return()}finally{if(l)throw a}}return o}}(t,r)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),m=i[0],d=i[1],f=(0,l.useRef)(o);(0,l.useEffect)((function(){var e=function(e,t,r){r===f.current&&d(t)};return u.ipcRenderer.on("electron-react-titlebar/maximunize/change",e),u.ipcRenderer.once("electron-react-titlebar/browser-window-id",(function(e,t){f.current=t})),u.ipcRenderer.send("electron-react-titlebar/initialize",o),function(){u.ipcRenderer.removeListener("electron-react-titlebar/maximunize/change",e),u.ipcRenderer.send("electron-react-titlebar/deinitialize",o)}}),[o]);var b=(0,l.useCallback)((function(){u.ipcRenderer.send("electron-react-titlebar/maximumize/set",o)}),[o]),p=(0,l.useCallback)((function(){u.ipcRenderer.send("electron-react-titlebar/minimumize/set",o)}),[o]),y=(0,l.useCallback)((function(){u.ipcRenderer.send("electron-react-titlebar/close",o)}),[o]);return c().createElement("div",{className:"window-controls"},c().createElement("button",{"aria-label":"minimize",tabIndex:-1,className:"window-control window-minimize",disabled:a,onClick:p},c().createElement("svg",{"aria-hidden":"true",version:"1.1",width:"10",height:"10"},c().createElement("path",{d:"M 0,5 10,5 10,6 0,6 Z"}))),c().createElement("button",{"aria-label":"maximize",tabIndex:-1,className:"window-control window-maximize",disabled:n,onClick:b},c().createElement("svg",{"aria-hidden":"true",version:"1.1",width:"10",height:"10"},c().createElement("path",{d:m?"m 2,1e-5 0,2 -2,0 0,8 8,0 0,-2 2,0 0,-8 z m 1,1 6,0 0,6 -1,0 0,-5 -5,0 z m -2,2 6,0 0,6 -6,0 z":"M 0,0 0,10 10,10 10,0 Z M 1,1 9,1 9,9 1,9 Z"}))),c().createElement("button",{"aria-label":"close",tabIndex:-1,className:"window-control window-close",onClick:y},c().createElement("svg",{"aria-hidden":"true",version:"1.1",width:"10",height:"10"},c().createElement("path",{d:"M 0,0 0,0.7 4.3,5 0,9.3 0,10 0.7,10 5,5.7 9.3,10 10,10 10,9.3 5.7,5 10,0.7 10,0 9.3,0 5,4.3 0.7,0 Z"}))))};const d=require("classnames");var f=e.n(d);const b=require("lodash");function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){h(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function h(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function v(e){return function(e){if(Array.isArray(e))return g(e)}(e)||E(e)||w(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(e,t){if(e){if("string"==typeof e)return g(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(e,t):void 0}}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function E(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function O(e,t,r){var n,a,o=function(e){if(Array.isArray(e))return e}(a=t)||E(a)||w(a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),i=o[0],l=o.slice(1);if(void 0===i)return(0,b.isEqual)(e,r)?e:r;var c=O(n=i in e?e[i]:{},l,r);return c!==n?Array.isArray(e)?[].concat(v(e.slice(0,i)),[c],v(e.slice(i+1,e.length))):y(y({},e),{},h({},i,c)):e}const j=require("react-virtualized");function S(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function x(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?S(Object(r),!0).forEach((function(t){k(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):S(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function k(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function I(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var M=c().createElement("svg",{width:"1792",height:"1792",viewBox:"0 0 1792 1792",xmlns:"http://www.w3.org/2000/svg"},c().createElement("path",{d:"M1671 566q0 40-28 68l-724 724-136 136q-28 28-68 28t-68-28l-136-136-362-362q-28-28-28-68t28-68l136-136q28-28 68-28t68 28l294 295 656-657q28-28 68-28t68 28l136 136q28 28 28 68z"})),A=c().createElement("span",null),P=c().createElement("svg",{width:"1792",height:"1792",viewBox:"0 0 1792 1792",xmlns:"http://www.w3.org/2000/svg"},c().createElement("path",{d:"M896 352q-148 0-273 73t-198 198-73 273 73 273 198 198 273 73 273-73 198-198 73-273-73-273-198-198-273-73zm768 544q0 209-103 385.5t-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103 385.5 103 279.5 279.5 103 385.5z"})),z=c().createElement("svg",{width:"1792",height:"1792",viewBox:"0 0 1792 1792",xmlns:"http://www.w3.org/2000/svg"},c().createElement("path",{d:"M1152 896q0 106-75 181t-181 75-181-75-75-181 75-181 181-75 181 75 75 181zm-256-544q-148 0-273 73t-198 198-73 273 73 273 198 198 273 73 273-73 198-198 73-273-73-273-198-198-273-73zm768 544q0 209-103 385.5t-279.5 279.5-385.5 103-385.5-103-279.5-279.5-103-385.5 103-385.5 279.5-279.5 385.5-103 385.5 103 279.5 279.5 103 385.5z"})),C=function(e){var t,r,n=e.mainIndex,a=e.subIndex,o=e.curItem,i=e.style,u=e.changeCheckState,s=(t=(0,l.useState)(!1),r=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o=[],i=!0,l=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);i=!0);}catch(e){l=!0,a=e}finally{try{i||null==r.return||r.return()}finally{if(l)throw a}}return o}}(t,r)||function(e,t){if(e){if("string"==typeof e)return I(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?I(e,t):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),m=s[0],d=s[1],b=(0,l.useCallback)((function(e){if("separator"!==o.type&&!1!==o.enabled)if("checkbox"===o.type){e.persist();var t=x(x({},o),{},{checked:!o.checked});o.click(t,e),u(n,a,!o.checked)}else if("radio"===o.type){var r=x(x({},o),{},{checked:!0});o.click(r,e),o.checked||u(n,a,!0,!0)}else e.persist(),o.click(o,e);else e.stopPropagation()}),[]);if(0==o.visiable)return c().createElement("div",null);var p=f()("list-item",{selected:m&&"separator"!==o.type&&!1!==o.enabled}),y=f()("menu-item",{disabled:"separator"!==o.type&&!1===o.enabled}),h="separator"===o.type?c().createElement("hr",null):c().createElement("div",{className:y,onClick:b},c().createElement("div",{className:"status-icon"},"radio"===o.type?o.checked?z:P:o.checked&&"checkbox"===o.type?M:A),c().createElement("div",{className:"menu-label"},c().createElement("span",null,o.label)),o.accelerator&&c().createElement("div",{className:"accelerator"},o.accelerator));return c().createElement("div",{role:"menuitem",className:p,style:i,tabIndex:-1,onMouseOver:function(){return d(!0)},onMouseLeave:function(){return d(!1)}},h)},N=function(e){var t=e.rect,r=e.mainIndex,n=e.menulist,a=e.changeCheckState,o=(0,l.useCallback)((function(e){var t=e.index,r=n[t];return!1===r.visiable?0:"separator"===r.type?10:30}),[n]),i=(0,l.useCallback)((function(e){var t=e.key,o=e.rowIndex,i=e.style;return c().createElement(C,{key:t,curItem:n[o],style:i,changeCheckState:a,mainIndex:r,subIndex:o})}),[n,a,r]),u=n.map((function(e,t){return o({index:t})})).reduce((function(e,t){return e+t}),0);return c().createElement("div",{id:"foldout-container",style:{position:"absolute",top:t.bottom,left:0,width:"100%",height:"calc(100% - ".concat(t.bottom,"px)")}},c().createElement("div",{className:"overlay",tabIndex:-1}),c().createElement("div",{className:"foldout",style:{position:"absolute",marginLeft:t.left,maxWidth:"calc(100% - ".concat(t.left,"px)"),height:"100%",overflow:"hidden",top:0}},c().createElement("div",{id:"app-menu-foldout"},c().createElement("div",{className:"menu-pane",style:{height:u,maxHeight:"100%"}},c().createElement("div",{className:"list",role:"menu"},c().createElement(j.Grid,{cellRenderer:i,columnCount:1,rowCount:n.length,columnWidth:240,height:u,rowHeight:o,width:240})),c().createElement("div",{className:"menu-pane menu-endblock"})))))};function q(e){return function(e){if(Array.isArray(e))return B(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||R(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function T(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o=[],i=!0,l=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(o.push(n.value),!t||o.length!==t);i=!0);}catch(e){l=!0,a=e}finally{try{i||null==r.return||r.return()}finally{if(l)throw a}}return o}}(e,t)||R(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function R(e,t){if(e){if("string"==typeof e)return B(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?B(e,t):void 0}}function B(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var D=function(e){var t=e.menu,r=T((0,l.useState)(!1),2),n=r[0],a=r[1],o=T((0,l.useState)(0),2),i=o[0],u=o[1],s=T((0,l.useState)(t),2),m=s[0],d=s[1],b=(0,l.useRef)(!1),p=(0,l.useRef)({}),y=(0,l.useCallback)((function(e){n&&u(e)}),[n]),h=(0,l.useCallback)((function(e){b.current?b.current=!1:a(!(i===e&&n))}),[n,i]),v=(0,l.useCallback)((function(e){e!==i&&n&&(b.current=!0)}),[n,i]);(0,l.useEffect)((function(){d(t)}),[t]);var w=function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(n){for(var a=q(m),o=m[e].submenu.length,i=0;i<o;i++)"radio"===m[e].submenu[i].type&&(a=O(a,[e,"submenu",i,"checked"],i===t));d(a)}else d(O(m,[e,"submenu",t,"checked"],r))};return c().createElement("div",{id:"app-menu-bar",role:"menubar","aria-label":"Application menu"},m.map((function(e,t){var r;return c().createElement("div",{key:t,onMouseOver:function(){return y(t)},onClick:function(){return h(t)},onTouchStart:function(){return v(t)},onMouseMove:function(){return function(e){u(e)}(t)},ref:function(e){return e&&function(e,t){p.current[t]=e}(e,t)},className:f()("toolbar-dropdown",{open:n&&t===i,closed:!n||t!==i})},n&&t===i&&c().createElement(N,{rect:null===(r=p.current[t])||void 0===r?void 0:r.getBoundingClientRect(),menulist:e.submenu,changeCheckState:w,mainIndex:t}),c().createElement("div",{className:"toolbar-button"},c().createElement("button",{className:"button-component",type:"button",tabIndex:-1},c().createElement("div",{className:"menu-item"},c().createElement("div",{className:"menu-label"},c().createElement("span",{"aria-label":"View"},c().createElement("span",{"aria-hidden":"true"},e.label)))))))})))},L=function(e){var t=e.children,r=e.icon,n=e.menu,a=e.disableMinimize,o=e.disableMaximize,i=e.className,l=e.browserWindowId;return c().createElement("div",{id:"electron-app-title-bar",className:"electron-app-title-bar ".concat(i||"")},c().createElement("div",{className:"resize-handle resize-handle-top"}),c().createElement("div",{className:"resize-handle resize-handle-left"}),!!r&&c().createElement("img",{className:"icon",src:r}),!!n&&c().createElement(D,{menu:n}),t,c().createElement(m,{disableMinimize:a,disableMaximize:o,browserWindowId:l}))};module.exports=t})(); | ||
//# sourceMappingURL=renderer.js.map |
{ | ||
"name": "electron-react-titlebar", | ||
"version": "1.0.0-beta.4", | ||
"version": "1.0.0", | ||
"description": "A github desktop style title bar component for electron.", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"./renderer": "./dist/renderer.js", | ||
"./style/style.css": "./assets/style.css" | ||
"./assets/style.css": "./assets/style.css" | ||
}, | ||
@@ -12,0 +12,0 @@ "scripts": { |
@@ -14,6 +14,5 @@ # electron-react-titlebar | ||
You should have electron installed first. | ||
``` | ||
electron app | ||
npm run build | ||
npm run demo | ||
``` | ||
@@ -23,6 +22,14 @@ | ||
### If you are using webpack | ||
### Main process | ||
```javascript | ||
import { TitleBar } from 'electron-react-titlebar' | ||
app.on('ready', () => { | ||
require('electron-react-titlebar/main').initialize() | ||
}) | ||
``` | ||
#### If you are using webpack | ||
```javascript | ||
import { TitleBar } from 'electron-react-titlebar/renderer' | ||
import 'electron-react-titlebar/assets/style.css' | ||
@@ -36,3 +43,3 @@ | ||
### If you're not a webpack user and wants to load css directly | ||
#### If you're not a webpack user and wants to load css directly | ||
@@ -66,5 +73,5 @@ ```js | ||
### currentWindow?: \<BrowserWindow\> | ||
### browserWindowId?: number | ||
The browserWindow Object that window controls affect to. Default value is `remote.currentWindow()` (optional). | ||
The browserWindow's id that window controls affect to. Default value is the browserWindow that renders the component (optional). | ||
@@ -76,6 +83,6 @@ ### menu?: \<MenuTemplate\> | ||
Note: electron-react-titlebar is supporting a subset of [Electron's MenuItem](https://github.com/electron/electron/blob/master/docs/api/menu-item.md). | ||
P | ||
Supported options: | ||
* `click` - supported | ||
* `click` - supported, but the parameter only returns `item` and `event` | ||
* `type` - `submenu` is not supported. | ||
@@ -86,1 +93,15 @@ * `label` - supported | ||
* `checked` - supported | ||
## Breaking changes since v1.0.0 | ||
The v1.0.0 version contains following breaking changes: | ||
- Requires `React@16.8` or newer version | ||
- Due to the Electron's removal of remote module since version 14, electron-react-titlebar now: | ||
- Needs to initialize in main process (See example above) | ||
- The require path of component has changed to `electron-react-titlebar/renderer` | ||
- The `currentWindow` prop has been removed, instead you can control your browserWindow by `browserWindowId` prop | ||
- The second parameter of callback of menuItem's click handler (the browserWindow) has been removed | ||
If you're still using Electron below 14 and don't want to take breaking changes, you can still use 0.x version of electron-react-titlebar. |
@@ -1,11 +0,19 @@ | ||
import { ipcMain, BrowserWindow } from 'electron' | ||
import { ipcMain, BrowserWindow, WebContents } from 'electron' | ||
const setupEventListener = (browserWindow: BrowserWindow, sender: WebContents) => { | ||
browserWindow.addListener('maximize', () => { | ||
sender.send('electron-react-titlebar/maximunize/change', true, browserWindow.id) | ||
}) | ||
browserWindow.addListener('unmaximize', () => { | ||
sender.send('electron-react-titlebar/maximunize/change', false, browserWindow.id) | ||
}) | ||
} | ||
export const initialize = (): void => { | ||
ipcMain.on('electron-react-titlebar/initialize', (event, browserWindowId) => { | ||
console.log(browserWindowId) | ||
const browserWindow = browserWindowId ? BrowserWindow.fromId(browserWindowId) : BrowserWindow.fromWebContents(event.sender) | ||
console.log(browserWindow) | ||
const callback = () => browserWindow?.webContents.send('electron-react-titlebar/maximunize/change', browserWindow.isMaximized()) | ||
browserWindow?.on('maximize', callback) | ||
browserWindow?.on('unmaximize', callback) | ||
if (browserWindow) { | ||
setupEventListener(browserWindow, event.sender) | ||
event.sender.send('electron-react-titlebar/browser-window-id', browserWindow.id) | ||
} | ||
}) | ||
@@ -12,0 +20,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
88152
1125
3
102