-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Allows admins to spec a cloud service repository per project * Shows a button to creators if assets is enabled. * Opens modal to let creator choose asset. * Automatically inserts asset into doc and maintains AEM origin. * Converts author URL to publish (polaris coming soon). Resolves: GH-90
- Loading branch information
1 parent
8a5894a
commit 83e6e73
Showing
7 changed files
with
118 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.da-dialog-asset { | ||
width: calc(100% - 72px); | ||
box-sizing: border-box; | ||
height: calc(100% - 72px); | ||
padding: 0; | ||
border: 0; | ||
border-radius: 16px; | ||
filter: drop-shadow(0 0 8px rgb(0 0 0 / 30%)); | ||
} | ||
|
||
.da-dialog-asset-inner { | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { getNx } from '../../../scripts/utils.js'; | ||
import getPathDetails from '../../shared/pathDetails.js'; | ||
import { DA_ORIGIN } from '../../shared/constants.js'; | ||
import { daFetch } from '../../shared/utils.js'; | ||
|
||
const { loadScript, loadStyle } = await import(`${getNx()}/scripts/nexter.js`); | ||
const { loadIms, handleSignIn } = await import(`${getNx()}/utils/ims.js`); | ||
|
||
const ASSET_SELECTOR_URL = 'https://experience.adobe.com/solutions/CQ-assets-selectors/assets/resources/assets-selectors.js'; | ||
|
||
export async function getRepoId() { | ||
const { repo, owner } = getPathDetails(); | ||
if (!(repo || owner)) return null; | ||
const resp = await daFetch(`${DA_ORIGIN}/config/${owner}/${repo}`); | ||
if (!resp.ok) return null; | ||
const json = await resp.json(); | ||
const repoConf = json.data.find((conf) => conf.key === 'aem.repositoryId'); | ||
if (!repoConf) return null; | ||
return repoConf.value; | ||
} | ||
|
||
export async function openAssets() { | ||
const repoId = await getRepoId(); | ||
const details = await loadIms(); | ||
if (details.anonymous) handleSignIn(); | ||
if (!(repoId && details.accessToken)) return; | ||
|
||
let dialog = document.querySelector('.da-dialog-asset'); | ||
if (!dialog) { | ||
await loadStyle(import.meta.url.replace('.js', '.css')); | ||
await loadScript(ASSET_SELECTOR_URL); | ||
|
||
dialog = document.createElement('dialog'); | ||
dialog.className = 'da-dialog-asset'; | ||
|
||
const inner = document.createElement('div'); | ||
inner.className = 'da-dialog-asset-inner'; | ||
|
||
dialog.append(inner); | ||
|
||
const main = document.body.querySelector('main'); | ||
main.insertAdjacentElement('afterend', dialog); | ||
|
||
const selectorProps = { | ||
imsToken: details.accessToken.token, | ||
repositoryId: repoId, | ||
aemTierType: 'author', | ||
onClose: () => { dialog.close(); }, | ||
handleSelection: (assets) => { | ||
const [asset] = assets; | ||
if (!asset) return; | ||
const format = asset['aem:formatName']; | ||
if (!format) return; | ||
const { path } = asset; | ||
const pubRepoId = repoId.replace('author', 'publish'); | ||
const { view } = window; | ||
const { state } = view; | ||
dialog.close(); | ||
|
||
const imgObj = { src: `https://${pubRepoId}${path}`, style: 'width: 180px' }; | ||
const fpo = state.schema.nodes.image.create(imgObj); | ||
view.dispatch(state.tr.insert(state.selection.head, fpo).scrollIntoView()); | ||
}, | ||
}; | ||
window.PureJSSelectors.renderAssetSelector(inner, selectorProps); | ||
} | ||
|
||
dialog.showModal(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters