Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

51 changes: 33 additions & 18 deletions build-shims.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,34 +247,49 @@ mockery.registerMock('@zimbra-client/errors', {

function createShim(shimModule) {
if (Array.isArray(shimModule)) {
shimModule.map((name, index) => !index ? name : `${shimModule[0]}/${name}`).forEach(createShim);
shimModule
.map((name, index) => (!index ? name : `${shimModule[0]}/${name}`))
.forEach(createShim);
return;
}
// console.log('require.cache', require.cache);
//turn snake case into camelCase, e.g. preact-router into preactRouter
let dirName = path.resolve(`src/shims/${shimModule}`);

mkdirp(dirName).then(() => {
fs.writeFileSync(`${dirName}/index.js`,
`/** This file is an auto-generated shim, aliased in for "${shimModule}" in the webpack config.
* When components import '${shimModule}', we want to give them back the copy
* Zimbra passed down when it called the factory provided to zimlet().
*/
mkdirp(dirName)
.then(() => {
fs.writeFileSync(
`${dirName}/index.js`,
`/** This file is an auto-generated shim, aliased in for "${shimModule}" in the webpack config.
* When components import '${shimModule}', we want to give them back the copy
* Zimbra passed down when it called the factory provided to zimlet().
*/

/* eslint-disable camelcase, dot-notation */
import { warnOnMissingExport } from '.${shimModule.split('/').map((pathpart, index) => !index ? './' : '../').join('')}';
import { warnOnMissingExport } from '.${shimModule
.split('/')
.map((pathpart, index) => (!index ? './' : '../'))
.join('')}';
const wrap = warnOnMissingExport.bind(null, global.shims['${shimModule}'], '${shimModule}');

${Object.keys(require(shimModule)).filter(exportName => exportName !== '__esModule').map(exportName =>
`export ${exportName === 'default' ? 'default' : `const ${exportName} =`} wrap('${exportName}');`).join('\n')
}
${'default' in require(shimModule) ? '' : `
export default global.shims['${shimModule}'];`}
${Object.keys(require(shimModule))
.filter(exportName => exportName !== '__esModule')
.map(
exportName =>
`export ${exportName === 'default' ? 'default' : `const ${exportName} =`} wrap('${exportName}');`
)
.join('\n')}
${
'default' in require(shimModule)
? ''
: `
export default global.shims['${shimModule}'];`
}
`
);
}).catch(() => {
console.error(`Unable to mkdir ${dirName}`);
});
);
})
.catch(() => {
console.error(`Unable to mkdir ${dirName}`);
});
}

shimmedModules.forEach(createShim);
Expand Down
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { coreJsConfig, customConfig } from '@zimbra/eslint-config';

const finalConfig = [
...customConfig,
...coreJsConfig.map(conf => {
return {
...conf,
ignores: [...conf.ignores, 'src/shims/**'],
rules: {
...conf.rules,
'no-console': 'off'
}
};
})
];

export default finalConfig;
18 changes: 12 additions & 6 deletions examples/dropbox/components/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { Component } from 'preact';
import style from './style.less';

export default class Page extends Component {

componentWillMount() {
this.shortcutHandlers = [
{ context: 'dropbox', command: 'DROPBOX_ALERT', handler: () => window.alert('You hit ctrl+A') } //eslint-disable-line no-alert
{
context: 'dropbox',
command: 'DROPBOX_ALERT',
// eslint-disable-next-line no-alert
handler: () => window.alert('You hit ctrl+A')
}
];

this.context.shortcutCommandHandler.addCommandHandlers(this.shortcutHandlers);
Expand All @@ -27,13 +31,15 @@ export default class Page extends Component {
<p>I am some content</p>

<h2>Keyboard Shortcuts</h2>
<p>This zimlet adds two keyboard shortcuts:</p>
<p>
<pre style="display: inline-block">G D</pre>: Open the Dropbox Tab (added globally)
</p>
<p>
This zimlet adds two keyboard shortcuts:
<pre style="display: inline-block">ctrl+A</pre>: Show an alert. Only active when the
Dropbox tab is open
</p>
<p><pre style="display: inline-block">G D</pre>: Open the Dropbox Tab (added globally)</p>
<p><pre style="display: inline-block">ctrl+A</pre>: Show an alert. Only active when the Dropbox tab is open</p>
</div>
);
}
}

11 changes: 5 additions & 6 deletions examples/dropbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ const dropBoxKeyBindings = {
}
};

export default (context) => {
export default context => {
let { plugins, components, keyBindings, shortcutCommandHandler, route } = context;
console.log('dropbox: construct', context, style);

let exports = {};

const globalShortcutHandlers = [{ context: 'all', command: 'GO_TO_DROPBOX', handler: () => route('/dropbox') }];
const globalShortcutHandlers = [
{ context: 'all', command: 'GO_TO_DROPBOX', handler: () => route('/dropbox') }
];

exports.init = function () {

console.log('In Dropbox zimlet. route is:', route);

// console.log('dropbox: init');
Expand All @@ -44,9 +45,7 @@ export default (context) => {
};

function Router() {
return [
<Page path="/dropbox" />
];
return [<Page path="/dropbox" />];
}

function MenuItem() {
Expand Down
Loading