2018-12-12 23:08:38 +00:00
|
|
|
import { SIZES } from '../../src/ui/thumbnail';
|
2021-08-03 22:53:37 +00:00
|
|
|
import { createPreviewWithType, layoutPreview, getClasses,
|
|
|
|
createLayout,
|
2023-03-30 22:29:56 +00:00
|
|
|
registerPreviewUI,
|
|
|
|
createPagePreview,
|
|
|
|
createDisambiguationPreview,
|
|
|
|
createReferencePreview,
|
2021-08-03 22:53:37 +00:00
|
|
|
pointerSize, landscapePopupWidth, portraitPopupWidth
|
|
|
|
} from '../../src/ui/renderer.js';
|
2023-03-30 22:29:56 +00:00
|
|
|
import { previewTypes } from '../../src/preview/model';
|
2018-12-12 23:08:38 +00:00
|
|
|
import scaleDownThumbnail from './scaleDownThumbnail';
|
|
|
|
|
2023-03-30 22:29:56 +00:00
|
|
|
registerPreviewUI( previewTypes.TYPE_PAGE, createPagePreview );
|
|
|
|
registerPreviewUI( previewTypes.TYPE_REFERENCE, createReferencePreview );
|
|
|
|
registerPreviewUI( previewTypes.TYPE_DISAMBIGUATION, createDisambiguationPreview );
|
|
|
|
|
2021-08-03 22:53:37 +00:00
|
|
|
/**
|
|
|
|
* @typedef {LayoutHint}
|
|
|
|
* @property {boolean} flippedX
|
|
|
|
* @property {boolean} flippedY
|
|
|
|
*/
|
2018-12-12 23:08:38 +00:00
|
|
|
/**
|
2019-02-14 10:13:33 +00:00
|
|
|
* Creates a static/stateless Popup and returns its HTML.
|
2018-12-12 23:08:38 +00:00
|
|
|
*
|
|
|
|
* @param {ext.popups.PreviewModel} model
|
2021-08-03 22:53:37 +00:00
|
|
|
* @param {LayoutHint} layoutHint
|
2018-12-12 23:08:38 +00:00
|
|
|
*
|
2019-08-05 12:35:21 +00:00
|
|
|
* @return {string} HTML
|
2018-12-12 23:08:38 +00:00
|
|
|
*/
|
2021-08-03 22:53:37 +00:00
|
|
|
function createPopup( model, layoutHint ) {
|
2018-12-12 23:08:38 +00:00
|
|
|
if ( model.thumbnail ) {
|
|
|
|
model.thumbnail = scaleDownThumbnail( model.thumbnail );
|
|
|
|
}
|
|
|
|
|
|
|
|
const preview = createPreviewWithType( model );
|
2021-08-03 22:53:37 +00:00
|
|
|
const WINDOW_WIDTH = preview.isTall ? 500 : 500;
|
|
|
|
const WINDOW_HEIGHT = preview.isTall ? 450 : 500;
|
|
|
|
const LINK_HEIGHT = 40;
|
|
|
|
const POPUP_SIZE = preview.isTall ? landscapePopupWidth : portraitPopupWidth;
|
|
|
|
|
|
|
|
const LINK_POS_X = layoutHint.flippedX ?
|
|
|
|
WINDOW_WIDTH - LINK_HEIGHT : LINK_HEIGHT;
|
|
|
|
const LINK_POS_Y = layoutHint.flippedY ?
|
|
|
|
WINDOW_HEIGHT - LINK_HEIGHT :
|
|
|
|
- POPUP_SIZE + LINK_HEIGHT;
|
|
|
|
|
|
|
|
const measures = {
|
|
|
|
pageX: LINK_POS_X,
|
|
|
|
pageY: 0,
|
|
|
|
clientY: 0,
|
|
|
|
clientRects: [
|
|
|
|
{
|
|
|
|
top: WINDOW_HEIGHT,
|
|
|
|
bottom: WINDOW_WIDTH
|
|
|
|
}
|
|
|
|
],
|
|
|
|
// Represent link position based on hints
|
|
|
|
offset: {
|
|
|
|
// control it.
|
|
|
|
top: LINK_POS_Y,
|
|
|
|
left: 0
|
|
|
|
},
|
|
|
|
width: POPUP_SIZE,
|
|
|
|
height: POPUP_SIZE,
|
|
|
|
scrollTop: 0,
|
|
|
|
windowWidth: WINDOW_WIDTH,
|
|
|
|
windowHeight: WINDOW_HEIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
// Mirror logic in render::createLayout
|
|
|
|
const layout = createLayout(
|
|
|
|
preview.isTall,
|
|
|
|
measures,
|
|
|
|
pointerSize,
|
|
|
|
model.languageDirection
|
|
|
|
);
|
|
|
|
|
|
|
|
const wrapper = document.createElement( 'div' );
|
|
|
|
const LANG_DIR = layout.dir === 'rtl' ? layout.dir : 'ltr';
|
|
|
|
wrapper.setAttribute( 'dir', LANG_DIR );
|
|
|
|
wrapper.setAttribute( 'class', `popups-storybook-example storybook-${LANG_DIR}` );
|
|
|
|
wrapper.style.maxHeight = `${WINDOW_HEIGHT}px;`;
|
|
|
|
wrapper.style.maxWidth = `${WINDOW_HEIGHT}px;`;
|
|
|
|
if ( layout.flippedX ) {
|
|
|
|
wrapper.classList.add( 'popups-storybook-example-flipped-x' );
|
|
|
|
}
|
|
|
|
if ( layout.flippedY ) {
|
|
|
|
wrapper.classList.add( 'popups-storybook-example-flipped-y' );
|
|
|
|
}
|
|
|
|
if ( preview.isTall ) {
|
|
|
|
wrapper.classList.add( 'popups-storybook-example-tall' );
|
|
|
|
}
|
2018-12-12 23:08:38 +00:00
|
|
|
|
2021-08-03 22:53:37 +00:00
|
|
|
const link = document.createElement( 'a' );
|
|
|
|
link.setAttribute( 'href', '#' );
|
|
|
|
link.setAttribute( 'class', 'popups-storybook-link' );
|
|
|
|
link.textContent = `Page preview ${layout.flippedX ? 'flipped-x' : ''}
|
|
|
|
${layout.flippedY ? 'flipped-y' : ''}
|
|
|
|
${preview.isTall ? '(landscape)' : '(portrait)'}
|
|
|
|
${preview.hasThumbnail ? 'with thumbnail' : ''}`;
|
2020-11-24 14:33:42 +00:00
|
|
|
|
2021-08-03 22:53:37 +00:00
|
|
|
wrapper.appendChild( link );
|
2018-12-12 23:08:38 +00:00
|
|
|
layoutPreview(
|
|
|
|
preview,
|
|
|
|
layout,
|
|
|
|
getClasses( preview, {
|
2021-08-03 22:53:37 +00:00
|
|
|
dir: layout.dir,
|
2018-12-12 23:08:38 +00:00
|
|
|
flippedX: layout.flippedX,
|
|
|
|
flippedY: layout.flippedY
|
|
|
|
} ),
|
|
|
|
SIZES.landscapeImage.h,
|
2021-08-03 22:53:37 +00:00
|
|
|
pointerSize,
|
|
|
|
WINDOW_HEIGHT
|
2018-12-12 23:08:38 +00:00
|
|
|
);
|
2023-06-30 16:41:53 +00:00
|
|
|
wrapper.appendChild( preview.el );
|
2021-08-03 22:53:37 +00:00
|
|
|
return wrapper.outerHTML;
|
2018-12-12 23:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default createPopup;
|