Skip to content

Commit

Permalink
can't use uglifyjs with es6 modules
Browse files Browse the repository at this point in the history
  • Loading branch information
edsilv committed Mar 6, 2019
1 parent f8fb345 commit d5a05ef
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 90 deletions.
4 changes: 2 additions & 2 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsviews/0.9.75/jsviews.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.min.js"></script>
<script src="https://unpkg.com/[email protected].6/dist-umd/manifesto.js"></script>
<script src="https://unpkg.com/@iiif/[email protected].10/dist-umd/manifold.js"></script>
<script src="https://unpkg.com/[email protected].7/dist-umd/manifesto.js"></script>
<script src="https://unpkg.com/@iiif/[email protected].11/dist-umd/manifold.js"></script>
<script src="https://unpkg.com/@iiif/base-component/dist/BaseComponent.js"></script>
<script src="https://unpkg.com/@edsilv/utils/dist/Utils.js"></script>
<script src="https://unpkg.com/@edsilv/jquery-plugins/dist/jquery-plugins.js"></script>
Expand Down
40 changes: 21 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iiif/iiif-gallery-component",
"version": "1.1.14",
"version": "1.1.15",
"description": "",
"main": "./dist/GalleryComponent.js",
"types": "./dist/GalleryComponent.d.ts",
Expand All @@ -9,7 +9,7 @@
"build-ts": "npx tsc",
"minify-js": "npx uglify-js ./dist/GalleryComponent.js > ./dist/GalleryComponent.min.js",
"build-css": "npx lessc ./src/css/styles.less > ./dist/styles.css",
"build": "npm run clean && npm run build-ts && npm run minify-js && npm run build-css",
"build": "npm run clean && npm run build-ts && npm run build-css",
"start": "npx serve"
},
"repository": {
Expand All @@ -27,14 +27,15 @@
"rimraf": "2.6.2",
"serve": "10.0.2",
"typescript": "3.2.2",
"uglify-js": "3.4.9"
"uglify-es": "^3.3.9"
},
"dependencies": {
"@edsilv/jquery-plugins": "1.0.3",
"@edsilv/utils": "0.2.2",
"@iiif/base-component": "1.1.3",
"@iiif/manifold": "2.0.0-pre.10",
"@iiif/manifold": "2.0.0-pre.11",
"@iiif/vocabulary": "^1.0.7",
"@types/jquery": "3.3.14",
"manifesto.js": "4.0.0-pre.6"
"manifesto.js": "4.0.0-pre.7"
}
}
98 changes: 36 additions & 62 deletions src/GalleryComponent.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
namespace IIIFComponents {
import { ViewingDirection } from "@iiif/vocabulary";

type AnnotationGroup = manifold.AnnotationGroup;
type Canvas = manifesto.Canvas;
type MultiSelectableCanvas = manifold.MultiSelectableCanvas;
type MultiSelectableRange = manifold.MultiSelectableRange;
type MultiSelectableThumb = manifold.MultiSelectableThumb;
type MultiSelectState = manifold.MultiSelectState;
type Range = manifesto.Range;
type Thumb = manifesto.Thumb;
type ViewingDirection = manifesto.ViewingDirection;
namespace IIIFComponents {

export interface IGalleryComponentContent {
searchResult: string;
Expand All @@ -26,7 +18,7 @@ namespace IIIFComponents {
initialZoom?: number;
minLabelWidth?: number;
pageModeEnabled?: boolean;
searchResults?: AnnotationGroup[];
searchResults?: manifold.AnnotationGroup[];
scrollStopDuration?: number;
sizingEnabled?: boolean;
thumbHeight?: number;
Expand Down Expand Up @@ -54,7 +46,7 @@ namespace IIIFComponents {
private _$thumbs: JQuery;
private _data: IGalleryComponentData = this.data();
private _range: number;
private _thumbs: MultiSelectableThumb[];
private _thumbs: manifold.MultiSelectableThumb[];
private _thumbsCache: JQuery | null;

constructor(options: _Components.IBaseComponentOptions) {
Expand Down Expand Up @@ -132,7 +124,7 @@ namespace IIIFComponents {

this._$selectAllButton.checkboxButton((checked: boolean) => {

const multiSelectState: MultiSelectState | null = this._getMultiSelectState();
const multiSelectState: manifold.MultiSelectState | null = this._getMultiSelectState();

if (multiSelectState) {
if (checked) {
Expand All @@ -147,10 +139,10 @@ namespace IIIFComponents {

this._$selectButton.on('click', () => {

const multiSelectState: MultiSelectState | null = this._getMultiSelectState();
const multiSelectState: manifold.MultiSelectState | null = this._getMultiSelectState();

if (multiSelectState) {
var ids: string[] = multiSelectState.getAllSelectedCanvases().map((canvas: Canvas) => {
var ids: string[] = multiSelectState.getAllSelectedCanvases().map((canvas: manifesto.Canvas) => {
return canvas.id;
});

Expand Down Expand Up @@ -242,7 +234,7 @@ namespace IIIFComponents {
thumbHeight: 320,
thumbLoadPadding: 3,
thumbWidth: 200,
viewingDirection: manifesto.ViewingDirection.LEFT_TO_RIGHT
viewingDirection: ViewingDirection.LEFT_TO_RIGHT
}
}

Expand All @@ -251,11 +243,11 @@ namespace IIIFComponents {
this._data = Object.assign(this._data, data);

if (this._data.helper && this._data.thumbWidth !== undefined && this._data.thumbHeight !== undefined) {
this._thumbs = <MultiSelectableThumb[]>this._data.helper.getThumbs(this._data.thumbWidth, this._data.thumbHeight);
this._thumbs = <manifold.MultiSelectableThumb[]>this._data.helper.getThumbs(this._data.thumbWidth, this._data.thumbHeight);
}

if (this._data.viewingDirection) {
if (this._data.viewingDirection.toString() === manifesto.ViewingDirection.BOTTOM_TO_TOP) {
if (this._data.viewingDirection.toString() === ViewingDirection.BOTTOM_TO_TOP) {
this._thumbs.reverse();
}

Expand All @@ -265,10 +257,10 @@ namespace IIIFComponents {
if (this._data.searchResults && this._data.searchResults.length) {

for (let i = 0; i < this._data.searchResults.length; i++) {
var searchResult: AnnotationGroup = this._data.searchResults[i];
var searchResult: manifold.AnnotationGroup = this._data.searchResults[i];

// find the thumb with the same canvasIndex and add the searchResult
let thumb: Thumb = this._thumbs.filter(t => t.index === searchResult.canvasIndex)[0];
let thumb: manifesto.Thumb = this._thumbs.filter(t => t.index === searchResult.canvasIndex)[0];

// clone the data so searchResults isn't persisted on the canvas.
let data = $.extend(true, {}, thumb.data);
Expand All @@ -286,25 +278,25 @@ namespace IIIFComponents {
this.selectIndex(this._data.helper.canvasIndex);
}

const multiSelectState: MultiSelectState | null = this._getMultiSelectState();
const multiSelectState: manifold.MultiSelectState | null = this._getMultiSelectState();

if (multiSelectState && multiSelectState.isEnabled) {
this._$multiSelectOptions.show();
this._$thumbs.addClass("multiSelect");

for (let i = 0; i < multiSelectState.canvases.length; i++) {
const canvas: MultiSelectableCanvas = multiSelectState.canvases[i];
const thumb: Thumb = this._getThumbByCanvas(canvas);
const canvas: manifold.MultiSelectableCanvas = multiSelectState.canvases[i];
const thumb: manifesto.Thumb = this._getThumbByCanvas(canvas);
this._setThumbMultiSelected(thumb, canvas.multiSelected);
}

// range selections override canvas selections
for (let i = 0; i < multiSelectState.ranges.length; i++) {
const range: MultiSelectableRange = multiSelectState.ranges[i];
const thumbs: Thumb[] = this._getThumbsByRange(range);
const range: manifold.MultiSelectableRange = multiSelectState.ranges[i];
const thumbs: manifesto.Thumb[] = this._getThumbsByRange(range);

for (let i = 0; i < thumbs.length; i++){
const thumb: Thumb = thumbs[i];
const thumb: manifesto.Thumb = thumbs[i];
this._setThumbMultiSelected(thumb, range.multiSelected);
}
}
Expand All @@ -318,7 +310,7 @@ namespace IIIFComponents {
}

private _update(): void {
var multiSelectState: MultiSelectState | null = this._getMultiSelectState();
var multiSelectState: manifold.MultiSelectState | null = this._getMultiSelectState();

if (multiSelectState && multiSelectState.isEnabled) {
// check/uncheck Select All checkbox
Expand All @@ -334,7 +326,7 @@ namespace IIIFComponents {
}
}

private _getMultiSelectState(): MultiSelectState | null {
private _getMultiSelectState(): manifold.MultiSelectState | null {

if (this._data.helper) {
return this._data.helper.getMultiSelectState();
Expand All @@ -352,13 +344,13 @@ namespace IIIFComponents {

this._$thumbs.empty();

const multiSelectState: MultiSelectState | null = this._getMultiSelectState();
const multiSelectState: manifold.MultiSelectState | null = this._getMultiSelectState();

// set initial thumb sizes
const heights = [];

for (let i = 0; i < this._thumbs.length; i++) {
const thumb: MultiSelectableThumb = this._thumbs[i];
const thumb: manifold.MultiSelectableThumb = this._thumbs[i];
const initialWidth: number = thumb.width;
const initialHeight: number = thumb.height;
thumb.initialWidth = initialWidth;
Expand All @@ -370,7 +362,7 @@ namespace IIIFComponents {
const medianHeight: number = Utils.Maths.median(heights);

for (let i = 0; i < this._thumbs.length; i++) {
const thumb: MultiSelectableThumb = this._thumbs[i];
const thumb: manifold.MultiSelectableThumb = this._thumbs[i];
thumb.initialHeight = medianHeight;
}

Expand All @@ -393,16 +385,16 @@ namespace IIIFComponents {
const $thumb = $(thumbs[i]);

$thumb.checkboxButton(function(checked: boolean) {
const thumb: MultiSelectableThumb = $.view(this).data;
const thumb: manifold.MultiSelectableThumb = $.view(this).data;
that._setThumbMultiSelected(thumb, !thumb.multiSelected);
const range: MultiSelectableRange = <MultiSelectableRange>that.options.data.helper.getCanvasRange(thumb.data);
const multiSelectState: MultiSelectState | null = that._getMultiSelectState();
const range: manifold.MultiSelectableRange = <manifold.MultiSelectableRange>that.options.data.helper.getCanvasRange(thumb.data);
const multiSelectState: manifold.MultiSelectState | null = that._getMultiSelectState();

if (multiSelectState) {
if (range) {
multiSelectState.selectRange(<MultiSelectableRange>range, thumb.multiSelected);
multiSelectState.selectRange(<manifold.MultiSelectableRange>range, thumb.multiSelected);
} else {
multiSelectState.selectCanvas(<MultiSelectableCanvas>thumb.data, thumb.multiSelected);
multiSelectState.selectCanvas(<manifold.MultiSelectableCanvas>thumb.data, thumb.multiSelected);
}
}

Expand All @@ -414,7 +406,7 @@ namespace IIIFComponents {
}
}

private _getThumbByCanvas(canvas: Canvas): Thumb {
private _getThumbByCanvas(canvas: manifesto.Canvas): manifesto.Thumb {
return this._thumbs.filter(c => c.data.id === canvas.id)[0];
}

Expand Down Expand Up @@ -502,18 +494,18 @@ namespace IIIFComponents {

}

private _getThumbsByRange(range: Range): Thumb[] {
private _getThumbsByRange(range: manifesto.Range): manifesto.Thumb[] {

let thumbs: Thumb[] = [];
let thumbs: manifesto.Thumb[] = [];

if (!this._data.helper) {
return thumbs;
}

for (let i = 0; i < this._thumbs.length; i++) {
const thumb: Thumb = this._thumbs[i];
const canvas: Canvas = thumb.data;
const r: Range = <Range>this._data.helper.getCanvasRange(canvas, range.path);
const thumb: manifesto.Thumb = this._thumbs[i];
const canvas: manifesto.Canvas = thumb.data;
const r: manifesto.Range = <manifesto.Range>this._data.helper.getCanvasRange(canvas, range.path);

if (r && r.id === range.id){
thumbs.push(thumb);
Expand Down Expand Up @@ -639,7 +631,7 @@ namespace IIIFComponents {
this._range = Utils.Maths.clamp(norm, 0.05, 1);
}

private _setThumbMultiSelected(thumb: Thumb, selected: boolean): void {
private _setThumbMultiSelected(thumb: manifesto.Thumb, selected: boolean): void {
$.observable(thumb).setProperty("multiSelected", selected);
}

Expand All @@ -665,22 +657,4 @@ namespace IIIFComponents.GalleryComponent {
} else {
g.IIIFComponents.GalleryComponent = IIIFComponents.GalleryComponent;
}
})(window);

interface JQuery {
// jsviews
link: any;
render: any;
// unevent
on(events: string, handler: (eventObject: JQueryEventObject, ...args: any[]) => any, wait: Number): JQuery;
// plugins
checkboxButton(onClicked: (checked: boolean) => void): void;
}

interface JQueryStatic {
// jsviews
observable: any;
templates: any;
views: any;
view: any;
}
})(window);
Loading

0 comments on commit d5a05ef

Please sign in to comment.