<|start_filename|>packages/ember-stargate/src/components/portal-target.js<|end_filename|>
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { assert } from '@ember/debug';

export default class PortalTargetComponent extends Component {
  @service('-portal')
  portalService;

  get count() {
    return this.portalService.getPortalCount(this.args.name);
  }

  @action
  register(element) {
    assert('PortalTargets needs a name', this.args.name);
    const options = {
      multiple: this.args.multiple,
      onChange: this.args.onChange,
    };
    this.portalService.registerTarget(this.args.name, element, options);
  }

  @action
  unregister() {
    this.portalService.unregisterTarget(this.args.name);
  }
}


<|start_filename|>packages/ember-stargate/package.json<|end_filename|>
{
  "name": "ember-stargate",
  "version": "0.3.0",
  "description": "Modern lightweight portals for Ember",
  "keywords": [
    "ember-addon"
  ],
  "repository": "https://github.com/kaliber5/ember-stargate",
  "license": "MIT",
  "author": "<NAME> <<EMAIL>>",
  "directories": {
    "doc": "doc",
    "test": "tests"
  },
  "scripts": {
    "build": "rollup --config",
    "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
    "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
    "lint:hbs": "ember-template-lint .",
    "lint:hbs:fix": "ember-template-lint . --fix",
    "lint:js": "eslint . --cache",
    "lint:js:fix": "eslint . --fix",
    "start": "rollup --config --watch",
    "test": "echo 'Addon does not have tests, run tests in test-app'",
    "prepare": "yarn build",
    "prepublishOnly": "yarn build"
  },
  "dependencies": {
    "@ember/render-modifiers": "^2.0.0",
    "@embroider/addon-shim": "^0.47.0",
    "@glimmer/component": "^1.0.4",
    "ember-resources": "^3.2.1",
    "tracked-maps-and-sets": "^3.0.1"
  },
  "devDependencies": {
    "@babel/core": "7.15.8",
    "@babel/plugin-proposal-class-properties": "7.14.5",
    "@babel/plugin-proposal-decorators": "7.15.8",
    "@babel/plugin-syntax-decorators": "7.14.5",
    "@embroider/addon-dev": "0.47.0",
    "@rollup/plugin-babel": "5.3.0",
    "babel-eslint": "10.1.0",
    "ember-template-lint": "3.7.0",
    "eslint": "7.32.0",
    "eslint-config-prettier": "8.3.0",
    "eslint-plugin-ember": "10.5.5",
    "eslint-plugin-node": "11.1.0",
    "eslint-plugin-prettier": "4.0.0",
    "eslint-plugin-qunit": "7.0.0",
    "npm-run-all": "4.1.5",
    "rollup": "2.58.3"
  },
  "engines": {
    "node": "12.* || >= 14"
  },
  "publishConfig": {
    "registry": "https://registry.npmjs.org"
  },
  "ember": {
    "edition": "octane"
  },
  "ember-addon": {
    "version": 2,
    "type": "addon",
    "main": "addon-main.js",
    "app-js": {
      "./components/portal-target.js": "./dist/_app_/components/portal-target.js",
      "./components/portal.js": "./dist/_app_/components/portal.js",
      "./services/-portal.js": "./dist/_app_/services/-portal.js"
    }
  },
  "release-it": {
    "plugins": {
      "release-it-lerna-changelog": {
        "infile": "CHANGELOG.md",
        "launchEditor": false
      }
    },
    "git": {
      "tagName": "v${version}"
    },
    "github": {
      "release": true,
      "tokenRef": "GITHUB_AUTH"
    }
  },
  "resolutions": {
    "socket.io": "4.3.1"
  },
  "exports": {
    "./*": "./dist/*",
    "./addon-main.js": "./addon-main.js"
  }
}


<|start_filename|>packages/ember-stargate/src/components/portal.js<|end_filename|>
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { next } from '@ember/runloop';
import { LifecycleResource, useResource } from 'ember-resources';

class PortalTrackerResource extends LifecycleResource {
  @service('-portal')
  portalService;

  _target;

  get target() {
    return this.portalService.getTarget(this._target);
  }

  setup() {
    this._target = this.args.positional[0];
    next(() => this.portalService.registerPortal(this._target));
  }

  update() {
    const previousTarget = this._target;
    const newTarget = this.args.positional[0];
    next(() => {
      this.portalService.registerPortal(newTarget);
      this.portalService.unregisterPortal(previousTarget);
    });
    this._target = newTarget;
  }

  teardown() {
    this.portalService.unregisterPortal(this._target);
  }
}

export default class PortalComponent extends Component {
  tracker = useResource(this, PortalTrackerResource, () => [this.args.target]);

  get target() {
    return this.tracker.target;
  }

  get renderInPlace() {
    return (
      this.args.renderInPlace === true ||
      (!this.target && this.args.fallback === 'inplace')
    );
  }
}


<|start_filename|>package.json<|end_filename|>
{
  "workspaces": [
    "packages/*"
  ],
  "private": true,
  "repository": "https://github.com/kaliber5/ember-stargate",
  "license": "MIT",
  "author": "<NAME> <<EMAIL>>",
  "scripts": {
    "prepare": "yarn workspace ember-stargate run prepare",
    "start": "npm-run-all --parallel start:*",
    "start:addon": "yarn workspace ember-stargate run start",
    "start:test-app": "yarn workspace test-app run start",
    "lint": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*",
    "lint:addon": "yarn workspace ember-stargate run lint",
    "lint:test-app": "yarn workspace test-app run lint",
    "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:fix:*",
    "lint:fix:addon": "yarn workspace ember-stargate run lint:fix",
    "lint:fix:test-app": "yarn workspace test-app run lint:fix",
    "test": "npm-run-all --aggregate-output --continue-on-error --parallel test:*",
    "test:addon": "yarn workspace ember-stargate run test",
    "test:test-app": "yarn workspace test-app run test"
  },
  "devDependencies": {
    "npm-run-all": "4.1.5",
    "prettier": "2.4.1",
    "release-it": "14.11.6",
    "release-it-lerna-changelog": "3.1.0",
    "release-it-yarn-workspaces": "2.0.1"
  },
  "release-it": {
    "plugins": {
      "release-it-lerna-changelog": {
        "infile": "CHANGELOG.md",
        "launchEditor": false
      }
    },
    "git": {
      "tagName": "v${version}"
    },
    "github": {
      "release": true,
      "tokenRef": "GITHUB_AUTH"
    }
  },
  "resolutions": {
    "socket.io": "4.3.1"
  }
}
