export default { namespaced: true, state: { stack: [], hidden: false, }, mutations: { setStack: (state, value) => { state.stack = value; }, setHidden: (state, value) => { state.hidden = value; }, }, getters: { config: state => !state.hidden && state.stack[0], }, actions: { open({ commit, state }, param) { return new Promise((resolve, reject) => { const config = typeof param === 'object' ? { ...param } : { type: param }; const clean = () => commit('setStack', state.stack.filter((otherConfig => otherConfig !== config))); config.resolve = (result) => { clean(); if (config.onResolve) { // Call onResolve immediately (mostly to prevent browsers from blocking popup windows) config.onResolve(result) .then(res => resolve(res)); } else { resolve(result); } }; config.reject = (error) => { clean(); reject(error); }; commit('setStack', [config, ...state.stack]); }); }, hideUntil({ commit, state }, promise) { commit('setHidden', true); return promise.then((res) => { commit('setHidden', false); return res; }, (err) => { commit('setHidden', false); throw err; }); }, fileDeletion: ({ dispatch }, item) => dispatch('open', { content: `
You are about to delete the file ${item.name}. Are you sure?
`, resolveText: 'Yes, delete', rejectText: 'No', }), folderDeletion: ({ dispatch }, item) => dispatch('open', { content: `You are about to delete the folder ${item.name} and all its files. Are you sure?
`, resolveText: 'Yes, delete', rejectText: 'No', }), discussionDeletion: ({ dispatch }) => dispatch('open', { content: 'You are about to delete a discussion. Are you sure?
', resolveText: 'Yes, delete', rejectText: 'No', }), commentDeletion: ({ dispatch }) => dispatch('open', { content: 'You are about to delete a comment. Are you sure?
', resolveText: 'Yes, delete', rejectText: 'No', }), trashDeletion: ({ dispatch }) => dispatch('open', { content: 'Files in the trash are automatically deleted after 7 days of inactivity.
', resolveText: 'Ok', }), fileRestoration: ({ dispatch }) => dispatch('open', { content: 'You are about to revert some changes. Are you sure?
', resolveText: 'Yes, revert', rejectText: 'No', }), removeWorkspace: ({ dispatch }) => dispatch('open', { content: 'You are about to remove a workspace locally. Are you sure?
', resolveText: 'Yes, remove', rejectText: 'No', }), reset: ({ dispatch }) => dispatch('open', { content: 'This will clean all your workspaces locally. Are you sure?
', resolveText: 'Yes, clean', rejectText: 'No', }), providerRedirection: ({ dispatch }, { providerName, onResolve }) => dispatch('open', { content: `You are about to navigate to the ${providerName} authorization page.
`, resolveText: 'Ok, go on', rejectText: 'Cancel', onResolve, }), workspaceGoogleRedirection: ({ dispatch }, { onResolve }) => dispatch('open', { content: 'StackEdit needs full Google Drive access to open this workspace.
', resolveText: 'Ok, grant', rejectText: 'Cancel', onResolve, }), signInForSponsorship: ({ dispatch }, { onResolve }) => dispatch('open', { type: 'signInForSponsorship', content: `You have to sign in with Google to sponsor.
You have to sign in with Google to start commenting.
You have to sign in with Google to enable revision history.
This feature is restricted to sponsors as it relies on server resources.
', resolveText: 'Ok, I understand', }), paymentSuccess: ({ dispatch }) => dispatch('open', { content: 'Thank you for your payment! Your sponsorship will be active in a minute.
', resolveText: 'Ok', }), }, };