Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup template-imports in core pkg #235

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/node_modules/
/packages/*/bower_components/
/packages/*/node_modules/
/packages/*/declarations/
/site/node_modules/
/test-app/node_modules/
/site/lib/docfy-theme/node_modules/
Expand Down
6 changes: 1 addition & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const { join } = require('path');

module.exports = {
root: true,
parserOptions: {
project: join(__dirname, './tsconfig.eslint.json')
},
plugins: [],
extends: ['@underline/eslint-config-ember-typescript'],
rules: {
Expand All @@ -28,6 +23,7 @@ module.exports = {
'.template-lintrc.js',
'testem.js',
'config/**/*.js',
'packages/*/babel.config.js',
'packages/*/addon-main.js',
'packages/*/.ember-cli.js',
'packages/*/ember-cli-build.js',
Expand Down
15 changes: 14 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
module.exports = require('@underline/eslint-config/.prettierrc.js');
const defaults = require('@underline/eslint-config/.prettierrc.js');
module.exports = {
...defaults,
plugins: ['prettier-plugin-ember-template-tag'],
overrides: [
...defaults.overrides,
{
files: '*.{js,ts,gjs,gts}',
options: {
templateSingleQuote: false
}
}
]
};
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"build": "yarn workspaces run build",
"lint:hbs": "ember-template-lint .",
"lint:js": "eslint . --ext .js,.ts",
"lint:js": "eslint . --ext .js,.ts,.gts,.gjs",
"start": "yarn workspace site start",
"test": "yarn workspace test-app run test",
"try:one": "yarn workspace test-app run try:one"
Expand All @@ -23,12 +23,21 @@
"@embroider/test-setup": "^3.0.1"
},
"devDependencies": {
"@underline/eslint-config-ember-typescript": "^0.13.0",
"@underline/eslint-config-node": "^0.13.0",
"@glint/core": "1.0.2",
"@glint/environment-ember-loose": "1.0.2",
"@glint/environment-ember-template-imports": "1.0.2",
"@underline/eslint-config-ember-typescript": "^0.14.3",
"@underline/eslint-config-node": "^0.14.0",
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^5.11.1",
"eslint": "^8.46.0",
"eslint-plugin-prettier": "^5.0.0",
"lerna": "^4.0.0",
"prettier": "^3.0.0",
"prettier-plugin-ember-template-tag": "^1.0.0",
"typescript": "^5.1.6"
},
"engines": {
"node": ">= 10.*"
}
}
16 changes: 16 additions & 0 deletions packages/core/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
presets: [['@babel/preset-typescript', { onlyRemoveTypeImports: true }]],
plugins: [
'@embroider/addon-dev/template-colocation-plugin',
[
'babel-plugin-ember-template-compilation',
{
targetFormat: 'hbs',
compilerPath: 'ember-source/dist/ember-template-compiler'
}
],
['@babel/plugin-proposal-decorators', { legacy: true }],
'@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-class-static-block'
]
};
8 changes: 0 additions & 8 deletions packages/core/babel.config.json

This file was deleted.

3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@
"@babel/core": "7.22.9",
"@babel/plugin-proposal-class-properties": "7.18.6",
"@babel/plugin-proposal-decorators": "7.22.7",
"@babel/plugin-transform-class-static-block": "^7.22.5",
"@babel/preset-typescript": "7.22.5",
"@embroider/addon-dev": "3.2.0",
"@glint/core": "1.0.2",
"@glint/environment-ember-loose": "1.0.2",
"@glint/environment-ember-template-imports": "1.0.2",
"@glint/template": "1.0.2",
"@rollup/plugin-babel": "6.0.3",
"@tsconfig/ember": "^3.0.0",
"babel-plugin-ember-template-compilation": "^2.1.1",
"concurrently": "^8.2.0",
"ember-source": "^5.1.2",
"rollup": "^3.27.0",
Expand Down
6 changes: 5 additions & 1 deletion packages/core/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const addon = new Addon({
});

