Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
refactor: use import syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Feb 18, 2023
1 parent a0e700f commit 0d9e5f3
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 61 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module.exports = {
react: {
version: '17.0.2',
},
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs'],
Expand All @@ -32,6 +35,7 @@ module.exports = {
},
},
rules: {
'import/no-unresolved': [2, { ignore: ['\\$:/'] }],
// 'no-use-before-define': ['error', { ignoreTypeReferences: true, functions: false }],
'unicorn/prevent-abbreviations': [
'error',
Expand Down
4 changes: 3 additions & 1 deletion demo/tiddlers/Index.tid
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ type: text/vnd.tiddlywiki

{{$:/snippets/minilanguageswitcher}}

Some readme here.
Some readme here.

<$example-widget />
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"eslint-import-resolver-typescript": "3.5.3",
"eslint-plugin-autofix": "1.1.0",
"eslint-plugin-html": "7.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-import": "npm:eslint-plugin-i@2.26.0-2",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "4.2.1",
Expand Down
104 changes: 52 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/index.js.meta
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
creator: LinOnetwo
title: $:/plugins/linonetwo/tw-react/widget.js
type: application/javascript
module-type: library
module-type: widget
hide-body: yes
11 changes: 5 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Widget as IWidget, IChangedTiddlers } from 'tiddlywiki';

const Widget = (require('$:/core/modules/widgets/widget.js') as { widget: typeof IWidget }).widget;
import type { IChangedTiddlers } from 'tiddlywiki';
import { widget as Widget } from '$:/core/modules/widgets/widget.js';

class ExampleWidget extends Widget {
// constructor(parseTreeNode: IParseTreeNode, options?: unknown) {
Expand All @@ -14,18 +13,18 @@ class ExampleWidget extends Widget {
/**
* Lifecycle method: Render this widget into the DOM
*/
render(parent: Node, _nextSibling: Node): void {
render(parent: Element, _nextSibling: Element | null): void {
this.parentDomNode = parent;
this.computeAttributes();
this.execute();

const containerElement = document.createElement('div');
containerElement.textContent = 'Hello world!';
this.domNodes.push(containerElement);
// eslint-disable-next-line unicorn/prefer-dom-node-append
parent.appendChild(containerElement);
}
}

/* eslint-disable @typescript-eslint/no-unsafe-member-access */
exports.widget = ExampleWidget;
exports.ExampleWidget = ExampleWidget;
exports['example-widget'] = ExampleWidget;

0 comments on commit 0d9e5f3

Please sign in to comment.