Skip to content

Commit

Permalink
update import paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jamemackson authored and mixonic committed Nov 9, 2021
1 parent be64c88 commit 7892463
Show file tree
Hide file tree
Showing 24 changed files with 1,497 additions and 1,230 deletions.
19 changes: 19 additions & 0 deletions addon/components/_has-dom.ts
@@ -0,0 +1,19 @@
// check if window exists and actually is the global
export default typeof self === 'object' &&
self !== null &&
(self as Window['self']).Object === Object &&
typeof Window !== 'undefined' &&
self.constructor === Window &&
typeof document === 'object' &&
document !== null &&
self.document === document &&
typeof location === 'object' &&
location !== null &&
self.location === location &&
typeof history === 'object' &&
history !== null &&
self.history === history &&
typeof navigator === 'object' &&
navigator !== null &&
self.navigator === navigator &&
typeof navigator.userAgent === 'string';
78 changes: 78 additions & 0 deletions addon/components/_internals.ts
@@ -0,0 +1,78 @@
function intern(str: string): string {
let obj = {};
//@ts-ignore
obj[str] = 1;
for (let key in obj) {
if (key === str) {
return key;
}
}
return str;
}

const GUID_KEY = intern(`__ember${Date.now()}`);

// `enumerableSymbol` copied from https://github.com/emberjs/ember.js/blob/master/packages/@ember/-internals/utils/lib/symbol.ts
// for not exported code these legacy components are dependant on.

// Some legacy symbols still need to be enumerable for a variety of reasons.
// This code exists for that, and as a fallback in IE11. In general, prefer
// `symbol` below when creating a new symbol.
function enumerableSymbol(debugName: string): string {
let id = GUID_KEY + Math.floor(Math.random() * Date.now());
let symbol = intern(`__${debugName}${id}__`);
return symbol;
}

export const HAS_BLOCK = enumerableSymbol('HAS_BLOCK');

export function isSimpleClick(event: MouseEvent): boolean {
let modifier =
event.shiftKey || event.metaKey || event.altKey || event.ctrlKey;
let secondaryClick = event.which > 1; // IE9 may return undefined

return !modifier && !secondaryClick;
}

// export interface GlobalContext {
// imports: object;
// exports: object;
// lookup: object;
// }

// /* globals global, window, self */
// declare const mainContext: object | undefined;

// // from lodash to catch fake globals
// function checkGlobal(value: any | null | undefined): value is object {
// return value && value.Object === Object ? value : undefined;
// }

// // element ids can ruin global miss checks
// function checkElementIdShadowing(value: any | null | undefined) {
// return value && value.nodeType === undefined ? value : undefined;
// }

// // export real global
// export default checkGlobal(checkElementIdShadowing(typeof global === 'object' && global)) ||
// checkGlobal(typeof self === 'object' && self) ||
// checkGlobal(typeof window === 'object' && window) ||
// (typeof mainContext !== 'undefined' && mainContext) || // set before strict mode in Ember loader/wrapper
// new Function('return this')(); // eval outside of strict mode

// // legacy imports/exports/lookup stuff (should we keep this??)
// export const context = (function (
// global: object,
// Ember: Partial<GlobalContext> | undefined
// ): GlobalContext {
// return Ember === undefined
// ? { imports: global, exports: global, lookup: global }
// : {
// // import jQuery
// imports: Ember.imports || global,
// // export Ember
// exports: Ember.exports || global,
// // search for Namespaces
// lookup: Ember.lookup || global,
// };
// })(global, global.Ember);
1 change: 1 addition & 0 deletions addon/components/checkbox.hbs
@@ -0,0 +1 @@
{{yield}}
7 changes: 2 additions & 5 deletions addon/components/checkbox.js
@@ -1,12 +1,12 @@
//@ts-check
/* eslint-disable ember/no-component-lifecycle-hooks */
/* eslint-disable ember/require-tagless-components */
/* eslint-disable ember/no-classic-classes */
/* eslint-disable ember/no-classic-components */
import { set } from '@ember/-internals/metal';
import { set } from '@ember/object';
import { assert } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import EmberComponent from '@ember/component';
import layout from '../templates/empty';