// Add extensions here, such as ts, gjs, etc that you may import
const extensions = ['.js', '.ts'];
const extensions = ['.js', '.ts', '.gjs', '.gts'];

export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
Expand Down Expand Up @@ -38,6 +38,8 @@ export default {
// package names.
addon.dependencies(),

addon.gjs(),

// This babel config should *not* apply presets or compile away ES modules.
// It exists only to provide development niceties for you, like automatic
// template colocation.
Expand All @@ -47,9 +49,11 @@ export default {
babelHelpers: 'bundled',
}),


// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),


// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(['**/*.css']),
Expand Down
90 changes: 90 additions & 0 deletions packages/core/src/components/close-button.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import 'focus-visible/dist/focus-visible.js';
import { on } from '@ember/modifier';
import useFrontileClass from '../helpers/use-frontile-class.ts';
import VisuallyHidden from './visually-hidden.ts';

export interface CloseButtonArgs {
/**
* The title of the close button
*
* @defaultValue 'Close'
*/
title?: string;

/**
* The icon size
*
* @defaultValue 'lg'
*/
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';

/**
* The function to call when button is clicked
*/
onClick?: (event: Event) => void;

/**
* Additional class for close button element
*/
class?: string;
}

export interface CloseButtonSignature {
Args: CloseButtonArgs;
Blocks: {
default: [string | null];
};
Element: HTMLButtonElement;
}

export default class CloseButton extends Component<CloseButtonSignature> {
@action handleClick(event: Event): void {
if (typeof this.args.onClick === 'function') {
this.args.onClick(event);
}
}

<template>
<button
type="button"
class={{useFrontileClass
"close-button"
(if @size @size "md")
class=@class
}}
...attributes
{{on "click" this.handleClick}}
>
{{#let
(useFrontileClass "close-button" (if @size @size "md") part="icon")
as |iconClassName|
}}
{{#if (has-block)}}
{{yield iconClassName}}
{{else}}
<svg
class={{iconClassName}}
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
></path>
</svg>
{{/if}}
{{/let}}

<VisuallyHidden>
{{if @title @title "Close"}}
</VisuallyHidden>
</button>
</template>
}
36 changes: 0 additions & 36 deletions packages/core/src/components/close-button.hbs

This file was deleted.

45 changes: 0 additions & 45 deletions packages/core/src/components/close-button.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/components/visually-hidden.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="sr-only" ...attributes>
{{yield}}
</div>
</div>
2 changes: 1 addition & 1 deletion packages/core/src/template-registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type VisuallyHidden from './components/visually-hidden.ts';
import type CloseButton from './components/close-button.ts';
import type CloseButton from './components/close-button';
import type Collapsible from './components/collapsible';

export default interface Registry {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "@tsconfig/ember/tsconfig.json",
"include": ["src/**/*", "unpublished-development-types/**/*"],
"glint": {
"environment": "ember-loose"
"environment": ["ember-loose", "ember-template-imports"]
},
"compilerOptions": {
"allowImportingTsExtensions": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/unpublished-development-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// These will *not* be published as part of your addon, so be careful that your published code does not rely on them!

import 'ember-source/types';
import '@glint/environment-ember-loose';
import '@glint/environment-ember-template-imports';
import type RenderModifiersRegistry from '@ember/render-modifiers/template-registry';
import type CoreRegistry from '../src/template-registry.ts';

Expand Down
2 changes: 1 addition & 1 deletion test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"ember-try": "^2.0.0",
"loader.js": "^4.7.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.6.0",
"prettier": "^3.0.0",
"qunit": "^2.19.4",
"qunit-dom": "^2.0.0",
"sinon": "^15.2.0",
Expand Down
5 changes: 0 additions & 5 deletions tsconfig.eslint.json

This file was deleted.

Loading
Loading