diff --git a/addon/action.js b/addon/action.js deleted file mode 100644 index 127c67da..00000000 --- a/addon/action.js +++ /dev/null @@ -1,25 +0,0 @@ -import Promise from "./promise"; - -export default class Action { - constructor(nameOrHandler, args=[], opts={}) { - if (typeof nameOrHandler === 'function') { - this.handler = nameOrHandler; - } else { - this.name = nameOrHandler; - } - this.reversed = opts.reversed; - this.args = args; - } - - validateHandler(transitionMap) { - if (!this.handler) { - this.handler = transitionMap.lookup(this.name); - } - } - - run(context) { - return new Promise((resolve, reject) => { - Promise.resolve(this.handler.apply(context, this.args)).then(resolve, reject); - }); - } -} diff --git a/addon/animate.js b/addon/animate.js deleted file mode 100644 index ab124ef8..00000000 --- a/addon/animate.js +++ /dev/null @@ -1,117 +0,0 @@ -import Promise from "./promise"; -import Ember from "ember"; - -var Velocity = Ember.$.Velocity; - -// Make sure Velocity always has promise support by injecting our own -// RSVP-based implementation if it doesn't already have one. -if (!Velocity.Promise) { - Velocity.Promise = Promise; -} - -export function animate(elt, props, opts, label) { - // These numbers are just sane defaults in the probably-impossible - // case where somebody tries to read our state before the first - // 'progress' callback has fired. - var state = { percentComplete: 0, timeRemaining: 100, timeSpent: 0 }; - - if (!elt || elt.length === 0) { - return Promise.resolve(); - } - - if (!opts) { - opts = {}; - } else { - opts = Ember.copy(opts); - } - - // By default, we ask velocity to clear the element's `display` - // and `visibility` properties at the start of animation. Our - // animated divs are all initially rendered with `display:none` - // and `visibility:hidden` to prevent a flash of before-animated - // content. - if (typeof(opts.display) === 'undefined') { - opts.display = ''; - } - if (typeof(opts.visibility) === 'undefined') { - opts.visibility = 'visible'; - } - - if (opts.progress) { - throw new Error("liquid-fire's 'animate' function reserves the use of Velocity's 'progress' option for its own nefarious purposes."); - } - - opts.progress = function(){ - state.percentComplete = arguments[1]; - state.timeRemaining = arguments[2]; - state.timeSpent = state.timeRemaining / (1/state.percentComplete - 1); - }; - - state.promise = Promise.resolve(Velocity.animate(elt[0], props, opts)); - - if (label) { - state.promise = state.promise.then(function(){ - clearLabel(elt, label); - }, function(err) { - clearLabel(elt, label); - throw err; - }); - applyLabel(elt, label, state); - } - - return state.promise; -} - -export function stop(elt) { - if (elt) { - elt.velocity('stop', true); - } -} - -export function setDefaults(props) { - for (var key in props) { - if (props.hasOwnProperty(key)) { - if (key === 'progress') { - throw new Error("liquid-fire's 'animate' function reserves the use of Velocity's '" + key + "' option for its own nefarious purposes."); - } - Velocity.defaults[key] = props[key]; - } - } -} - -export function isAnimating(elt, animationLabel) { - return elt && elt.data('lfTags_' + animationLabel); -} - -export function finish(elt, animationLabel) { - return stateForLabel(elt, animationLabel).promise; -} - -export function timeSpent(elt, animationLabel) { - return stateForLabel(elt, animationLabel).timeSpent; -} - -export function timeRemaining(elt, animationLabel) { - return stateForLabel(elt, animationLabel).timeRemaining; -} - - -function stateForLabel(elt, label) { - var state = isAnimating(elt, label); - if (!state) { - throw new Error("no animation labeled " + label + " is in progress"); - } - return state; -} - -function applyLabel(elt, label, state) { - if (elt){ - elt.data('lfTags_' + label, state); - } -} - -function clearLabel(elt, label) { - if (elt) { - elt.data('lfTags_' + label, null); - } -} diff --git a/addon/components/liquid-measured.js b/addon/components/liquid-measured.js deleted file mode 100644 index f8b9a0bd..00000000 --- a/addon/components/liquid-measured.js +++ /dev/null @@ -1,81 +0,0 @@ -import MutationObserver from "liquid-fire/mutation-observer"; -import Ember from "ember"; -import layout from "liquid-fire/templates/components/liquid-measured"; - -export default Ember.Component.extend({ - layout, - didInsertElement: function() { - var self = this; - - // This prevents margin collapse - this.$().css({ - overflow: 'auto' - }); - - this.didMutate(); - - this.observer = new MutationObserver(function(mutations) { self.didMutate(mutations); }); - this.observer.observe(this.get('element'), { - attributes: true, - subtree: true, - childList: true, - characterData: true - }); - this.$().bind('webkitTransitionEnd', function() { self.didMutate(); }); - // Chrome Memory Leak: https://bugs.webkit.org/show_bug.cgi?id=93661 - window.addEventListener('unload', function(){ self.willDestroyElement(); }); - }, - - willDestroyElement: function() { - if (this.observer) { - this.observer.disconnect(); - } - }, - - transitionMap: Ember.inject.service('liquid-fire-transitions'), - - didMutate: function() { - // by incrementing the running transitions counter here we prevent - // tests from falling through the gap between the time they - // triggered mutation the time we may actually animate in - // response. - var tmap = this.get('transitionMap'); - tmap.incrementRunningTransitions(); - Ember.run.next(this, function() { - this._didMutate(); - tmap.decrementRunningTransitions(); - }); - }, - - _didMutate: function() { - var elt = this.$(); - if (!elt || !elt[0]) { return; } - this.set('measurements', measure(elt)); - } - -}); - -export function measure($elt) { - var width, height; - - // if jQuery sees a zero dimension, it will temporarily modify the - // element's css to try to make its size measurable. But that's bad - // for us here, because we'll get an infinite recursion of mutation - // events. So we trap the zero case without hitting jQuery. - - if ($elt[0].offsetWidth === 0) { - width = 0; - } else { - width = $elt.outerWidth(); - } - if ($elt[0].offsetHeight === 0) { - height = 0; - } else { - height = $elt.outerHeight(); - } - - return { - width: width, - height: height - }; -} diff --git a/addon/components/liquid-spacer.js b/addon/components/liquid-spacer.js deleted file mode 100644 index 88a3b85b..00000000 --- a/addon/components/liquid-spacer.js +++ /dev/null @@ -1,63 +0,0 @@ -import { measure } from "./liquid-measured"; -import Growable from "liquid-fire/growable"; -import Ember from "ember"; -import layout from "liquid-fire/templates/components/liquid-spacer"; - -export default Ember.Component.extend(Growable, { - layout, - enabled: true, - - didInsertElement: function() { - var child = this.$('> div'); - var measurements = this.myMeasurements(measure(child)); - this.$().css('overflow', 'hidden') - .outerWidth(measurements.width) - .outerHeight(measurements.height); - }, - - sizeChange: Ember.observer('measurements', function() { - if (!this.get('enabled')) { return; } - var elt = this.$(); - if (!elt || !elt[0]) { return; } - var want = this.myMeasurements(this.get('measurements')); - var have = measure(this.$()); - this.animateGrowth(elt, have, want); - }), - - // given our child's outerWidth & outerHeight, figure out what our - // outerWidth & outerHeight should be. - myMeasurements: function(childMeasurements) { - var elt = this.$(); - return { - width: childMeasurements.width + sumCSS(elt, padding('width')) + sumCSS(elt, border('width')), - height: childMeasurements.height + sumCSS(elt, padding('height')) + sumCSS(elt, border('height')) - }; - //if (this.$().css('box-sizing') === 'border-box') { - } - -}); - -function sides(dimension) { - return dimension === 'width' ? ['Left', 'Right'] : ['Top', 'Bottom']; -} - -function padding(dimension) { - var s = sides(dimension); - return ['padding'+s[0], 'padding'+s[1]]; -} - -function border(dimension) { - var s = sides(dimension); - return ['border'+s[0]+'Width', 'border'+s[1]+'Width']; -} - -function sumCSS(elt, fields) { - var accum = 0; - for (var i=0; i < fields.length; i++) { - var num = parseFloat(elt.css(fields[i]), 10); - if (!isNaN(num)) { - accum += num; - } - } - return accum; -} diff --git a/addon/constrainables.js b/addon/constrainables.js deleted file mode 100644 index 60eb3ec1..00000000 --- a/addon/constrainables.js +++ /dev/null @@ -1,76 +0,0 @@ -import { routeName, routeModel } from "liquid-fire/ember-internals"; - -export default { - oldValue : { - reversesTo: 'newValue', - accessor: function(conditions) { - return [versionValue(conditions, 1)]; - } - }, - newValue: { - reversesTo: 'oldValue', - accessor: function(conditions) { - return [versionValue(conditions, 0)]; - } - }, - oldRoute: { - reversesTo: 'newRoute', - accessor: function(conditions) { - return routeName(versionValue(conditions, 1)); - } - }, - newRoute: { - reversesTo: 'oldRoute', - accessor: function(conditions) { - return routeName(versionValue(conditions, 0)); - } - }, - oldModel: { - reversesTo: 'newModel', - accessor: function(conditions) { - return routeModel(versionValue(conditions, 1)); - } - }, - newModel: { - reversesTo: 'oldModel', - accessor: function(conditions) { - return routeModel(versionValue(conditions, 0)); - } - }, - helperName: {}, - outletName: {}, - parentElementClass: { - accessor: function(conditions) { - var cls = conditions.parentElement.attr('class'); - if (cls) { - return cls.split(/\s+/); - } - } - }, - parentElement: {}, - firstTime: {}, - oldModalComponent: { - reversesTo: 'newModalComponent', - accessor: function(conditions) { - var value = versionValue(conditions, 1); - if (value) { - return [value.name]; - } - } - }, - newModalComponent: { - reversesTo: 'oldModalComponent', - accessor: function(conditions) { - var value = versionValue(conditions, 0); - if (value) { - return [value.name]; - } - } - }, - media: {} -}; - -function versionValue(conditions, index) { - var versions = conditions.versions; - return versions[index] ? versions[index].value : null; -} diff --git a/addon/constraint.js b/addon/constraint.js deleted file mode 100644 index 023eda59..00000000 --- a/addon/constraint.js +++ /dev/null @@ -1,51 +0,0 @@ -import Ember from "ember"; -import constrainables from "./constrainables"; - -// Every rule constraint has a target and either `keys` or -// `predicate`. key-based constraints are cheaper because we can check -// them with O(1) lookups, whereas predicates must be searched O(n). -export default class Constraint { - constructor(target, matcher) { - // targets are the properties of a transition that we can - // constrain - this.target = target; - if (arguments.length === 1) { return; } - if (matcher instanceof RegExp) { - this.predicate = function(value) { return matcher.test(value); }; - } else if (typeof matcher === 'function') { - this.predicate = matcher; - } else if (typeof matcher === 'boolean') { - this.predicate = function(value) { return matcher ? value : !value; }; - } else { - this.keys = constraintKeys(matcher); - } - } - - invert() { - if (!constrainables[this.target].reversesTo) { - return this; - } - var inverse = new this.constructor(constrainables[this.target].reversesTo); - inverse.predicate = this.predicate; - inverse.keys = this.keys; - return inverse; - } -} - -export var EMPTY = '__liquid_fire_EMPTY__'; -export var ANY = '__liquid_fire_ANY__'; - -export function constraintKeys(matcher) { - if (typeof matcher === 'undefined' || matcher === null) { - matcher = [ EMPTY ]; - } else if (!Ember.isArray(matcher)) { - matcher = [matcher]; - } - return Ember.A(matcher).map((elt) => { - if (typeof elt === 'string') { - return elt; - } else { - return Ember.guidFor(elt); - } - }); -} diff --git a/addon/constraints.js b/addon/constraints.js deleted file mode 100644 index 722a3fde..00000000 --- a/addon/constraints.js +++ /dev/null @@ -1,240 +0,0 @@ -/* globals console */ - -import Ember from 'ember'; -import { constraintKeys, EMPTY, ANY } from './constraint'; -import constrainables from "./constrainables"; - -export default class Constraints { - constructor() { - this.targets = {}; - this.ruleCounter = 0; - for (var i = 0; i < constrainableKeys.length; i++) { - this.targets[constrainableKeys[i]] = {}; - } - } - - addRule(rule) { - rule.id = this.ruleCounter++; - if (rule.debug) { - this.debug = true; - } - this.addHalfRule(rule); - if (rule.reverse) { - var inverted = rule.invert(); - inverted.id = rule.id + ' reverse'; - this.addHalfRule(inverted); - } - } - - addHalfRule(rule) { - var seen = {}; - rule.constraints.forEach((constraint) => { - seen[constraint.target] = true; - this.addConstraint(rule, constraint); - }); - constrainableKeys.forEach((key) => { - if (!seen[key]) { - this.addConstraint(rule, { target: key }); - } - }); - } - - addConstraint(rule, constraint) { - var context = this.targets[constraint.target]; - if (!context) { - throw new Error(`Unknown constraint target ${constraint.target}`); - } - if (constraint.keys) { - constraint.keys.forEach((key) => { - this.addKey(context, key, rule); - }); - } else { - this.addKey(context, ANY, rule); - } - } - - addKey(context, key, rule) { - if (!context[key]) { - context[key] = {}; - } - context[key][Ember.guidFor(rule)] = rule; - } - - bestMatch(conditions) { - if (this.debug) { - console.log("[liquid-fire] Checking transition rules for", conditions.parentElement[0]); - } - - var rules = this.match(conditions); - var best = highestPriority(rules); - - if (rules.length > 1 && this.debug) { - rules.forEach((rule) => { - if (rule !== best && rule.debug) { - console.log(`${describeRule(rule)} matched, but it was superceded by another rule`); - } - }); - } - if (best && best.debug) { - console.log(`${describeRule(best)} matched`); - } - return best; - } - - match(conditions) { - var rules = this.matchByKeys(conditions); - rules = this.matchPredicates(conditions, rules); - return rules; - } - - matchByKeys(conditions) { - var matchSets = []; - for (var i = 0; i < constrainableKeys.length; i++) { - var key = constrainableKeys[i]; - var value = conditionAccessor(conditions, key); - matchSets.push(this.matchingSet(key, value)); - } - return intersection(matchSets); - } - - matchingSet(prop, value) { - var keys = constraintKeys(value); - var context = this.targets[prop]; - var matched = Ember.A(); - for (var i = 0; i < keys.length; i++) { - if (context[keys[i]]) { - matched.push(context[keys[i]]); - } - } - if (keys.length === 0 && context[EMPTY]) { - matched.push(context[EMPTY]); - } - if (context[ANY]) { - matched.push(context[ANY]); - } - matched = union(matched); - if (this.debug) { - this.logDebugRules(matched, context, prop, value); - } - return matched; - } - - logDebugRules(matched, context, target, value) { - Ember.A(Object.keys(context)).forEach((setKey) => { - var set = context[setKey]; - Ember.A(Object.keys(set)).forEach((ruleKey) => { - var rule = set[ruleKey]; - if (rule.debug && !matched[Ember.guidFor(rule)]) { - console.log(`${describeRule(rule)} rejected because ${target} was`, ...value); - } - }); - }); - } - - matchPredicates(conditions, rules) { - var output = []; - for (var i = 0; i < rules.length; i++) { - var rule = rules[i]; - var matched = true; - for (var j = 0; j < rule.constraints.length; j++) { - var constraint = rule.constraints[j]; - if (constraint.predicate && !this.matchConstraintPredicate(conditions, rule, constraint)) { - matched = false; - break; - } - } - if (matched) { - output.push(rule); - } - } - return output; - } - - matchConstraintPredicate(conditions, rule, constraint) { - var values = conditionAccessor(conditions, constraint.target); - var reverse = constrainables[constraint.target].reversesTo; - var inverseValues; - if (reverse) { - inverseValues = conditionAccessor(conditions, reverse); - } - for (var i = 0; i < values.length; i++) { - if (constraint.predicate(values[i], inverseValues ? inverseValues[i] : null)) { - return true; - } - } - if (rule.debug) { - if (constraint.target === 'parentElement') { - values = values.map((v)=>v[0]); - } - console.log(`${describeRule(rule)} rejected because of a constraint on ${constraint.target}. ${constraint.target} was`, ...values); - } - } -} - -function conditionAccessor(conditions, key) { - var constrainable = constrainables[key]; - if (constrainable.accessor) { - return constrainable.accessor(conditions) || []; - } else { - return [conditions[key]]; - } -} - -// Returns a list of property values from source whose keys also -// appear in all of the rest objects. -function intersection(sets) { - var source = sets[0]; - var rest = sets.slice(1); - var keys = Object.keys(source); - var keysLength = keys.length; - var restLength = rest.length; - var result = []; - for (var keyIndex = 0; keyIndex < keysLength; keyIndex++) { - var key = keys[keyIndex]; - var matched = true; - for (var restIndex = 0; restIndex < restLength; restIndex++) { - if (!rest[restIndex].hasOwnProperty(key)) { - matched = false; - break; - } - } - if (matched) { - result.push(source[key]); - } - } - return result; -} - -function union(sets) { - var setsLength = sets.length; - var output = {}; - for (var i = 0; i < setsLength; i++) { - var set = sets[i]; - var keys = Object.keys(set); - for (var j = 0; j < keys.length; j++) { - var key = keys[j]; - output[key] = set[key]; - } - } - return output; -} - -function describeRule(rule) { - return `[liquid-fire rule ${rule.id}]`; -} - -function highestPriority(rules) { - var best; - var bestScore = 0; - for (var i = 0; i < rules.length; i++) { - var rule = rules[i]; - var score = rules[i].constraints.length; - if (!best || score > bestScore || (score === bestScore && rule.id > best.id)) { - best = rule; - bestScore = score; - } - } - return best; -} - -var constrainableKeys = Ember.A(Object.keys(constrainables)); diff --git a/addon/dsl.js b/addon/dsl.js deleted file mode 100644 index 709f8179..00000000 --- a/addon/dsl.js +++ /dev/null @@ -1,139 +0,0 @@ -import { setDefaults } from "./animate"; -import Rule from "./rule"; -import Constraint from "./constraint"; -import Action from "./action"; - -export default class DSL { - - constructor(map) { - this.map = map; - } - - setDefault(props) { - setDefaults(props); - } - - transition() { - var rule = new Rule(); - var parts = Array.prototype.slice.apply(arguments).reduce(function(a,b){ - return a.concat(b); - }, []); - - for (var i = 0; i < parts.length; i++) { - rule.add(parts[i]); - } - - this.map.addRule(rule); - } - - fromRoute(routeName) { - return [ - new Constraint('oldRoute', routeName) - ]; - } - - toRoute(routeName) { - return [ - new Constraint('newRoute', routeName) - ]; - } - - withinRoute(routeName) { - return this.fromRoute(routeName).concat(this.toRoute(routeName)); - } - - fromValue(matcher) { - return [ - new Constraint('oldValue', matcher) - ]; - } - - toValue(matcher) { - return [ - new Constraint('newValue', matcher) - ]; - } - - betweenValues(matcher) { - return this.fromValue(matcher).concat(this.toValue(matcher)); - } - - fromModel(matcher) { - return [ - new Constraint('oldModel', matcher) - ]; - } - - toModel(matcher) { - return [ - new Constraint('newModel', matcher) - ]; - } - - betweenModels(matcher) { - return this.fromModel(matcher).concat(this.toModel(matcher)); - } - - hasClass(name) { - return new Constraint('parentElementClass', name); - } - - matchSelector(selector) { - return new Constraint('parentElement', function(elt) { - return elt.is(selector); - }); - } - - childOf(selector) { - return this.matchSelector(selector + ' > *'); - } - - use(nameOrHandler, ...args) { - return new Action(nameOrHandler, args); - } - - reverse(nameOrHandler, ...args) { - return new Action(nameOrHandler, args, { reversed: true }); - } - - useAndReverse(nameOrHandler, ...args) { - return [ - this.use(nameOrHandler, ...args), - this.reverse(nameOrHandler, ...args) - ]; - } - - onInitialRender() { - return new Constraint('firstTime', 'yes'); - } - - includingInitialRender() { - return new Constraint('firstTime', ['yes', 'no']); - } - - inHelper(...names) { - return new Constraint('helperName', names); - } - - outletName(...names) { - return new Constraint('outletName', names); - } - - toModal(matcher) { - return new Constraint('newModalComponent', matcher); - } - - fromModal(matcher) { - return new Constraint('oldModalComponent', matcher); - } - - media(query) { - return new Constraint('media', function() { - return window.matchMedia(query).matches; - }); - } - - debug() { - return 'debug'; - } -} diff --git a/addon/ember-internals.js b/addon/ember-internals.js deleted file mode 100644 index 78eddb69..00000000 --- a/addon/ember-internals.js +++ /dev/null @@ -1,142 +0,0 @@ -/* - This module is intended to encapsulate all the known places where - liquid-fire depends on non-public Ember APIs. - */ - -import Ember from "ember"; -var emberRequire = Ember.__loader.require; -var internal = emberRequire('htmlbars-runtime').internal; -var registerKeyword = emberRequire('ember-htmlbars/keywords').registerKeyword; -var legacyViewKeyword = emberRequire('ember-htmlbars/keywords/view').default; -var _Stream = emberRequire('ember-metal/streams/stream'); -var BasicStream = _Stream.default; -var Stream = _Stream.Stream; - -var isStable; -try { - isStable = emberRequire('ember-htmlbars/keywords/real_outlet').default.isStable; -} catch (err) { - isStable = emberRequire('ember-htmlbars/keywords/outlet').default.isStable; -} - -// Given an Ember Component, return the containing element -export function containingElement(view) { - return view._renderNode.contextualElement; -} - -// This is Ember's {{#if}} predicate semantics (where empty lists -// count as false, etc). -export var shouldDisplay = emberRequire('ember-views/streams/should_display').default; - -// Finds the route name from a route state so we can apply our -// matching rules to it. -export function routeName(routeIdentity) { - var o, r; - if (routeIdentity && (o = routeIdentity.outletState) && (r = o.render)) { - return [ r.name ]; - } -} - -// Finds the route's model from a route state so we can apply our -// matching rules to it. -export function routeModel(routeIdentity) { - var o; - if (routeIdentity && (o = routeIdentity.outletState)) { - return [ o._lf_model ]; - } -} - -function withLockedModel(outletState) { - var r, c; - if (outletState && (r = outletState.render) && (c = r.controller) && !outletState._lf_model) { - outletState = Ember.copy(outletState); - outletState._lf_model = c.get('model'); - } - return outletState; -} - -export function registerKeywords() { - registerKeyword('get-outlet-state', { - willRender(renderNode, env) { - env.view.ownerView._outlets.push(renderNode); - }, - - setupState(lastState, env, scope, params) { - var outletName = env.hooks.getValue(params[0]); - var stream = lastState.stream; - var source = lastState.source; - if (!stream) { - source = { identity: { - outletState: withLockedModel(env.outletState[outletName]) - }}; - - if (!!Stream) { - stream = new Stream(function() { - return source.identity; - }); - } else { - stream = new BasicStream(function() { - return source.identity; - }); - } - } - return { stream, source, outletName }; - }, - - render(renderNode, env, scope, params, hash, template, inverse, visitor) { - internal.hostBlock(renderNode, env, scope, template, null, null, visitor, function(options) { - var stream = renderNode.getState ? renderNode.getState().stream : renderNode.state.stream; - options.templates.template.yield([stream]); - }); - - }, - rerender(morph, env) { - var state = morph._state ? morph._state : morph.state; - var newState = withLockedModel(env.outletState[state.outletName]); - - if (isStable(state.source.identity, { outletState: newState })) { - // If our own view was stable, we preserve the same object - // identity so that liquid-versions will not animate us. But - // we still need to propagate any child changes forward. - Ember.set(state.source.identity, 'outletState', newState); - } else { - // If our own view has changed, we present a whole new object, - // so that liquid-versions will see the change. - state.source.identity = { outletState: newState }; - } - - state.stream.notify(); - }, - isStable() { - return true; - } - }); - - registerKeyword('set-outlet-state', { - setupState(state, env, scope, params) { - var outletName = env.hooks.getValue(params[0]); - var outletState = env.hooks.getValue(params[1]); - return { outletState: { [ outletName ] : outletState }}; - }, - - childEnv(state, env) { - return env.childWithOutletState(state.outletState); - }, - - render(renderNode, env, scope, params, hash, template, inverse, visitor) { - internal.hostBlock(renderNode, env, scope, template, null, null, visitor, function(options) { - options.templates.template.yield(); - }); - }, - - isStable() { - return true; - } - }); - - // This gives us a non-deprecated view keyword so we can continue to - // ship the old liquid-modal template for now without breaking - // people's apps. liquid-modal itself is deprecated and will ship in - // 1.13 but not 2.0. - registerKeyword('lf-vue', legacyViewKeyword); -} diff --git a/addon/growable.js b/addon/growable.js deleted file mode 100644 index 45711130..00000000 --- a/addon/growable.js +++ /dev/null @@ -1,42 +0,0 @@ -import Ember from "ember"; -import Promise from "liquid-fire/promise"; -var capitalize = Ember.String.capitalize; - -export default Ember.Mixin.create({ - growDuration: 250, - growPixelsPerSecond: 200, - growEasing: 'slide', - - transitionMap: Ember.inject.service('liquid-fire-transitions'), - - animateGrowth: function(elt, have, want) { - this.get('transitionMap').incrementRunningTransitions(); - return Promise.all([ - this._adaptDimension(elt, 'width', have, want), - this._adaptDimension(elt, 'height', have, want) - ]).then(()=>{ - this.get('transitionMap').decrementRunningTransitions(); - }); - }, - - _adaptDimension: function(elt, dimension, have, want) { - if (have[dimension] === want[dimension]) { - return Promise.resolve(); - } - var target = {}; - target['outer'+capitalize(dimension)] = [ - want[dimension], - have[dimension], - ]; - return Ember.$.Velocity(elt[0], target, { - duration: this._durationFor(have[dimension], want[dimension]), - queue: false, - easing: this.get('growEasing') || this.constructor.prototype.growEasing - }); - }, - - _durationFor: function(before, after) { - return Math.min(this.get('growDuration') || this.constructor.prototype.growDuration, 1000*Math.abs(before - after)/(this.get('growPixelsPerSecond') || this.constructor.prototype.growPixelsPerSecond)); - } - -}); diff --git a/addon/index.js b/addon/index.js deleted file mode 100644 index 1b1ad368..00000000 --- a/addon/index.js +++ /dev/null @@ -1,15 +0,0 @@ -import TransitionMap from "./transition-map"; -import { animate, stop, isAnimating, timeSpent, timeRemaining, finish } from "./animate"; -import Promise from "./promise"; -import MutationObserver from "./mutation-observer"; -import versionWarnings from "./version-warnings"; -import "./velocity-ext"; - -versionWarnings({ - minEmberVersion: [1, 11], - minVelocityVersion: [0, 11, 8] -}); - - -export { TransitionMap, animate, stop, isAnimating, timeSpent, timeRemaining, finish, - Promise, MutationObserver }; diff --git a/addon/internal-rules.js b/addon/internal-rules.js deleted file mode 100644 index a543c175..00000000 --- a/addon/internal-rules.js +++ /dev/null @@ -1,16 +0,0 @@ -export default function() { - this.setDefault({duration: 250}); - // BEGIN-SNIPPET default-modal-rule - this.transition( - this.inHelper('liquid-modal'), - this.use('explode', { - pick: '.lf-overlay', - use: ['cross-fade', { maxOpacity: 0.5 }] - }, { - pick: '.lm-container', - use: 'scale' - }) - ); - // END-SNIPPET - -} diff --git a/addon/is-browser.js b/addon/is-browser.js deleted file mode 100644 index fce6eebf..00000000 --- a/addon/is-browser.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function isBrowser() { - return (typeof window !== 'undefined') && window && (typeof document !== 'undefined') && document; -} \ No newline at end of file diff --git a/addon/modal.js b/addon/modal.js deleted file mode 100644 index 7be341ed..00000000 --- a/addon/modal.js +++ /dev/null @@ -1,79 +0,0 @@ -import Ember from "ember"; -import getOwner from 'ember-getowner-polyfill'; -var get = Ember.get; - - -export default Ember.Object.extend({ - - enabled: Ember.computed('modals.activeRouteNames', function() { - return get(this, 'modals.activeRouteNames').indexOf(get(this, 'route')) >= 0; - }), - - controller: Ember.computed('enabled', function() { - if (!get(this, 'enabled')) { return; } - var owner = getOwner(this); - var name = get(this, 'options.controller') || get(this, 'route'); - return owner.lookup('controller:' + name); - }), - - update: Ember.observer('controller', Ember.on('init', function() { - var context = this.makeContext(); - var activeContexts = get(this, 'modals.modalContexts'); - var matchingContext = activeContexts.find((c) => get(c, 'modal') === this); - - if (context) { - if (matchingContext) { - activeContexts.replace(activeContexts.indexOf(matchingContext), 1, [context]); - } else { - activeContexts.pushObject(context); - } - } else { - if (matchingContext) { - activeContexts.removeObject(matchingContext); - } - } - })), - - makeContext: function() { - var params, - controller = get(this, 'controller'); - - if (!controller) { return; } - - params = currentParams(controller, get(this, 'options.withParams')); - if (params) { - return Ember.Object.create({ - modal: this, - source: controller, - name: get(this, 'name'), - options: get(this, 'options'), - params: params - }); - } - } - -}); - -function currentParams(controller, paramMap) { - var params = {}; - var proto = controller.constructor.proto(); - var foundNonDefault = false; - var to, from, value, defaultValue; - - for (from in paramMap) { - to = paramMap[from]; - value = controller.get(from); - params[to] = value; - defaultValue = proto[from]; - if (defaultValue instanceof Ember.ComputedProperty) { - defaultValue = undefined; - } - if (value !== defaultValue) { - foundNonDefault = true; - } - } - - if (foundNonDefault) { - return params; - } -} diff --git a/addon/modals.js b/addon/modals.js deleted file mode 100644 index 1f2ea3bf..00000000 --- a/addon/modals.js +++ /dev/null @@ -1,78 +0,0 @@ -import Ember from "ember"; -import getOwner from 'ember-getowner-polyfill'; -import Modal from "./modal"; - -export default Ember.Service.extend({ - routing: Ember.inject.service('-routing'), - - setup: Ember.on('init', function() { - - this.set('modalContexts', Ember.A()); - this.set('modals', Ember.A()); - - var owner = getOwner(this); - var modalConfigs = owner.lookup('router:main').router.modals; - if (modalConfigs && modalConfigs.length > 0) { - var self = this; - modalConfigs.forEach(function(m){ self.registerModal(m); }); - } - }), - - registerModal: function(config) { - var ext = { - modals: this - }; - - for (var param in config.options.withParams) { - ext[param + "Observer"] = observerForParam(param); - } - - var owner = getOwner(this); - if (Ember.setOwner) { - Ember.setOwner(ext, owner); - } else { - ext.container = this.container; - } - - var ExtendedModal = Modal.extend(ext); - - if (Ember.setOwner) { - var serviceContext = this; - - Object.defineProperty(ExtendedModal.prototype, 'container', { - configurable: true, - enumerable: false, - get() { - Ember.deprecate('Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.', - false, - { id: 'ember-application.injected-container', until: '3.0.0' }); - - return serviceContext.container; - } - }); - } - - this.get('modals').pushObject( - Modal.extend(ext).create(config) - ); - }, - - activeRouteNames: Ember.computed('routing.currentRouteName', function() { - // We need this to force the right observers to all be in place - // for invalidation, even though we aren't use it directly. - this.get('routing.currentRouteName'); - - var owner = getOwner(this); - var infos = owner.lookup('router:main').router.currentHandlerInfos; - if (infos) { - return infos.map(function(h){ return h.name; }); - } else { - return []; - } - }) - -}); - -function observerForParam(param) { - return Ember.observer('controller.' + param, function() { this.update(); }); -} diff --git a/addon/mutation-observer.js b/addon/mutation-observer.js deleted file mode 100644 index be5c7346..00000000 --- a/addon/mutation-observer.js +++ /dev/null @@ -1,35 +0,0 @@ -import isBrowser from './is-browser'; -var activePollers = []; - -function MutationPoller(callback){ - this.callback = callback; -} - -MutationPoller.prototype = { - observe: function(){ - this.interval = setInterval(this.callback, 100); - activePollers.push(this); - }, - disconnect: function() { - clearInterval(this.interval); - activePollers.splice(activePollers.indexOf(this), 1); - } -}; - -var M; -if (isBrowser()) { - M = (window.MutationObserver || window.WebkitMutationObserver || MutationPoller); -} else { - M = MutationPoller; -} - - -export default M; - -// PhantomJS does not have real mutation observers, so to get -// reasonable test timing we have to manually kick it. -export function testingKick() { - for (var i = 0; i < activePollers.length; i ++) { - activePollers[i].callback(); - } -} diff --git a/addon/promise.js b/addon/promise.js deleted file mode 100644 index 61caeed4..00000000 --- a/addon/promise.js +++ /dev/null @@ -1,3 +0,0 @@ -// Ember is already polyfilling Promise as needed, so just use that. -import Ember from "ember"; -export default Ember.RSVP.Promise; diff --git a/addon/router-dsl-ext.js b/addon/router-dsl-ext.js deleted file mode 100644 index ba745fcc..00000000 --- a/addon/router-dsl-ext.js +++ /dev/null @@ -1,84 +0,0 @@ -import Ember from "ember"; -var Router = Ember.Router; -var proto = Ember.RouterDSL.prototype; - -var currentMap = null; - -proto.modal = function(componentName, opts) { - - Ember.assert('modal("' + componentName + '",...) needs a `withParams` argument', opts && opts.withParams); - - opts = Ember.copy(opts); - - opts.withParams = expandParamOptions(opts.withParams); - opts.otherParams = expandParamOptions(opts.otherParams); - - if (typeof(opts.dismissWithOutsideClick) === 'undefined') { - opts.dismissWithOutsideClick = true; - } - - if (typeof(opts.dismissWithEscape) === 'undefined') { - opts.dismissWithEscape = true; - } - - currentMap.push({ - route: this.parent, - name: componentName, - options: opts - }); -}; - -// 1.10 and above -Router.reopen({ - _initRouterJs: function() { - currentMap = []; - this._super.apply(this, arguments); - this.router.modals = currentMap; - } -}); - -// 1.9 and below -var origMap = Router.map; -Router.reopenClass({ - map: function() { - currentMap = []; - var output = origMap.apply(this, arguments); - if (this.router) { - this.router.modals = currentMap; - } - return output; - } -}); - - -// takes string, array of strings, object, or array of objects and strings -// and turns them into one object to map withParams/otherParams from context to modal -// -// "foo" => { foo: "foo" } -// ["foo"] => { foo: "foo" } -// { foo: "bar" } => { foo: "bar" } -// ["foo", { bar: "baz" }] => { foo: "foo", bar: "baz" } -// -function expandParamOptions(options) { - if (!options) { return {}; } - - if (!Ember.isArray(options)) { - options = [options]; - } - - var params = {}; - var option, i, key; - - for (i = 0; i < options.length; i++) { - option = options[i]; - if (typeof option === "object") { - for (key in option) { - params[key] = option[key]; - } - } else { - params[option] = option; - } - } - - return params; - } \ No newline at end of file diff --git a/addon/rule.js b/addon/rule.js deleted file mode 100644 index 06c7caa0..00000000 --- a/addon/rule.js +++ /dev/null @@ -1,50 +0,0 @@ -import Ember from "ember"; -import Action from "./action"; -import Constraint from "./constraint"; - -export default class Rule { - constructor() { - this.constraints = Ember.A(); - this.use = null; - this.reverse = null; - } - - add(thing) { - if (thing instanceof Action) { - var prop = 'use'; - if (thing.reversed) { - prop = 'reverse'; - } - if (this[prop]) { - throw new Error(`More than one "${prop}" statement in the same transition rule is not allowed`); - } - this[prop] = thing; - } else if (thing === 'debug') { - this.debug = true; - } else { - this.constraints.push(thing); - } - } - - validate(transitionMap) { - if (!this.use) { - throw new Error(`Every transition rule must include a "use" statement`); - } - this.use.validateHandler(transitionMap); - if (this.reverse) { - this.reverse.validateHandler(transitionMap); - } - if (!this.constraints.find((c) => c.target === 'firstTime')) { - this.constraints.push(new Constraint('firstTime', 'no')); - } - } - - invert() { - var rule = new this.constructor(); - rule.use = this.reverse; - rule.reverse = this.use; - rule.constraints = this.constraints.map((c) => c.invert()); - rule.debug = this.debug; - return rule; - } -} diff --git a/addon/running-transition.js b/addon/running-transition.js deleted file mode 100644 index d1ec0d3c..00000000 --- a/addon/running-transition.js +++ /dev/null @@ -1,79 +0,0 @@ -import Ember from "ember"; - -export default class RunningTransition { - constructor(transitionMap, versions, animation) { - this.transitionMap = transitionMap; - this.animation = animation || transitionMap.lookup('default'); - this.animationContext = publicAnimationContext(this, versions); - } - - run() { - if (this._ran) { - return this._ran; - } - - this.transitionMap.incrementRunningTransitions(); - return this._ran = this._invokeAnimation().catch((err) => { - // If the animation blew up, try to leave the DOM in a - // non-broken state as best we can before rethrowing. - return this.transitionMap.lookup('default').apply(this.animationContext) - .then(function(){ throw err; }); - }).finally(() => { - this.transitionMap.decrementRunningTransitions(); - }); - } - - interrupt() { - this.interrupted = true; - this.animationContext.oldElement = null; - this.animationContext.newElement = null; - this.animationContext.older.forEach((entry) => { - entry.element = null; - }); - } - - _invokeAnimation() { - return this.animation.run(this.animationContext).then(() => { - return this.interrupted; - }); - } -} - -// This defines the public set of things that user's transition -// implementations can access as `this`. -function publicAnimationContext(rt, versions) { - var c = {}; - addPublicVersion(c, 'new', versions[0]); - if (versions[1]) { - addPublicVersion(c, 'old', versions[1]); - } - c.older = versions.slice(2).map((v) => { - var context = {}; - addPublicVersion(context, null, v); - return context; - }); - - // Animations are allowed to look each other up. - c.lookup = function(name) { - return rt.transitionMap.lookup(name); - }; - - return c; -} - -function addPublicVersion(context, prefix, version) { - var props = { - view: version.view, - element: version.view ? version.view.$() : null, - value: version.value - }; - for (var key in props) { - var outputKey = key; - if (props.hasOwnProperty(key)) { - if (prefix) { - outputKey = prefix + Ember.String.capitalize(key); - } - context[outputKey] = props[key]; - } - } -} diff --git a/addon/tabbable.js b/addon/tabbable.js deleted file mode 100644 index 62f03af7..00000000 --- a/addon/tabbable.js +++ /dev/null @@ -1,40 +0,0 @@ -/*! - * Adapted from jQuery UI core - * - * http://jqueryui.com - * - * Copyright 2014 jQuery Foundation and other contributors - * Released under the MIT license. - * http://jquery.org/license - * - * http://api.jqueryui.com/category/ui-core/ - */ - -import Ember from 'ember'; - -var $ = Ember.$; - -function focusable( element, isTabIndexNotNaN ) { - var nodeName = element.nodeName.toLowerCase(); - return ( /input|select|textarea|button|object/.test( nodeName ) ? - !element.disabled : - "a" === nodeName ? - element.href || isTabIndexNotNaN : - isTabIndexNotNaN) && visible( element ); -} - -function visible(element) { - var $el = $(element); - return $.expr.filters.visible(element) && - !$($el, $el.parents()).filter(function() { - return $.css( this, "visibility" ) === "hidden"; - }).length; -} - -if (!$.expr[':'].tabbable) { - $.expr[':'].tabbable = function( element ) { - var tabIndex = $.attr( element, "tabindex" ), - isTabIndexNaN = isNaN( tabIndex ); - return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN ); - }; -} diff --git a/addon/templates/components/liquid-measured.hbs b/addon/templates/components/liquid-measured.hbs deleted file mode 100644 index 889d9eea..00000000 --- a/addon/templates/components/liquid-measured.hbs +++ /dev/null @@ -1 +0,0 @@ -{{yield}} diff --git a/addon/templates/components/liquid-spacer.hbs b/addon/templates/components/liquid-spacer.hbs deleted file mode 100644 index 0c300427..00000000 --- a/addon/templates/components/liquid-spacer.hbs +++ /dev/null @@ -1,3 +0,0 @@ -{{#liquid-measured measurements=measurements}} - {{yield}} -{{/liquid-measured}} diff --git a/addon/transition-map.js b/addon/transition-map.js deleted file mode 100644 index 952877d7..00000000 --- a/addon/transition-map.js +++ /dev/null @@ -1,133 +0,0 @@ -import RunningTransition from "./running-transition"; -import DSL from "./dsl"; -import Ember from "ember"; -import Action from "./action"; -import internalRules from "./internal-rules"; -import Constraints from "./constraints"; -import getOwner from 'ember-getowner-polyfill'; - -var TransitionMap = Ember.Service.extend({ - init: function() { - this.activeCount = 0; - this.constraints = new Constraints(); - this.map(internalRules); - var owner = getOwner(this); - var config = owner._lookupFactory('transitions:main'); - if (config) { - this.map(config); - } - if (Ember.testing) { - this._registerWaiter(); - } - }, - - runningTransitions: function() { - return this.activeCount; - }, - - incrementRunningTransitions: function() { - this.activeCount++; - }, - - decrementRunningTransitions: function() { - this.activeCount--; - Ember.run.next(() => { - this._maybeResolveIdle(); - }); - }, - - waitUntilIdle: function() { - if (this._waitingPromise) { - return this._waitingPromise; - } - return this._waitingPromise = new Ember.RSVP.Promise((resolve) => { - this._resolveWaiting = resolve; - Ember.run.next(() => { - this._maybeResolveIdle(); - }); - }); - }, - - _maybeResolveIdle: function() { - if (this.activeCount === 0 && this._resolveWaiting) { - var resolveWaiting = this._resolveWaiting; - this._resolveWaiting = null; - this._waitingPromise = null; - resolveWaiting(); - } - }, - - lookup: function(transitionName) { - var owner = getOwner(this); - var handler = owner._lookupFactory('transition:' + transitionName); - if (!handler) { - throw new Error("unknown transition name: " + transitionName); - } - return handler; - }, - - defaultAction: function() { - if (!this._defaultAction) { - this._defaultAction = new Action(this.lookup('default')); - } - return this._defaultAction; - }, - - transitionFor: function(conditions) { - var action; - if (conditions.use && conditions.firstTime !== 'yes') { - action = new Action(conditions.use); - action.validateHandler(this); - } else { - var rule = this.constraints.bestMatch(conditions); - if (rule) { - action = rule.use; - } else { - action = this.defaultAction(); - } - } - - return new RunningTransition(this, conditions.versions, action); - }, - - - map: function(handler) { - if (handler){ - handler.apply(new DSL(this)); - } - return this; - }, - - addRule: function(rule) { - rule.validate(this); - this.constraints.addRule(rule); - }, - - _registerWaiter: function() { - var self = this; - this._waiter = function() { - return self.runningTransitions() === 0; - }; - Ember.Test.registerWaiter(this._waiter); - }, - - willDestroy: function() { - if (this._waiter) { - Ember.Test.unregisterWaiter(this._waiter); - this._waiter = null; - } - } - -}); - - -TransitionMap.reopenClass({ - map: function(handler) { - var t = TransitionMap.create(); - t.map(handler); - return t; - } -}); - - -export default TransitionMap; diff --git a/addon/velocity-ext.js b/addon/velocity-ext.js deleted file mode 100644 index 0a8aa723..00000000 --- a/addon/velocity-ext.js +++ /dev/null @@ -1,43 +0,0 @@ -/* - This makes it possible to animate outerHeight and outerWidth with - Velocity, which is much more convenient for our purposes. Submitted - to Velocity as PR #485. -*/ - -import Ember from "ember"; -var VCSS = Ember.$.Velocity.CSS; - -function augmentDimension(name, element) { - var sides = name === 'width' ? ['Left', 'Right' ] : ['Top', 'Bottom']; - - if (VCSS.getPropertyValue(element, "boxSizing").toString().toLowerCase() === 'border-box') { - /* in box-sizing mode, the VCSS width / height accessors already give the outerWidth / outerHeight. */ - return 0; - } else { - var augment = 0; - var fields = ['padding'+sides[0], 'padding'+sides[1], 'border'+sides[0]+'Width', 'border'+sides[1]+'Width']; - for (var i = 0; i < fields.length; i++) { - var value = parseFloat(VCSS.getPropertyValue(element, fields[i])); - if (!isNaN(value)) { - augment += value; - } - } - return augment; - } -} - -function outerDimension(name) { - return function(type, element, propertyValue) { - switch (type) { - case "name": - return name; - case "extract": - return parseFloat(propertyValue) + augmentDimension(name, element); - case "inject": - return (parseFloat(propertyValue) - augmentDimension(name, element)) + "px"; - } - }; -} - -VCSS.Normalizations.registered.outerWidth = outerDimension('width'); -VCSS.Normalizations.registered.outerHeight = outerDimension('height'); diff --git a/addon/version-warnings.js b/addon/version-warnings.js deleted file mode 100644 index ad1c129f..00000000 --- a/addon/version-warnings.js +++ /dev/null @@ -1,25 +0,0 @@ -import Ember from "ember"; - -function emberVersion() { - var m = /^(\d+)\.(\d+)/.exec(Ember.VERSION); - if (!m) { - return [ 0, 0 ]; - } - return [ parseInt(m[1]), parseInt(m[2]) ]; -} - -export default function(args) { - - if (Ember.compare(args.minEmberVersion, emberVersion()) === 1) { - Ember.warn(`This version of liquid fire requires Ember ${ args.minEmberVersion.join('.') } or newer`); - } - - if (!Ember.$.Velocity) { - Ember.warn("Velocity.js is missing"); - } else { - var version = Ember.$.Velocity.version; - if (Ember.compare(args.minVelocityVersion, [version.major, version.minor, version.patch]) === 1) { - Ember.warn("You should probably upgrade Velocity.js, recommended minimum is " + args.minVelocityVersion.join('.')); - } - } -} diff --git a/app/.gitkeep b/app/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/components/lf-outlet.js b/app/components/lf-outlet.js deleted file mode 100644 index 37d51761..00000000 --- a/app/components/lf-outlet.js +++ /dev/null @@ -1,2 +0,0 @@ -import { StaticOutlet } from "liquid-fire/ember-internals"; -export default StaticOutlet; diff --git a/app/components/lf-overlay.js b/app/components/lf-overlay.js deleted file mode 100644 index ddfa5396..00000000 --- a/app/components/lf-overlay.js +++ /dev/null @@ -1,23 +0,0 @@ -import Ember from "ember"; -var COUNTER = '__lf-modal-open-counter'; - -export default Ember.Component.extend({ - tagName: 'span', - classNames: ['lf-overlay'], - - didInsertElement: function() { - var body = Ember.$('body'); - var counter = body.data(COUNTER) || 0; - body.addClass('lf-modal-open'); - body.data(COUNTER, counter+1); - }, - - willDestroy: function() { - var body = Ember.$('body'); - var counter = body.data(COUNTER) || 0; - body.data(COUNTER, counter-1); - if (counter < 2) { - body.removeClass('lf-modal-open lf-modal-closing'); - } - } -}); diff --git a/app/components/liquid-bind.js b/app/components/liquid-bind.js deleted file mode 100644 index 1a2ab0fd..00000000 --- a/app/components/liquid-bind.js +++ /dev/null @@ -1,12 +0,0 @@ -import Ember from 'ember'; - -var LiquidBind = Ember.Component.extend({ - tagName: '', - positionalParams: ['value'] // needed for Ember 1.13.[0-5] and 2.0.0-beta.[1-3] support -}); - -LiquidBind.reopenClass({ - positionalParams: ['value'] -}); - -export default LiquidBind; diff --git a/app/components/liquid-child.js b/app/components/liquid-child.js deleted file mode 100644 index 72217b58..00000000 --- a/app/components/liquid-child.js +++ /dev/null @@ -1,13 +0,0 @@ -import Ember from "ember"; -export default Ember.Component.extend({ - classNames: ['liquid-child'], - - didInsertElement() { - let $container = this.$(); - if ($container) { - $container.css('visibility','hidden'); - } - this.sendAction('liquidChildDidRender', this); - } - -}); diff --git a/app/components/liquid-container.js b/app/components/liquid-container.js deleted file mode 100644 index 611fcc30..00000000 --- a/app/components/liquid-container.js +++ /dev/null @@ -1,142 +0,0 @@ -import Ember from "ember"; -import Growable from "liquid-fire/growable"; -import { measure } from "./liquid-measured"; - -export default Ember.Component.extend(Growable, { - classNames: ['liquid-container'], - - lockSize: function(elt, want) { - elt.outerWidth(want.width); - elt.outerHeight(want.height); - }, - - unlockSize: function() { - var doUnlock = () => { - this.updateAnimatingClass(false); - var elt = this.$(); - if (elt) { - elt.css({width: '', height: ''}); - } - }; - if (this._scaling) { - this._scaling.then(doUnlock); - } else { - doUnlock(); - } - }, - - // We're doing this manually instead of via classNameBindings - // because it depends on upward-data-flow, which generates warnings - // under Glimmer. - updateAnimatingClass(on){ - if (this.isDestroyed || !this._wasInserted) { - return; - } - if (arguments.length === 0) { - on = this.get('liquidAnimating'); - } else { - this.set('liquidAnimating', on); - } - if (on) { - this.$().addClass('liquid-animating'); - } else { - this.$().removeClass('liquid-animating'); - } - }, - - startMonitoringSize: Ember.on('didInsertElement', function() { - this._wasInserted = true; - this.updateAnimatingClass(); - }), - - actions: { - - willTransition: function(versions) { - if (!this._wasInserted) { - return; - } - - // Remember our own size before anything changes - var elt = this.$(); - this._cachedSize = measure(elt); - - // And make any children absolutely positioned with fixed sizes. - for (var i = 0; i < versions.length; i++) { - goAbsolute(versions[i]); - } - - // Apply '.liquid-animating' to liquid-container allowing - // any customizable CSS control while an animating is occuring - this.updateAnimatingClass(true); - }, - - afterChildInsertion: function(versions) { - var elt = this.$(); - var enableGrowth = this.get('enableGrowth') !== false; - - // Measure children - var sizes = []; - for (var i = 0; i < versions.length; i++) { - if (versions[i].view) { - sizes[i] = measure(versions[i].view.$()); - } - } - - // Measure ourself again to see how big the new children make - // us. - var want = measure(elt); - var have = this._cachedSize || want; - - // Make ourself absolute - if (enableGrowth) { - this.lockSize(elt, have); - } else { - this.lockSize(elt, { - height: Math.max(want.height, have.height), - width: Math.max(want.width, have.width), - }); - } - - // Make the children absolute and fixed size. - for (i = 0; i < versions.length; i++) { - goAbsolute(versions[i], sizes[i]); - } - - // Kick off our growth animation - if (enableGrowth) { - this._scaling = this.animateGrowth(elt, have, want); - } - }, - - afterTransition: function(versions) { - for (var i = 0; i < versions.length; i++) { - goStatic(versions[i]); - } - this.unlockSize(); - } - } -}); - -function goAbsolute(version, size) { - if (!version.view) { - return; - } - var elt = version.view.$(); - var pos = elt.position(); - if (!size) { - size = measure(elt); - } - elt.outerWidth(size.width); - elt.outerHeight(size.height); - elt.css({ - position: 'absolute', - top: pos.top, - left: pos.left - }); -} - -function goStatic(version) { - if (version.view && !version.view.isDestroyed) { - version.view.$().css({width: '', height: '', position: ''}); - } -} diff --git a/app/components/liquid-if.js b/app/components/liquid-if.js deleted file mode 100644 index 04139501..00000000 --- a/app/components/liquid-if.js +++ /dev/null @@ -1,19 +0,0 @@ -import Ember from 'ember'; -import { shouldDisplay } from 'liquid-fire/ember-internals'; - -var LiquidIf = Ember.Component.extend({ - positionalParams: ['predicate'], // needed for Ember 1.13.[0-5] and 2.0.0-beta.[1-3] support - tagName: '', - helperName: 'liquid-if', - didReceiveAttrs() { - this._super(); - var predicate = shouldDisplay(this.getAttr('predicate')); - this.set('showFirstBlock', this.inverted ? !predicate : predicate); - } -}); - -LiquidIf.reopenClass({ - positionalParams: ['predicate'] -}); - -export default LiquidIf; diff --git a/app/components/liquid-measured.js b/app/components/liquid-measured.js deleted file mode 100644 index e61d6865..00000000 --- a/app/components/liquid-measured.js +++ /dev/null @@ -1 +0,0 @@ -export { default, measure } from "liquid-fire/components/liquid-measured"; diff --git a/app/components/liquid-modal.js b/app/components/liquid-modal.js deleted file mode 100644 index f11f0a62..00000000 --- a/app/components/liquid-modal.js +++ /dev/null @@ -1,100 +0,0 @@ -import Ember from "ember"; -import getOwner from 'ember-getowner-polyfill'; - -export default Ember.Component.extend({ - classNames: ['liquid-modal'], - currentContext: Ember.computed('owner.modalContexts.lastObject', function(){ - var context = this.get('owner.modalContexts.lastObject'); - if (context) { - context.view = this.innerView(context); - } - return context; - }), - - owner: Ember.inject.service('liquid-fire-modals'), - - innerView: function(current) { - var self = this, - name = current.get('name'), - owner = getOwner(this), - component = owner.lookup('component-lookup:main').lookupFactory(name); - Ember.assert("Tried to render a modal using component '" + name + "', but couldn't find it.", !!component); - - var args = Ember.copy(current.get('params')); - - args.registerMyself = Ember.on('init', function() { - self.set('innerViewInstance', this); - }); - - // set source so we can bind other params to it - args._source = Ember.computed(function() { - return current.get("source"); - }); - - var otherParams = current.get("options.otherParams"); - var from, to; - for (from in otherParams) { - to = otherParams[from]; - args[to] = Ember.computed.alias("_source."+from); - } - - var actions = current.get("options.actions") || {}; - - // Override sendAction in the modal component so we can intercept and - // dynamically dispatch to the controller as expected - args.sendAction = function(name) { - var actionName = actions[name]; - if (!actionName) { - this._super.apply(this, Array.prototype.slice.call(arguments)); - return; - } - - var controller = current.get("source"); - var args = Array.prototype.slice.call(arguments, 1); - args.unshift(actionName); - controller.send.apply(controller, args); - }; - - return component.extend(args); - }, - - actions: { - outsideClick: function() { - if (this.get('currentContext.options.dismissWithOutsideClick')) { - this.send('dismiss'); - } else { - proxyToInnerInstance(this, 'outsideClick'); - } - }, - escape: function() { - if (this.get('currentContext.options.dismissWithEscape')) { - this.send('dismiss'); - } else { - proxyToInnerInstance(this, 'escape'); - } - }, - dismiss: function() { - Ember.$('body').addClass('lf-modal-closing'); - var source = this.get('currentContext.source'), - proto = source.constructor.proto(), - params = this.get('currentContext.options.withParams'), - clearThem = {}; - - for (var key in params) { - if (proto[key] instanceof Ember.ComputedProperty) { - clearThem[key] = undefined; - } else { - clearThem[key] = proto[key]; - } - } - source.setProperties(clearThem); - } - } -}); - -function proxyToInnerInstance(self, message) { - var vi = self.get('innerViewInstance'); - if (vi) { - vi.send(message); - } -} diff --git a/app/components/liquid-outlet.js b/app/components/liquid-outlet.js deleted file mode 100644 index 875f4fcc..00000000 --- a/app/components/liquid-outlet.js +++ /dev/null @@ -1,16 +0,0 @@ -import Ember from "ember"; - -var LiquidOutlet = Ember.Component.extend({ - positionalParams: ['inputOutletName'], // needed for Ember 1.13.[0-5] and 2.0.0-beta.[1-3] support - tagName: '', - didReceiveAttrs() { - this._super(); - this.set('outletName', this.attrs.inputOutletName || 'main'); - } -}); - -LiquidOutlet.reopenClass({ - positionalParams: ['inputOutletName'] -}); - -export default LiquidOutlet; diff --git a/app/components/liquid-spacer.js b/app/components/liquid-spacer.js deleted file mode 100644 index 04e27bb0..00000000 --- a/app/components/liquid-spacer.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from "liquid-fire/components/liquid-spacer"; diff --git a/app/components/liquid-unless.js b/app/components/liquid-unless.js deleted file mode 100644 index 5f349680..00000000 --- a/app/components/liquid-unless.js +++ /dev/null @@ -1,7 +0,0 @@ -import LiquidIf from './liquid-if'; - -export default LiquidIf.extend({ - helperName: 'liquid-unless', - layoutName: 'components/liquid-if', - inverted: true -}); diff --git a/app/components/liquid-versions.js b/app/components/liquid-versions.js deleted file mode 100644 index 80ee2bb3..00000000 --- a/app/components/liquid-versions.js +++ /dev/null @@ -1,120 +0,0 @@ -import Ember from "ember"; -import { containingElement } from "liquid-fire/ember-internals"; - -var get = Ember.get; -var set = Ember.set; - -export default Ember.Component.extend({ - tagName: "", - name: 'liquid-versions', - - transitionMap: Ember.inject.service('liquid-fire-transitions'), - - didReceiveAttrs() { - this._super(); - if (!this.versions || this._lastVersion !== this.getAttr('value')) { - this.appendVersion(); - this._lastVersion = this.getAttr('value'); - } - }, - - appendVersion() { - var versions = this.versions; - var firstTime = false; - var newValue = this.getAttr('value'); - var oldValue; - - if (!versions) { - firstTime = true; - versions = Ember.A(); - } else { - oldValue = versions[0]; - } - - // TODO: may need to extend the comparison to do the same kind of - // key-based diffing that htmlbars is doing. - if (!firstTime && ((!oldValue && !newValue) || - (oldValue === newValue))) { - return; - } - - this.notifyContainer('willTransition', versions); - var newVersion = { - value: newValue, - shouldRender: newValue || get(this, 'renderWhenFalse') - }; - versions.unshiftObject(newVersion); - - this.firstTime = firstTime; - if (firstTime) { - set(this, 'versions', versions); - } - - if (!newVersion.shouldRender && !firstTime) { - this._transition(); - } - }, - - _transition: function() { - var versions = get(this, 'versions'); - var transition; - var firstTime = this.firstTime; - this.firstTime = false; - - - this.notifyContainer('afterChildInsertion', versions); - - transition = get(this, 'transitionMap').transitionFor({ - versions: versions, - parentElement: Ember.$(containingElement(this)), - use: get(this, 'use'), - // Using strings instead of booleans here is an - // optimization. The constraint system can match them more - // efficiently, since it treats boolean constraints as generic - // "match anything truthy/falsy" predicates, whereas string - // checks are a direct object property lookup. - firstTime: firstTime ? 'yes' : 'no', - helperName: get(this, 'name'), - outletName: get(this, 'outletName') - }); - - if (this._runningTransition) { - this._runningTransition.interrupt(); - } - this._runningTransition = transition; - - transition.run().then((wasInterrupted) => { - // if we were interrupted, we don't handle the cleanup because - // another transition has already taken over. - if (!wasInterrupted) { - this.finalizeVersions(versions); - this.notifyContainer("afterTransition", versions); - } - }, (err) => { - this.finalizeVersions(versions); - this.notifyContainer("afterTransition", versions); - throw err; - }); - - }, - - finalizeVersions: function(versions) { - versions.replace(1, versions.length - 1); - }, - - notifyContainer: function(method, versions) { - var target = get(this, 'notify'); - if (target) { - target.send(method, versions); - } - }, - - actions: { - childDidRender: function(child) { - var version = get(child, 'version'); - set(version, 'view', child); - this._transition(); - } - } - -}); diff --git a/app/components/liquid-with.js b/app/components/liquid-with.js deleted file mode 100644 index 0b7c7df9..00000000 --- a/app/components/liquid-with.js +++ /dev/null @@ -1,16 +0,0 @@ -import Ember from "ember"; - -var LiquidWith = Ember.Component.extend({ - name: 'liquid-with', - positionalParams: ['value'], // needed for Ember 1.13.[0-5] and 2.0.0-beta.[1-3] support - tagName: '', - iAmDeprecated: Ember.on('init', function() { - Ember.deprecate("liquid-with is deprecated, use liquid-bind instead -- it accepts a block now."); - }) -}); - -LiquidWith.reopenClass({ - positionalParams: ['value'] -}); - -export default LiquidWith; diff --git a/app/components/lm-container.js b/app/components/lm-container.js deleted file mode 100644 index 5a11966c..00000000 --- a/app/components/lm-container.js +++ /dev/null @@ -1,96 +0,0 @@ -/* - Parts of this file were adapted from ic-modal - - https://github.com/instructure/ic-modal - Released under The MIT License (MIT) - Copyright (c) 2014 Instructure, Inc. -*/ - -import Ember from "ember"; -import "liquid-fire/tabbable"; -import isBrowser from "liquid-fire/is-browser"; - -/** - * If you do something to move focus outside of the browser (like - * command+l to go to the address bar) and then tab back into the - * window, capture it and focus the first tabbable element in an active - * modal. - */ -var lastOpenedModal = null; - -if (isBrowser()) { - Ember.$(document).on('focusin', handleTabIntoBrowser); -} - - -function handleTabIntoBrowser() { - if (lastOpenedModal) { - lastOpenedModal.focus(); - } -} - - -export default Ember.Component.extend({ - classNames: ['lm-container'], - attributeBindings: ['tabindex'], - tabindex: 0, - - keyUp: function(event) { - // Escape key - if (event.keyCode === 27) { - this.sendAction(); - } - }, - - keyDown: function(event) { - // Tab key - if (event.keyCode === 9) { - this.constrainTabNavigation(event); - } - }, - - didInsertElement: function() { - this.focus(); - lastOpenedModal = this; - }, - - willDestroy: function() { - lastOpenedModal = null; - }, - - focus: function() { - if (this.get('element').contains(document.activeElement)) { - // just let it be if we already contain the activeElement - return; - } - var target = this.$('[autofocus]'); - if (!target.length) { - target = this.$(':tabbable'); - } - - if (!target.length) { - target = this.$(); - } - - target[0].focus(); - }, - - constrainTabNavigation: function(event) { - var tabbable = this.$(':tabbable'); - var finalTabbable = tabbable[event.shiftKey ? 'first' : 'last']()[0]; - var leavingFinalTabbable = ( - finalTabbable === document.activeElement || - // handle immediate shift+tab after opening with mouse - this.get('element') === document.activeElement - ); - if (!leavingFinalTabbable) { return; } - event.preventDefault(); - tabbable[event.shiftKey ? 'last' : 'first']()[0].focus(); - }, - - click: function(event) { - if (event.target === this.get('element')) { - this.sendAction('clickAway'); - } - } -}); diff --git a/app/initializers/liquid-fire.js b/app/initializers/liquid-fire.js deleted file mode 100644 index 30135fd9..00000000 --- a/app/initializers/liquid-fire.js +++ /dev/null @@ -1,10 +0,0 @@ -// This initializer exists only to make sure that the following -// imports happen before the app boots. -import "liquid-fire/router-dsl-ext"; -import { registerKeywords } from "liquid-fire/ember-internals"; -registerKeywords(); - -export default { - name: 'liquid-fire', - initialize: function() {} -}; diff --git a/app/services/liquid-fire-modals.js b/app/services/liquid-fire-modals.js deleted file mode 100644 index 6db75c92..00000000 --- a/app/services/liquid-fire-modals.js +++ /dev/null @@ -1,2 +0,0 @@ -import Modals from "liquid-fire/modals"; -export default Modals; diff --git a/app/services/liquid-fire-transitions.js b/app/services/liquid-fire-transitions.js deleted file mode 100644 index d18d50d5..00000000 --- a/app/services/liquid-fire-transitions.js +++ /dev/null @@ -1,2 +0,0 @@ -import TransitionMap from "liquid-fire/transition-map"; -export default TransitionMap; diff --git a/app/templates/components/liquid-bind.hbs b/app/templates/components/liquid-bind.hbs deleted file mode 100644 index 457cfd56..00000000 --- a/app/templates/components/liquid-bind.hbs +++ /dev/null @@ -1,33 +0,0 @@ -{{#if containerless}} - {{~#liquid-versions value=attrs.value use=use - outletName=attrs.outletName - name="liquid-bind" renderWhenFalse=true class=class as |version| ~}} - {{~#if hasBlock}} - {{~yield version ~}} - {{else}} - {{~version ~}} - {{/if~}} - -{{/liquid-versions ~}} -{{else}} - {{~#liquid-container - id=id - class=class - growDuration=growDuration - growPixelsPerSecond=growPixelsPerSecond - growEasing=growEasing - enableGrowth=enableGrowth - as |container| ~}} - {{~#liquid-versions value=attrs.value notify=container use=use - outletName=attrs.outletName - name="liquid-bind" renderWhenFalse=true as |version| ~}} - - {{~#if hasBlock}} - {{~yield version ~}} - {{else}} - {{~version ~}} - {{/if~}} - - {{/liquid-versions ~}} - {{/liquid-container ~}} -{{/if}} diff --git a/app/templates/components/liquid-container.hbs b/app/templates/components/liquid-container.hbs deleted file mode 100644 index 6d2e6148..00000000 --- a/app/templates/components/liquid-container.hbs +++ /dev/null @@ -1 +0,0 @@ -{{yield this}} \ No newline at end of file diff --git a/app/templates/components/liquid-if.hbs b/app/templates/components/liquid-if.hbs deleted file mode 100644 index ca432937..00000000 --- a/app/templates/components/liquid-if.hbs +++ /dev/null @@ -1,28 +0,0 @@ -{{#if containerless}} - {{#liquid-versions value=showFirstBlock name=helperName - use=use renderWhenFalse=(hasBlock "inverse") class=class as |valueVersion|}} - {{#if valueVersion}} - {{yield}} - {{else}} - {{yield to="inverse"}} - {{/if}} - {{/liquid-versions}} -{{else}} - {{#liquid-container - id=id - class=class - growDuration=growDuration - growPixelsPerSecond=growPixelsPerSecond - growEasing=growEasing - enableGrowth=enableGrowth - as |container|}} - {{#liquid-versions value=showFirstBlock notify=container name=helperName - use=use renderWhenFalse=(hasBlock "inverse") as |valueVersion|}} - {{#if valueVersion}} - {{yield}} - {{else}} - {{yield to="inverse"}} - {{/if}} - {{/liquid-versions}} - {{/liquid-container}} -{{/if}} diff --git a/app/templates/components/liquid-modal.hbs b/app/templates/components/liquid-modal.hbs deleted file mode 100644 index 9288e79c..00000000 --- a/app/templates/components/liquid-modal.hbs +++ /dev/null @@ -1,8 +0,0 @@ -{{#liquid-versions name="liquid-modal" value=currentContext renderWhenFalse=false as |cc|}} - {{#lm-container action="escape" clickAway="outsideClick"}} - - {{/lm-container}} - {{lf-overlay}} -{{/liquid-versions}} diff --git a/app/templates/components/liquid-outlet.hbs b/app/templates/components/liquid-outlet.hbs deleted file mode 100644 index 3132d863..00000000 --- a/app/templates/components/liquid-outlet.hbs +++ /dev/null @@ -1,20 +0,0 @@ -{{~#get-outlet-state outletName as |outletState|~}} - {{#liquid-bind outletState - id=id - class=class - use=use - name="liquid-outlet" - outletName=outletName - containerless=containerless - growDuration=growDuration - growPixelsPerSecond=growPixelsPerSecond - growEasing=growEasing - enableGrowth=enableGrowth - as |version| ~}} - - {{#set-outlet-state outletName version.outletState~}} - {{outlet outletName}} - {{~/set-outlet-state}} - - {{~/liquid-bind~}} -{{/get-outlet-state}} diff --git a/app/templates/components/liquid-versions.hbs b/app/templates/components/liquid-versions.hbs deleted file mode 100644 index fd7107aa..00000000 --- a/app/templates/components/liquid-versions.hbs +++ /dev/null @@ -1,7 +0,0 @@ -{{#each versions key="@identity" as |version| ~}} - {{#if version.shouldRender ~}} - {{#liquid-child version=version liquidChildDidRender="childDidRender" class=class ~}} - {{yield version.value ~}} - {{/liquid-child}} - {{/if}} -{{/each}} diff --git a/app/templates/components/liquid-with.hbs b/app/templates/components/liquid-with.hbs deleted file mode 100644 index 84b13f25..00000000 --- a/app/templates/components/liquid-with.hbs +++ /dev/null @@ -1,18 +0,0 @@ -{{#if containerless}} - {{~#liquid-versions value=attrs.value use=use name=name class=class as |version| ~}} - {{~yield version ~}} - {{/liquid-versions~}} -{{else}} - {{#liquid-container - id=id - class=class - growDuration=growDuration - growPixelsPerSecond=growPixelsPerSecond - growEasing=growEasing - enableGrowth=enableGrowth - as |container| ~}} - {{~#liquid-versions value=attrs.value notify=container use=use name=name as |version| ~}} - {{~yield version ~}} - {{/liquid-versions~}} - {{/liquid-container}} -{{/if}} diff --git a/app/transitions/cross-fade.js b/app/transitions/cross-fade.js deleted file mode 100644 index 0257e2f1..00000000 --- a/app/transitions/cross-fade.js +++ /dev/null @@ -1,10 +0,0 @@ -// BEGIN-SNIPPET cross-fade-definition -import { animate, stop, Promise } from "liquid-fire"; -export default function crossFade(opts={}) { - stop(this.oldElement); - return Promise.all([ - animate(this.oldElement, {opacity: 0}, opts), - animate(this.newElement, {opacity: [(opts.maxOpacity || 1), 0]}, opts) - ]); -} -// END-SNIPPET diff --git a/app/transitions/default.js b/app/transitions/default.js deleted file mode 100644 index ccea8c1d..00000000 --- a/app/transitions/default.js +++ /dev/null @@ -1,12 +0,0 @@ -import { Promise } from "liquid-fire"; - -// This is what we run when no animation is asked for. It just sets -// the newly-added element to visible (because we always start them -// out invisible so that transitions can control their initial -// appearance). -export default function defaultTransition() { - if (this.newElement) { - this.newElement.css({visibility: ''}); - } - return Promise.resolve(); -} diff --git a/app/transitions/explode.js b/app/transitions/explode.js deleted file mode 100644 index 0ea702d1..00000000 --- a/app/transitions/explode.js +++ /dev/null @@ -1,174 +0,0 @@ -import Ember from "ember"; -import { Promise } from "liquid-fire"; - -// Explode is not, by itself, an animation. It exists to pull apart -// other elements so that each of the pieces can be targeted by -// animations. - -export default function explode(...pieces) { - var seenElements = {}; - var sawBackgroundPiece = false; - var promises = pieces.map((piece) => { - if (piece.matchBy) { - return matchAndExplode(this, piece, seenElements); - } else if (piece.pick || piece.pickOld || piece.pickNew){ - return explodePiece(this, piece, seenElements); - } else { - sawBackgroundPiece = true; - return runAnimation(this, piece); - } - }); - if (!sawBackgroundPiece) { - if (this.newElement) { - this.newElement.css({visibility: ''}); - } - if (this.oldElement) { - this.oldElement.css({visibility: 'hidden'}); - } - } - return Promise.all(promises); -} - -function explodePiece(context, piece, seen) { - var childContext = Ember.copy(context); - var selectors = [piece.pickOld || piece.pick, piece.pickNew || piece.pick]; - var cleanupOld, cleanupNew; - - if (selectors[0] || selectors[1]) { - cleanupOld = _explodePart(context, 'oldElement', childContext, selectors[0], seen); - cleanupNew = _explodePart(context, 'newElement', childContext, selectors[1], seen); - if (!cleanupOld && !cleanupNew) { - return Promise.resolve(); - } - } - - return runAnimation(childContext, piece).finally(() => { - if (cleanupOld) { cleanupOld(); } - if (cleanupNew) { cleanupNew(); } - }); -} - -function _explodePart(context, field, childContext, selector, seen) { - var child, childOffset, width, height, newChild; - var elt = context[field]; - - childContext[field] = null; - if (elt && selector) { - child = elt.find(selector).filter(function() { - var guid = Ember.guidFor(this); - if (!seen[guid]) { - seen[guid] = true; - return true; - } - }); - if (child.length > 0) { - childOffset = child.offset(); - width = child.outerWidth(); - height = child.outerHeight(); - newChild = child.clone(); - - // Hide the original element - child.css({visibility: 'hidden'}); - - // If the original element's parent was hidden, hide our clone - // too. - if (elt.css('visibility') === 'hidden') { - newChild.css({ visibility: 'hidden' }); - } - newChild.appendTo(elt.parent()); - newChild.outerWidth(width); - newChild.outerHeight(height); - var newParentOffset = newChild.offsetParent().offset(); - newChild.css({ - position: 'absolute', - top: childOffset.top - newParentOffset.top, - left: childOffset.left - newParentOffset.left, - margin: 0 - }); - - // Pass the clone to the next animation - childContext[field] = newChild; - return function cleanup() { - newChild.remove(); - child.css({visibility: ''}); - }; - } - } -} - -function animationFor(context, piece) { - var name, args, func; - if (!piece.use) { - throw new Error("every argument to the 'explode' animation must include a followup animation to 'use'"); - } - if (Ember.isArray(piece.use) ) { - name = piece.use[0]; - args = piece.use.slice(1); - } else { - name = piece.use; - args = []; - } - if (typeof name === 'function') { - func = name; - } else { - func = context.lookup(name); - } - return function() { - return Promise.resolve(func.apply(this, args)); - }; -} - -function runAnimation(context, piece) { - return new Promise((resolve, reject) => { - animationFor(context, piece).apply(context).then(resolve, reject); - }); -} - -function matchAndExplode(context, piece, seen) { - if (!context.oldElement || !context.newElement) { - return Promise.resolve(); - } - - // reduce the matchBy scope - if (piece.pick) { - context.oldElement = context.oldElement.find(piece.pick); - context.newElement = context.newElement.find(piece.pick); - } - - if (piece.pickOld) { - context.oldElement = context.oldElement.find(piece.pickOld); - } - - if (piece.pickNew) { - context.newElement = context.newElement.find(piece.pickNew); - } - - // use the fastest selector available - var selector; - - if (piece.matchBy === 'id') { - selector = (attrValue) => { return `#${attrValue}`; }; - } else if (piece.matchBy === 'class') { - selector = (attrValue) => { return `.${attrValue}`; }; - } else { - selector = (attrValue) => { - var escapedAttrValue = attrValue.replace(/'/g, "\\'"); - return `[${piece.matchBy}='${escapedAttrValue}']`; - }; - } - - var hits = Ember.A(context.oldElement.find(`[${piece.matchBy}]`).toArray()); - return Promise.all(hits.map((elt) => { - var attrValue = Ember.$(elt).attr(piece.matchBy); - - // if there is no match for a particular item just skip it - if (attrValue === "" || context.newElement.find(selector(attrValue)).length === 0) { - return Promise.resolve(); - } - - return explodePiece(context, { - pick: selector(attrValue), - use: piece.use - }, seen); - })); -} diff --git a/app/transitions/fade.js b/app/transitions/fade.js deleted file mode 100644 index 7e5b6dec..00000000 --- a/app/transitions/fade.js +++ /dev/null @@ -1,37 +0,0 @@ -// BEGIN-SNIPPET fade-definition -import { isAnimating, finish, timeSpent, animate, stop } from "liquid-fire"; -export default function fade(opts={}) { - var firstStep; - var outOpts = opts; - var fadingElement = findFadingElement(this); - - if (fadingElement) { - // We still have some older version that is in the process of - // fading out, so out first step is waiting for it to finish. - firstStep = finish(fadingElement, 'fade-out'); - } else { - if (isAnimating(this.oldElement, 'fade-in')) { - // if the previous view is partially faded in, scale its - // fade-out duration appropriately. - outOpts = { duration: timeSpent(this.oldElement, 'fade-in') }; - } - stop(this.oldElement); - firstStep = animate(this.oldElement, {opacity: 0}, outOpts, 'fade-out'); - } - return firstStep.then(() => { - return animate(this.newElement, {opacity: [(opts.maxOpacity || 1), 0]}, opts, 'fade-in'); - }); -} - -function findFadingElement(context) { - for (var i = 0; i < context.older.length; i++) { - var entry = context.older[i]; - if (isAnimating(entry.element, 'fade-out')) { - return entry.element; - } - } - if (isAnimating(context.oldElement, 'fade-out')) { - return context.oldElement; - } -} -// END-SNIPPET diff --git a/app/transitions/flex-grow.js b/app/transitions/flex-grow.js deleted file mode 100644 index eb952254..00000000 --- a/app/transitions/flex-grow.js +++ /dev/null @@ -1,8 +0,0 @@ -import { animate, stop, Promise } from "liquid-fire"; -export default function flexGrow(opts) { - stop(this.oldElement); - return Promise.all([ - animate(this.oldElement, {'flex-grow': 0}, opts), - animate(this.newElement, {'flex-grow': [1, 0]}, opts) - ]); -} diff --git a/app/transitions/fly-to.js b/app/transitions/fly-to.js deleted file mode 100644 index 28023771..00000000 --- a/app/transitions/fly-to.js +++ /dev/null @@ -1,36 +0,0 @@ -import { animate, Promise } from "liquid-fire"; - -export default function flyTo(opts={}) { - if (!this.newElement) { - return Promise.resolve(); - } else if (!this.oldElement) { - this.newElement.css({visibility: ''}); - return Promise.resolve(); - } - - var oldOffset = this.oldElement.offset(); - var newOffset = this.newElement.offset(); - - - if (opts.movingSide === 'new') { - let motion = { - translateX: [0, oldOffset.left - newOffset.left], - translateY: [0, oldOffset.top - newOffset.top], - outerWidth: [this.newElement.outerWidth(), this.oldElement.outerWidth()], - outerHeight: [this.newElement.outerHeight(), this.oldElement.outerHeight()] - }; - this.oldElement.css({ visibility: 'hidden' }); - return animate(this.newElement, motion, opts); - } else { - let motion = { - translateX: newOffset.left - oldOffset.left, - translateY: newOffset.top - oldOffset.top, - outerWidth: this.newElement.outerWidth(), - outerHeight: this.newElement.outerHeight() - }; - this.newElement.css({ visibility: 'hidden' }); - return animate(this.oldElement, motion, opts).then(() => { - this.newElement.css({ visibility: ''}); - }); - } -} diff --git a/app/transitions/move-over.js b/app/transitions/move-over.js deleted file mode 100644 index 1b33051c..00000000 --- a/app/transitions/move-over.js +++ /dev/null @@ -1,48 +0,0 @@ -import { stop, animate, Promise, isAnimating, finish } from "liquid-fire"; - -export default function moveOver(dimension, direction, opts) { - var oldParams = {}, - newParams = {}, - firstStep, - property, - measure; - - if (dimension.toLowerCase() === 'x') { - property = 'translateX'; - measure = 'width'; - } else { - property = 'translateY'; - measure = 'height'; - } - - if (isAnimating(this.oldElement, 'moving-in')) { - firstStep = finish(this.oldElement, 'moving-in'); - } else { - stop(this.oldElement); - firstStep = Promise.resolve(); - } - - return firstStep.then(() => { - var bigger = biggestSize(this, measure); - oldParams[property] = (bigger * direction) + 'px'; - newParams[property] = ["0px", (-1 * bigger * direction) + 'px']; - - return Promise.all([ - animate(this.oldElement, oldParams, opts), - animate(this.newElement, newParams, opts, 'moving-in') - ]); - }); -} - -function biggestSize(context, dimension) { - var sizes = []; - if (context.newElement) { - sizes.push(parseInt(context.newElement.css(dimension), 10)); - sizes.push(parseInt(context.newElement.parent().css(dimension), 10)); - } - if (context.oldElement) { - sizes.push(parseInt(context.oldElement.css(dimension), 10)); - sizes.push(parseInt(context.oldElement.parent().css(dimension), 10)); - } - return Math.max.apply(null, sizes); -} diff --git a/app/transitions/scale.js b/app/transitions/scale.js deleted file mode 100644 index 2bac610f..00000000 --- a/app/transitions/scale.js +++ /dev/null @@ -1,7 +0,0 @@ -import { animate } from "liquid-fire"; - -export default function scale(opts={}) { - return animate(this.oldElement, {scale: [0.2, 1]}, opts).then(() => { - return animate(this.newElement, {scale: [1, 0.2]}, opts); - }); -} diff --git a/app/transitions/scroll-then.js b/app/transitions/scroll-then.js deleted file mode 100644 index 334379b2..00000000 --- a/app/transitions/scroll-then.js +++ /dev/null @@ -1,30 +0,0 @@ -import Ember from 'ember'; -import isBrowser from "liquid-fire/is-browser"; - -export default function(nextTransitionName, options, ...rest) { - if (isBrowser()) { - Ember.assert( - "You must provide a transition name as the first argument to scrollThen. Example: this.use('scrollThen', 'toLeft')", - 'string' === typeof nextTransitionName - ); - - var el = document.getElementsByTagName('html'); - var nextTransition = this.lookup(nextTransitionName); - if (!options) { options = {}; } - - Ember.assert( - "The second argument to scrollThen is passed to Velocity's scroll function and must be an object", - 'object' === typeof options - ); - - // set scroll options via: this.use('scrollThen', 'ToLeft', {easing: 'spring'}) - options = Ember.merge({duration: 500, offset: 0}, options); - - // additional args can be passed through after the scroll options object - // like so: this.use('scrollThen', 'moveOver', {duration: 100}, 'x', -1); - - return window.$.Velocity(el, 'scroll', options).then(() => { - nextTransition.apply(this, rest); - }); - } -} diff --git a/app/transitions/to-down.js b/app/transitions/to-down.js deleted file mode 100644 index 4f0fb9a5..00000000 --- a/app/transitions/to-down.js +++ /dev/null @@ -1,4 +0,0 @@ -import moveOver from "./move-over"; -export default function(opts) { - return moveOver.call(this, 'y', 1, opts); -} diff --git a/app/transitions/to-left.js b/app/transitions/to-left.js deleted file mode 100644 index 5ff22bbc..00000000 --- a/app/transitions/to-left.js +++ /dev/null @@ -1,4 +0,0 @@ -import moveOver from "./move-over"; -export default function(opts) { - return moveOver.call(this, 'x', -1, opts); -} diff --git a/app/transitions/to-right.js b/app/transitions/to-right.js deleted file mode 100644 index 5ff974ae..00000000 --- a/app/transitions/to-right.js +++ /dev/null @@ -1,4 +0,0 @@ -import moveOver from "./move-over"; -export default function(opts) { - return moveOver.call(this, 'x', 1, opts); -} diff --git a/app/transitions/to-up.js b/app/transitions/to-up.js deleted file mode 100644 index 858f3f37..00000000 --- a/app/transitions/to-up.js +++ /dev/null @@ -1,4 +0,0 @@ -import moveOver from "./move-over"; -export default function(opts) { - return moveOver.call(this, 'y', -1, opts); -} diff --git a/blueprints/transition/files/app/__path__/__name__.js b/blueprints/transition/files/app/__path__/__name__.js deleted file mode 100644 index 830e50c7..00000000 --- a/blueprints/transition/files/app/__path__/__name__.js +++ /dev/null @@ -1,16 +0,0 @@ -import { animate, stop } from "liquid-fire"; - -export default function (oldView, insertNewView) { - - // Stop any currently running animation on oldView - stop(oldView); - - // Fade out the old view - return animate(oldView, { opacity: 0 }) - // Render the new view - .then(insertNewView) - // And fade it in, from opacity 0 to 1 - .then(function(newView){ - return animate(newView, { opacity: [1, 0]}); - }); -} diff --git a/blueprints/transition/index.js b/blueprints/transition/index.js deleted file mode 100644 index 778e36db..00000000 --- a/blueprints/transition/index.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - description: 'Generates a liquid fire transition.' -}; diff --git a/ext/plugins/transform-liquid-with-as-to-hash.js b/ext/plugins/transform-liquid-with-as-to-hash.js deleted file mode 100644 index d16c6221..00000000 --- a/ext/plugins/transform-liquid-with-as-to-hash.js +++ /dev/null @@ -1,60 +0,0 @@ -// Taken from https://github.com/emberjs/ember.js/blob/4a1010a490c09dc4d662d22b229523c8f8734f82/packages/ember-template-compiler/lib/plugins/transform-with-as-to-hash.js - -/** - An HTMLBars AST transformation that replaces all instances of - - ```handlebars - {{#liquid-with foo.bar as bar}} - {{/liquid-with}} - ``` - - with - - ```handlebars - {{#liquid-with foo.bar as |bar|}} - {{/liquid-with}} - ``` -*/ - -function TransformLiquidWithAsToHash() { - this.syntax = null; -} - -TransformLiquidWithAsToHash.prototype.transform = function TransformWithAsToHash_transform(ast) { - var pluginContext = this; - var walker = new pluginContext.syntax.Walker(); - - walker.visit(ast, function(node) { - if (pluginContext.validate(node)) { - - if (node.program && node.program.blockParams.length) { - throw new Error('You cannot use keyword (`{{liquid-with foo as bar}}`) and block params (`{{liquid-with foo as |bar|}}`) at the same time.'); - } - - var removedParams = sexpr(node).params.splice(1, 2); - var keyword = removedParams[1].original; - node.program.blockParams = [keyword]; - } - }); - - return ast; -}; - -TransformLiquidWithAsToHash.prototype.validate = function TransformWithAsToHash_validate(node) { - return node.type === 'BlockStatement' && - sexpr(node).path.original === 'liquid-with' && - sexpr(node).params.length === 3 && - sexpr(node).params[1].type === 'PathExpression' && - sexpr(node).params[1].original === 'as'; -}; - -// For compatibility with pre- and post-glimmer -function sexpr(node) { - if (node.sexpr) { - return node.sexpr; - } else { - return node; - } -} - -module.exports = TransformLiquidWithAsToHash; diff --git a/index.js b/index.js index faa77f61..0c982ba1 100644 --- a/index.js +++ b/index.js @@ -1,54 +1,6 @@ /*jshint node: true */ 'use strict'; -var checker = require('ember-cli-version-checker'); -var path = require('path'); -var mergeTrees = require('broccoli-merge-trees'); -var Funnel = require('broccoli-funnel'); - module.exports = { - name: 'liquid-fire', - - init: function() { - checker.assertAbove(this, '0.2.0'); - }, - - treeForVendor: function(tree){ - var velocityPath = path.dirname(require.resolve('velocity-animate')); - var velocityTree = new Funnel(this.treeGenerator(velocityPath), { - srcDir: '/', - destDir: 'velocity' - }); - - var matchMediaPath = path.dirname(require.resolve('match-media')); - var matchMediaTree = new Funnel(this.treeGenerator(matchMediaPath), { - srcDir: '/', - destDir: 'match-media' - }); - - return mergeTrees([tree, velocityTree, matchMediaTree]); - }, - - included: function(app){ - // see: https://github.com/ember-cli/ember-cli/issues/3718 - if (typeof app.import !== 'function' && app.app) { - app = app.app; - } - - if (!process.env.EMBER_CLI_FASTBOOT) { - app.import('vendor/velocity/velocity.js'); - app.import('vendor/match-media/matchMedia.js'); - } - - app.import('vendor/liquid-fire.css'); - }, - - setupPreprocessorRegistry: function(type, registry) { - var TransformLiquidWithAsToHash = require('./ext/plugins/transform-liquid-with-as-to-hash'); - - registry.add('htmlbars-ast-plugin', { - name: "transform-liquid-with-as-to-hash", - plugin: TransformLiquidWithAsToHash - }); - } + name: 'liquid-fire' };