/**
@module @ember/component
Expand All @@ -32,12 +32,9 @@ import layout from '../templates/empty';
properties will not be applied.
@class Checkbox
@extends Component
@public
*/
const Checkbox = EmberComponent.extend({
layout,

/**
By default, this component will add the `ember-checkbox` class to the component's element.
Expand Down
42 changes: 21 additions & 21 deletions addon/components/link-to.ts
@@ -1,6 +1,3 @@
/**
@module ember
*/
import { alias } from '@ember/object/computed';
import { computed } from '@ember/object';
import { getOwner } from '@ember/application';
Expand All @@ -10,13 +7,8 @@ import { getEngineParent } from '@ember/engine';
import EngineInstance from '@ember/engine/instance';
import { inject as injectService } from '@ember/service';
import { DEBUG } from '@glimmer/env';

// private
import RouterState from '@ember/-internals/routing/lib/system/router_state';
import { isSimpleClick } from '@ember/-internals/views';
import { flaggedInstrument } from '@ember/instrumentation';

import { HAS_BLOCK } from '../component-managers/curly';
import { isSimpleClick } from './_internals';
import { HAS_BLOCK } from './_internals';

/**
The `LinkTo` component renders a link to the supplied `routeName` passing an optionally
Expand Down Expand Up @@ -515,7 +507,7 @@ const LinkComponent = EmberComponent.extend({
let { eventName } = this;
this.on(eventName, this, this._invoke);
},

//@ts-ignore
_routing: injectService('-routing'),
_currentRoute: alias('_routing.currentRouteName'),
_currentRouterState: alias('_routing.currentState'),
Expand All @@ -526,6 +518,7 @@ const LinkComponent = EmberComponent.extend({
}),

_engineMountPoint: computed(function (this: any) {
//@ts-ignore
return (getOwner(this) as EngineInstance).mountPoint;
}),

Expand Down Expand Up @@ -658,7 +651,7 @@ const LinkComponent = EmberComponent.extend({
}
),

_isActive(routerState: RouterState): boolean {
_isActive(routerState: any /* RouterState */): boolean {
if (this.loading) {
return false;
}
Expand Down Expand Up @@ -785,16 +778,23 @@ const LinkComponent = EmberComponent.extend({
routeName,
};

flaggedInstrument(
'interaction.link-to',
// flaggedInstrument(
// 'interaction.link-to',
// payload,
// this._generateTransition(
// payload,
// routeName,
// models,
// queryParams,
// shouldReplace
// )
// );
this._generateTransition(
payload,
this._generateTransition(
payload,
routeName,
models,
queryParams,
shouldReplace
)
routeName,
models,
queryParams,
shouldReplace
);
return false;
},
Expand Down
14 changes: 7 additions & 7 deletions addon/components/text-field.ts
@@ -1,11 +1,13 @@
/* eslint-disable ember/no-mixins */
/* eslint-disable ember/no-classic-classes */
/**
@module @ember/component
*/
import { hasDOM } from '@ember/-internals/browser-environment';
import { computed } from '@ember/-internals/metal';
import { TextSupport } from '@ember/-internals/views';
import Component from '../component';
import layout from '../templates/empty';

import hasDOM from './_has-dom';
import { computed } from '@ember/object';
import Component from '@ember/component';
import { TextSupport } from '../mixins/text-support';

const inputTypes = hasDOM ? Object.create(null) : null;
function canSetTypeOfInput(type: string): boolean {
Expand Down Expand Up @@ -46,8 +48,6 @@ function canSetTypeOfInput(type: string): boolean {
@public
*/
const TextField = Component.extend(TextSupport, {
layout,

/**
By default, this component will add the `ember-text-field` class to the component's element.
Expand Down
150 changes: 150 additions & 0 deletions addon/mixins/_target_action_support.js
@@ -0,0 +1,150 @@
/* eslint-disable ember/no-get */
/* eslint-disable ember/no-new-mixins */
/**
@module ember
*/

import { context } from '../components/_internals';
import { get, computed } from '@ember/object';
import Mixin from '@ember/object/mixin';
import { assert } from '@ember/debug';
/**
`Ember.TargetActionSupport` is a mixin that can be included in a class
to add a `triggerAction` method with semantics similar to the Handlebars
`{{action}}` helper. In normal Ember usage, the `{{action}}` helper is
usually the best choice. This mixin is most often useful when you are
doing more complex event handling in Components.
@class TargetActionSupport
@namespace Ember
@extends Mixin
@private
*/
export default Mixin.create({
target: null,
action: null,
actionContext: null,

actionContextObject: computed('actionContext', function () {
let actionContext = get(this, 'actionContext');

if (typeof actionContext === 'string') {
let value = get(this, actionContext);
if (value === undefined) {
value = get(context.lookup, actionContext);
}
return value;
} else {
return actionContext;
}
}),

/**
Send an `action` with an `actionContext` to a `target`. The action, actionContext
and target will be retrieved from properties of the object. For example:
```javascript
import { alias } from '@ember/object/computed';
App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
target: alias('controller'),
action: 'save',
actionContext: alias('context'),
click() {
this.triggerAction(); // Sends the `save` action, along with the current context
// to the current controller
}
});
```
The `target`, `action`, and `actionContext` can be provided as properties of
an optional object argument to `triggerAction` as well.
```javascript
App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
click() {
this.triggerAction({
action: 'save',
target: this.get('controller'),
actionContext: this.get('context')
}); // Sends the `save` action, along with the current context
// to the current controller
}
});
```
The `actionContext` defaults to the object you are mixing `TargetActionSupport` into.
But `target` and `action` must be specified either as properties or with the argument
to `triggerAction`, or a combination:
```javascript
import { alias } from '@ember/object/computed';
App.SaveButtonView = Ember.View.extend(Ember.TargetActionSupport, {
target: alias('controller'),
click() {
this.triggerAction({
action: 'save'
}); // Sends the `save` action, along with a reference to `this`,
// to the current controller
}
});
```
@method triggerAction
@param opts {Object} (optional, with the optional keys action, target and/or actionContext)
@return {Boolean} true if the action was sent successfully and did not return false
@private
*/
triggerAction(opts = {}) {
let { action, target, actionContext } = opts;
action = action || get(this, 'action');
target = target || getTarget(this);

if (actionContext === undefined) {
actionContext = get(this, 'actionContextObject') || this;
}

if (target && action) {
let ret;

if (target.send) {
ret = target.send(...[action].concat(actionContext));
} else {
assert(
`The action '${action}' did not exist on ${target}`,
typeof target[action] === 'function'
);
ret = target[action](...[].concat(actionContext));
}

if (ret !== false) {
return true;
}
}

return false;
},
});

function getTarget(instance) {
let target = get(instance, 'target');
if (target) {
if (typeof target === 'string') {
let value = get(instance, target);
if (value === undefined) {
value = get(context.lookup, target);
}

return value;
} else {
return target;
}
}

if (instance._target) {
return instance._target;
}

return null;
}

0 comments on commit 7892463

Please sign in to comment.