Skip to content

Commit

Permalink
Glint Support
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeAstapov committed Aug 9, 2023
1 parent b403649 commit 9683b70
Show file tree
Hide file tree
Showing 21 changed files with 775 additions and 1,569 deletions.
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,42 @@ You can also provide specific events that you want to bind to with the `event` o
<div {{click-outside this.onClickOutside events=(array 'click' 'mouseup')}}></div>
```

## Usage with Glint

`ember-click-outside-modifier` is a glint enabled addon. Add this to your
`types/global.d.ts` file:

```ts
import '@glint/environment-ember-loose';

import type EmberClickOutsideRegistry from 'ember-click-outside-modifier/template-registry';

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry extends EmberClickOutsideRegistry, /* other addon registries */ {
// local entries
}
}
```

For the entire guide, please refer to [Using
Addons](https://typed-ember.gitbook.io/glint/environments/ember/using-addons#using-glint-enabled-addons)
section on the glint handbook.

Types are made available through package.json `exports` field.

## Usage with <template> tag

For usage in `gts` or `gjs` files, modifier are exported from the index:

```gts
import { clickOutside } from 'ember-truth-helpers';
<template>
<div {{clickOutside this.handleClickOutside}}>
Lorem ipsum.
</div>
</template>
```

Contributing
------------------------------------------------------------------------------
Expand Down
19 changes: 13 additions & 6 deletions ember-click-outside-modifier/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

module.exports = {
root: true,
parser: '@babel/eslint-parser',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
requireConfigFile: false,
babelOptions: {
plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
root: __dirname,
},
},
plugins: ['ember'],
Expand All @@ -25,6 +21,17 @@ module.exports = {
},
rules: {},
overrides: [
// ts files
{
files: ['**/*.ts'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
// Add any custom rules here
},
},
// node files
{
files: [
Expand Down
29 changes: 22 additions & 7 deletions ember-click-outside-modifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@
},
"license": "MIT",
"author": "Aleksandr Kanunnikov <[email protected]>",
"exports": {
".": "./dist/index.js",
"./*": "./dist/*",
"./addon-main.js": "./addon-main.js"
},
"files": [
"addon-main.js",
"dist"
"dist",
"types"
],
"scripts": {
"build": "rollup --config",
Expand All @@ -39,13 +35,17 @@
"@babel/plugin-proposal-decorators": "^7.17.8",
"@embroider/addon-dev": "^1.5.0",
"@rollup/plugin-babel": "^5.3.1",
"@tsconfig/ember": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-ember": "^10.6.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.6.2",
"rollup": "^2.70.2"
"rollup": "^2.70.2",
"typescript": "^5.1.6"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand All @@ -60,5 +60,20 @@
"app-js": {
"./modifiers/click-outside.js": "./dist/_app_/modifiers/click-outside.js"
}
},
"exports": {
".": "./dist/index.js",
"./*": {
"types": "./types/*.d.ts",
"default": "./dist/*.js"
},
"./addon-main.js": "./addon-main.js"
},
"typesVersions": {
"*": {
"*": [
"types/*"
]
}
}
}
2 changes: 1 addition & 1 deletion ember-click-outside-modifier/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints(['modifiers/**/*.js']),
addon.publicEntrypoints(['index.js', 'modifiers/**/*.js']),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
Expand Down
1 change: 1 addition & 0 deletions ember-click-outside-modifier/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as clickOutside } from './modifiers/click-outside';
10 changes: 10 additions & 0 deletions ember-click-outside-modifier/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"include": [
"src/**/*",
"types/**/*"
],
"glint": {
"environment": "ember-loose"
}
}
18 changes: 18 additions & 0 deletions ember-click-outside-modifier/types/modifiers/click-outside.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Modifier from 'ember-modifier';

export interface ClickOutsideSignature {
Element?: HTMLElement;
Args: {
Positional: [handlerValue: (event: Event) => unknown, useCapture?: boolean];
Named:
| never
| {
events?: string[];
}
| {
event?: string;
};
};
}

export default class ClickOutsideModifier extends Modifier<ClickOutsideSignature> {}
5 changes: 5 additions & 0 deletions ember-click-outside-modifier/types/template-registry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type ClickOutsideModifier from './modifiers/click-outside';

export default interface EmberClickOutsideRegistry {
'click-outside': typeof ClickOutsideModifier;
}
19 changes: 13 additions & 6 deletions test-app/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

module.exports = {
root: true,
parser: '@babel/eslint-parser',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
requireConfigFile: false,
babelOptions: {
plugins: [['@babel/plugin-proposal-decorators', { legacy: true }]],
root: __dirname,
},
},
plugins: ['ember'],
Expand All @@ -25,6 +21,17 @@ module.exports = {
},
rules: {},
overrides: [
// ts files
{
files: ['**/*.ts'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
// Add any custom rules here
},
},
// node files
{
files: [
Expand Down
File renamed without changes.
Empty file removed test-app/app/components/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions test-app/app/components/glint-typecheck.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<button type="button" {{click-outside this.noop}}>Click me!</button>
<button type="button" {{click-outside this.noop true}}>Click me!</button>
<button type="button" {{click-outside this.noop false}}>Click me!</button>
<button type="button" {{click-outside this.noop event="touchstart"}}>Click me!</button>
<button type="button" {{click-outside this.noop events=(array "touchstart" "touchend")}}>Click me!</button>
7 changes: 7 additions & 0 deletions test-app/app/components/glint-typecheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Component from '@glimmer/component';

export default class extends Component {
noop() {
// do nothing
}
}
14 changes: 14 additions & 0 deletions test-app/app/config/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Type declarations for
* import config from 'test-app/config/environment'
*/
declare const config: {
environment: string;
modulePrefix: string;
podModulePrefix: string;
locationType: 'history' | 'hash' | 'none' | 'auto';
rootURL: string;
APP: Record<string, unknown>;
};

export default config;
2 changes: 0 additions & 2 deletions test-app/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{{page-title "TestApp"}}

<h2 id="title">Welcome to Ember</h2>

{{outlet}}
14 changes: 13 additions & 1 deletion test-app/config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ module.exports = async function () {
name: 'ember-lts-3.20',
npm: {
devDependencies: {
'ember-source': '~3.20.6',
'@ember/test-helpers': '^2.6.0',
'ember-modifier': '^3.0.0',
'ember-qunit': '^5.1.5',
'ember-resolver': '^8.0.3',
'ember-source': '~3.20.6',
},
},
},
{
name: 'ember-lts-3.24',
npm: {
devDependencies: {
'@ember/test-helpers': '^2.6.0',
'ember-qunit': '^5.1.5',
'ember-resolver': '^8.0.3',
'ember-source': '~3.24.6',
},
},
Expand All @@ -28,6 +34,9 @@ module.exports = async function () {
name: 'ember-lts-3.28',
npm: {
devDependencies: {
'@ember/test-helpers': '^2.6.0',
'ember-qunit': '^5.1.5',
'ember-resolver': '^8.0.3',
'ember-source': '~3.28.9',
},
},
Expand All @@ -36,6 +45,9 @@ module.exports = async function () {
name: 'ember-lts-4.4',
npm: {
devDependencies: {
'@ember/test-helpers': '^2.6.0',
'ember-qunit': '^5.1.5',
'ember-resolver': '^8.0.3',
'ember-source': '~4.4.0',
},
},
Expand Down
43 changes: 40 additions & 3 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"lint:hbs:fix": "ember-template-lint . --fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:glint": "glint",
"start": "ember serve",
"test": "npm-run-all lint test:*",
"test:ember": "ember test",
Expand All @@ -33,10 +34,45 @@
"@babel/eslint-parser": "^7.17.0",
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^2.6.0",
"@ember/test-helpers": "^3.2.0",
"@embroider/test-setup": "^1.6.0",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@glint/core": "^1.0.2",
"@glint/environment-ember-loose": "^1.0.2",
"@glint/template": "^1.0.2",
"@tsconfig/ember": "^3.0.0",
"@types/ember": "^4.0.4",
"@types/eslint": "^8.44.1",
"@types/ember-data": "^4.4.11",
"@types/ember-data__adapter": "^4.0.2",
"@types/ember-data__model": "^4.0.1",
"@types/ember-data__serializer": "^4.0.2",
"@types/ember-data__store": "^4.0.3",
"@types/ember__application": "^4.0.6",
"@types/ember__array": "^4.0.4",
"@types/ember__component": "^4.0.14",
"@types/ember__controller": "^4.0.5",
"@types/ember__debug": "^4.0.4",
"@types/ember__destroyable": "^4.0.2",
"@types/ember__engine": "^4.0.5",
"@types/ember__error": "^4.0.3",
"@types/ember__helper": "^4.0.2",
"@types/ember__modifier": "^4.0.5",
"@types/ember__object": "^4.0.6",
"@types/ember__owner": "^4.0.4",
"@types/ember__polyfills": "^4.0.2",
"@types/ember__routing": "^4.0.13",
"@types/ember__runloop": "^4.0.3",
"@types/ember__service": "^4.0.3",
"@types/ember__string": "^3.0.11",
"@types/ember__template": "^4.0.2",
"@types/ember__test": "^4.0.2",
"@types/ember__utils": "^4.0.3",
"@types/qunit": "^2.19.6",
"@types/rsvp": "^4.0.4",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"broccoli-asset-rev": "^3.0.0",
"ember-auto-import": "^2.4.1",
"ember-cli": "~4.3.0",
Expand All @@ -50,8 +86,8 @@
"ember-disable-prototype-extensions": "^1.1.3",
"ember-load-initializers": "^2.1.2",
"ember-page-title": "^7.0.0",
"ember-qunit": "^5.1.5",
"ember-resolver": "^8.0.3",
"ember-qunit": "^7.0.0",
"ember-resolver": "^11.0.0",
"ember-source": "~4.3.0",
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^4.4.2",
Expand All @@ -67,6 +103,7 @@
"prettier": "^2.6.2",
"qunit": "^2.18.2",
"qunit-dom": "^2.0.0",
"typescript": "^5.1.6",
"webpack": "^5.72.0"
},
"engines": {
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions test-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"compilerOptions": {
// The combination of `baseUrl` with `paths` allows Ember's classic package
// layout, which is not resolvable with the Node resolution algorithm, to
// work with TypeScript.
"baseUrl": ".",
"paths": {
"test-app/tests/*": ["tests/*"],
"test-app/*": ["app/*"],
"*": ["types/*"]
}
},
"glint": {
"environment": "ember-loose"
}
}
Loading

0 comments on commit 9683b70

Please sign in to comment.