Skip to content

Commit

Permalink
perf: migrate to vite
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <[email protected]>
  • Loading branch information
st3iny committed May 30, 2024
1 parent 9164208 commit e7f9d6e
Show file tree
Hide file tree
Showing 30 changed files with 5,497 additions and 5,653 deletions.
14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"ignorePatterns": ["src/**/*.d.ts"],
"globals": {
"appName": true,
"appVersion": true
},
"extends": [
"@nextcloud/eslint-config/typescript"
],
"rules": {
"vue/no-reserved-component-names": "off"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ yarn-error.log*
.marginalia

js/
/css/
build/
coverage*
vendor/
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public function index(): TemplateResponse {
$this->initialStateService->provideInitialState(Application::APP_ID, 'isCirclesEnabled', $isCirclesEnabled && $isCircleVersionCompatible);
$this->initialStateService->provideInitialState(Application::APP_ID, 'isTalkEnabled', $isTalkEnabled && $isTalkVersionCompatible);

Util::addStyle(Application::APP_ID, 'contacts-index');
Util::addStyle(Application::APP_ID, 'contacts-main');
Util::addScript(Application::APP_ID, 'contacts-main');

return new TemplateResponse(Application::APP_ID, 'main');
Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/LoadContactsFilesActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function handle(Event $event): void {
return;
}

Util::addStyle(Application::APP_ID, 'contacts-index');
Util::addStyle(Application::APP_ID, 'contacts-files-action');

// only available since Nc 28
if (method_exists(Util::class, 'addInitScript')) {
Util::addInitScript(Application::APP_ID, 'contacts-files-action');
Expand Down
11,010 changes: 5,418 additions & 5,592 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
"homepage": "https://github.com/nextcloud/contacts",
"license": "agpl",
"private": true,
"type": "module",
"scripts": {
"build": "webpack --node-env production --progress",
"dev": "webpack --node-env development --progress",
"watch": "webpack --node-env development --progress --watch",
"build": "vite build --mode production",
"dev": "vite build --mode development",
"watch": "vite build --mode development --watch",
"lint": "eslint --ext .js,.ts,.vue src",
"lint:fix": "eslint --ext .js,.ts,.vue src --fix",
"stylelint": "stylelint src",
Expand All @@ -53,6 +54,7 @@
"@nextcloud/router": "^2.2.0",
"@nextcloud/sharing": "^0.1.0",
"@nextcloud/vue": "^8.11.3",
"@shortcm/qr-image": "^9.0.4",
"@vueuse/core": "^10.9.0",
"b64-to-blob": "^1.2.19",
"camelcase": "^8.0.0",
Expand All @@ -65,7 +67,6 @@
"moment": "^2.30.1",
"p-limit": "^5.0.0",
"pinia": "^2.1.7",
"qr-image": "^3.2.0",
"string-natural-compare": "^3.0.1",
"uuid": "^9.0.1",
"vue": "~2.7.15",
Expand All @@ -83,14 +84,12 @@
"npm": "^9.0.0"
},
"devDependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.24.6",
"@nextcloud/babel-config": "^1.2.0",
"@nextcloud/browserslist-config": "^3.0.1",
"@nextcloud/eslint-config": "^8.3.0",
"@nextcloud/stylelint-config": "^2.3.0",
"@nextcloud/typings": "^1.7.0",
"@nextcloud/webpack-vue-config": "^6.0.1",
"@nextcloud/vite-config": "^1.2.3",
"@types/jest": "^29.5.12",
"@vue/vue2-jest": "^29.2.6",
"babel-jest": "^29.7.0",
Expand All @@ -103,6 +102,7 @@
"ts-jest": "^29.1.3",
"ts-loader": "^9.5.1",
"typescript": "^5.4.5",
"vite": "^5.2.12",
"vue-template-compiler": "~2.7"
},
"browserslist": [
Expand Down
3 changes: 3 additions & 0 deletions src/admin-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
*
*/

// eslint-disable-next-line import/no-unresolved, n/no-missing-import
import 'vite/modulepreload-polyfill'

import Vue from 'vue'
import AdminSettings from './components/AdminSettings.vue'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export default {
}
},
confirmDeletion() {
OC.dialogs.confirm(
window.OC.dialogs.confirm(
t('contacts', 'This will delete the address book and every contacts within it'),
t('contacts', 'Delete {addressbook}?', { addressbook: this.addressbook.displayName }),
this.deleteAddressbook,
Expand Down
12 changes: 7 additions & 5 deletions src/components/ContactDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
import { showError } from '@nextcloud/dialogs'

import { stringify } from 'ical.js'
import qr from 'qr-image'
import { getSVG } from '@shortcm/qr-image/lib/svg'
import mitt from 'mitt'
import {
NcActions as Actions,
Expand Down Expand Up @@ -699,7 +699,7 @@ export default {
},

enableToggleBirthdayExclusion() {
return parseInt(OC.config.version.split('.')[0]) >= 26
return parseInt(window.OC.config.version.split('.')[0]) >= 26
&& this.localContact?.vCard // Wait until localContact was fetched
},

Expand Down Expand Up @@ -750,7 +750,7 @@ export default {
return this.contact.addressbook.id === 'z-server-generated--system'
},
nextcloudVersionAtLeast28() {
return parseInt(OC.config.version.split('.')[0]) >= 28
return parseInt(window.OC.config.version.split('.')[0]) >= 28
},
},

Expand Down Expand Up @@ -806,14 +806,16 @@ export default {
/**
* Generate a qrcode for the contact
*/
showQRcode() {
async showQRcode() {
const jCal = this.contact.jCal.slice(0)
// do not encode photo
jCal[1] = jCal[1].filter(props => props[0] !== 'photo')

const data = stringify(jCal)
if (data.length > 0) {
this.qrcode = btoa(qr.imageSync(data, { type: 'svg' }))
const svgBytes = await getSVG(data)
const svgString = new TextDecoder().decode(svgBytes)
this.qrcode = btoa(svgString)
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/components/DetailsHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default {
</script>

<style lang="scss" scoped>
@import '../../css/ContactDetailsLayout';
@import '../css/ContactDetailsLayout';

$top-padding: 50px;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

@import '../ContactDetailsLayout.scss';
@import '../ContactDetailsLayout';

$property-label-max-width: $contact-details-label-max-width;
$property-value-max-width: $contact-details-value-max-width;
Expand Down Expand Up @@ -81,8 +81,8 @@ $property-row-gap: $contact-details-row-gap;

textarea {
// Limit max height to make scrolling the form a bit easier
min-height: 2 * $grid-height-unit - 2*$grid-input-margin;
max-height: 5 * $grid-height-unit - 2*$grid-input-margin;
min-height: 2 * $grid-height-unit - 2 * $grid-input-margin;
max-height: 5 * $grid-height-unit - 2 * $grid-input-margin;
}

input,
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion css/SettingsSection.scss → src/css/SettingsSection.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

// contacts settings section
.app-contacts #app-settings-content {
padding-left: 0px !important;
padding-left: 0px !important;
}

#app-settings-content {
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 9 additions & 5 deletions src/files-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

// eslint-disable-next-line import/no-unresolved, n/no-missing-import
import 'vite/modulepreload-polyfill'

import ConfirmationDialog from './components/ConfirmationDialog.vue'

import { generateUrl } from '@nextcloud/router'
Expand All @@ -33,7 +37,7 @@ Vue.prototype.t = t

const mime = 'text/vcard'
const name = 'contacts-import'
const nextcloudVersionIsGreaterThanOr28 = parseInt(OC.config.version.split('.')[0]) >= 28
const nextcloudVersionIsGreaterThanOr28 = parseInt(window.OC.config.version.split('.')[0]) >= 28

if (nextcloudVersionIsGreaterThanOr28) {
registerFileAction(new FileAction({
Expand Down Expand Up @@ -80,19 +84,19 @@ if (nextcloudVersionIsGreaterThanOr28) {
}))
} else {
window.addEventListener('DOMContentLoaded', () => {
if (OCA.Files && OCA.Files.fileActions) {
OCA.Files.fileActions.registerAction({
if (window.OCA.Files && window.OCA.Files.fileActions) {
window.OCA.Files.fileActions.registerAction({
name,
displayName: t('contacts', 'Import'),
mime,
permissions: OC.PERMISSION_READ,
permissions: window.OC.PERMISSION_READ,
iconClass: 'icon-contacts-dark',
actionHandler(fileName, context) {
const absPath = `${context.dir === '/' ? '' : context.dir}/${fileName}`
window.location = generateUrl(`/apps/contacts/import?file=${absPath}`)
},
})
OCA.Files.fileActions.setDefault(mime, name)
window.OCA.Files.fileActions.setDefault(mime, name)
return
}
console.error('Unable to register vcf import action')
Expand Down
25 changes: 8 additions & 17 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { generateFilePath } from '@nextcloud/router'
import { getRequestToken } from '@nextcloud/auth'

// eslint-disable-next-line import/no-unresolved, n/no-missing-import
import 'vite/modulepreload-polyfill'

import { sync } from 'vuex-router-sync'
import Vue from 'vue'

Expand All @@ -35,24 +37,13 @@ import ClickOutside from 'vue-click-outside'
import { Tooltip as VTooltip } from '@nextcloud/vue'

// Global scss sheets
import '../css/contacts.scss'
import './css/contacts.scss'

// Dialogs css
import '@nextcloud/dialogs/style.css'

import { createPinia, PiniaVuePlugin } from 'pinia'

// CSP config for webpack dynamic chunk loading
// eslint-disable-next-line
__webpack_nonce__ = btoa(getRequestToken())

// Correct the root of the app for chunk loading
// OC.linkTo matches the apps folders
// OC.generateUrl ensure the index.php (or not)
// We do not want the index.php since we're loading files
// eslint-disable-next-line
__webpack_public_path__ = generateFilePath('contacts', '', 'js/')

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

Expand All @@ -68,12 +59,12 @@ Vue.prototype.n = n
Vue.prototype.appName = appName
Vue.prototype.appVersion = appVersion
Vue.prototype.logger = logger
Vue.prototype.OC = OC
Vue.prototype.OCA = OCA
Vue.prototype.OC = window.OC
Vue.prototype.OCA = window.OCA

// Force redirect if rewrite enabled but accessed through index.php
if (window.location.pathname.split('/')[1] === 'index.php'
&& OC.config.modRewriteWorking) {
&& window.OC.config.modRewriteWorking) {
router.push({
name: 'group',
params: { selectedGroup: t('contacts', 'All contacts') },
Expand Down
8 changes: 4 additions & 4 deletions src/mixins/CircleActionsMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export default {

methods: {
confirmLeaveCircle() {
OC.dialogs.confirmDestructive(
window.OC.dialogs.confirmDestructive(
t('contacts', 'You are about to leave {circle}.\nAre you sure?', {
circle: this.circle.displayName,
}),
t('contacts', 'Please confirm team leave'),
OC.dialogs.YES_NO_BUTTONS,
window.OC.dialogs.YES_NO_BUTTONS,
this.leaveCircle,
true,
)
Expand Down Expand Up @@ -127,12 +127,12 @@ export default {
},

confirmDeleteCircle() {
OC.dialogs.confirmDestructive(
window.OC.dialogs.confirmDestructive(
t('contacts', 'You are about to delete {circle}.\nAre you sure?', {
circle: this.circle.displayName,
}),
t('contacts', 'Please confirm team deletion'),
OC.dialogs.YES_NO_BUTTONS,
window.OC.dialogs.YES_NO_BUTTONS,
this.deleteCircle,
true,
)
Expand Down
2 changes: 1 addition & 1 deletion src/services/cdav.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function xhrProvider() {
}
return result
}
OC.registerXHRForErrorProcessing(xhr)
window.OC.registerXHRForErrorProcessing(xhr)
return xhr
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/collaborationAutocompletion.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { SHARES_TYPES_MEMBER_MAP } from '../models/constants.ts'

// generate allowed shareType from SHARES_TYPES_MEMBER_MAP
const shareType = Object.keys(SHARES_TYPES_MEMBER_MAP)
const maxAutocompleteResults = parseInt(OC.config['sharing.maxAutocompleteResults'], 10) || 25
const maxAutocompleteResults = parseInt(window.OC.config['sharing.maxAutocompleteResults'], 10) || 25

/**
* Get suggestions
Expand Down Expand Up @@ -124,7 +124,7 @@ const formatResults = function(result) {
label: result.label,
id: `${type}-${result.value.shareWith}`,
// If this is a user, set as user for avatar display by UserBubble
user: [OC.Share.SHARE_TYPE_USER, OC.Share.SHARE_TYPE_REMOTE].indexOf(result.value.shareType) > -1
user: [window.OC.Share.SHARE_TYPE_USER, window.OC.Share.SHARE_TYPE_REMOTE].indexOf(result.value.shareType) > -1
? result.value.shareWith
: null,
type,
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions templates/settings/admin.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php
// TODO: uncomment once there are custom styles in the admin settings entrypoint
// style('contacts', 'contacts-index');
// style('contacts', 'contacts-admin-settings');
script('contacts', 'contacts-admin-settings');
?>

Expand Down
10 changes: 10 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import path from 'path'
import { createAppConfig } from '@nextcloud/vite-config'

export default createAppConfig({
'main': path.join(__dirname, 'src', 'main.js'),
'files-action': path.join(__dirname, 'src', 'files-action.js'),
'admin-settings': path.join(__dirname, 'src', 'admin-settings.js'),
}, {
inlineCSS: false,
})

0 comments on commit e7f9d6e

Please sign in to comment.