Skip to content

Commit

Permalink
Merge pull request #4 from kitschpatrol/tweakpane-v4
Browse files Browse the repository at this point in the history
Update for Tweakpane v4.
  • Loading branch information
kgolinski committed Feb 11, 2024
2 parents 394d154 + 3cf40bd commit 1b52b32
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 97 deletions.
7 changes: 6 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
node_modules
/dist/**/*
/docs/**/*
/ts*/**/*
/types/**/*
.eslintrc.cjs
rollup.config.js
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ const params = {
prop: 'Put your\nmultiline\ntext here!'
};

pane.addInput(params, 'prop', {
pane.addBinding(params, 'prop', {
view: 'textarea',
lineCount: 6,
rows: 6,
placeholder: 'Type here...'
}).on('change', (ev) => {
console.log(ev.value);
Expand Down
48 changes: 26 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
{
"name": "@pangenerator/tweakpane-textarea-plugin",
"version": "1.0.4",
"version": "2.0.0",
"description": "Textarea plugin for Tweakpane",
"main": "dist/tweakpane-textarea-plugin.js",
"type": "module",
"types": "dist/types/index.d.ts",
"author": "panGenerator <contact@pangenerator.com>",
"license": "MIT",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "git+https://github.com/panGenerator/tweakpane-textarea-plugin.git"
},
"keywords": [
"tweakpane",
"tweakpane-plugin",
"plugin",
"textarea",
"multiline"
],
"repository": {
"type": "git",
"url": "git+https://github.com/panGenerator/tweakpane-textarea-plugin.git"
},
"files": [
"dist"
],
"scripts": {
"prepare": "run-s clean build",
"prepublishOnly": "npm test",
"start": "npm run watch",
"test": "eslint --ext .ts \"src/**/*.ts\"",
"assets": "run-s clean build assets:version assets:zip",
"assets:version": "node scripts/assets-append-version.js",
"assets:zip": "zip -x \"*types*\" -j -r $(cat package.json | npx json name)-$(cat package.json | npx json version).zip dist",
"clean": "rimraf dist *.tgz *.zip",
"assets:zip": "zip -x '*types*' -j -r $(node scripts/dist-name.js)-$(cat package.json | npx json version).zip dist",
"build": "run-p build:*",
"build:dev": "rollup --config rollup.config.js",
"build:dts": "tsc --project src/tsconfig-dts.json",
"build:prod": "rollup --config rollup.config.js --environment BUILD:production",
"clean": "rimraf dist *.tgz *.zip",
"format": "run-p format:*",
"format:scss": "prettier --parser scss --write \"src/sass/**/*.scss\"",
"format:ts": "eslint --ext .ts --fix \"src/**/*.ts\"",
"postversion": "git push --tags",
"prepare": "run-s clean build",
"prepublishOnly": "npm test",
"server": "http-server -c-1 -o /test/browser.html",
"start": "run-p watch server",
"test": "eslint --ext .ts \"src/**/*.ts\"",
"watch": "run-p watch:*",
"watch:sass": "onchange --initial --kill \"src/sass/**/*.scss\" -- npm run build:dev",
"watch:ts": "onchange --initial --kill \"src/**/*.ts\" -- rollup --config rollup.config.js",
"postversion": "git push --tags"
"watch:ts": "onchange --initial --kill \"src/**/*.ts\" -- rollup --config rollup.config.js"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-replace": "^2.4.1",
"@rollup/plugin-typescript": "^8.2.0",
"@tweakpane/core": "^1.0.6",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"@tweakpane/core": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"autoprefixer": "^10.2.4",
"eslint": "^7.20.0",
"eslint": "^8.46.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-simple-import-sort": "^7.0.0",
"http-server": "^14.1.1",
"npm-run-all": "^4.1.5",
"onchange": "^7.1.0",
"postcss": "^8.2.6",
Expand All @@ -63,9 +66,10 @@
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.49.9",
"typescript": "^4.1.5"
"tweakpane": "^4.0.0",
"typescript": "^4.9.5"
},
"peerDependencies": {
"tweakpane": "^3.0.5"
"tweakpane": "^4.0.0"
}
}
26 changes: 5 additions & 21 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-env node */

import Alias from '@rollup/plugin-alias';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import Replace from '@rollup/plugin-replace';
Expand All @@ -24,12 +26,11 @@ async function compileCss() {

function getPlugins(css, shouldMinify) {
const plugins = [
// Use ES6 source files to avoid CommonJS transpiling
Alias({
entries: [
{
find: '@tweakpane/core',
replacement: './node_modules/@tweakpane/core/dist/es6/index.js',
replacement: './node_modules/@tweakpane/core/dist/index.js',
},
],
}),
Expand All @@ -55,23 +56,7 @@ function getPlugins(css, shouldMinify) {
}

function getDistName(packageName) {
return packageName.split('/')[1];
// .reduce((comps, comp) => (comp !== '' ? [...comps, comp] : comps), [])
// .join('-');
}

function getUmdName(packageName) {
// `@tweakpane/plugin-foobar` -> `TweakpaneFoobarPlugin`
// `tweakpane-plugin-foobar` -> `TweakpaneFoobarPlugin`
return (
packageName
.split('/')[1]
.split(/[@/-]/)
.map((comp) =>
comp !== 'plugin' ? comp.charAt(0).toUpperCase() + comp.slice(1) : '',
)
.join('') + 'Plugin'
);
return packageName.replace(/^@[^\/]+\//, '')
}

export default async () => {
Expand All @@ -85,11 +70,10 @@ export default async () => {
external: ['tweakpane'],
output: {
file: `dist/${distName}${postfix}.js`,
format: 'umd',
format: 'esm',
globals: {
tweakpane: 'Tweakpane',
},
name: getUmdName(Package.name),
},
plugins: getPlugins(css, production),

Expand Down
14 changes: 9 additions & 5 deletions scripts/assets-append-version.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
'use strict';
/* eslint-disable no-console */
/* eslint-env node */

const Fs = require('fs');
const Glob = require('glob');
const Path = require('path');
const Package = require('../package');
import Fs from 'fs';
import Glob from 'glob';
import Path from 'path';

const Package = JSON.parse(
Fs.readFileSync(new URL('../package.json', import.meta.url)),
);

const PATTERN = 'dist/*';

Expand Down
16 changes: 16 additions & 0 deletions scripts/dist-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable no-console */
/* eslint-env node */

import Fs from 'fs';

const Package = JSON.parse(
Fs.readFileSync(new URL('../package.json', import.meta.url)),
);

// `@tweakpane/plugin-foobar` -> `tweakpane-plugin-foobar`
// `tweakpane-plugin-foobar` -> `tweakpane-plugin-foobar`
const name = Package.name
.split(/[@/-]/)
.reduce((comps, comp) => (comp !== '' ? [...comps, comp] : comps), [])
.join('-');
console.log(name);
12 changes: 6 additions & 6 deletions src/controller.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Controller, forceCast, Value, ViewProps} from '@tweakpane/core';

import {TextAreaView} from './view';
import {TextAreaView} from './view.js';
/**
* @hidden
*/
export interface Config {
value: Value<string>;
viewProps: ViewProps;
lineCount: number;
rows: number;
placeholder: string;
}

Expand All @@ -18,22 +18,22 @@ export class TextAreaController implements Controller<TextAreaView> {
public readonly value: Value<string>;
public readonly view: TextAreaView;
public readonly viewProps: ViewProps;
public readonly lineCount: number;
public readonly rows: number;
public readonly placeholder: string;

constructor(doc: Document, config: Config) {
this.onInputChange_ = this.onInputChange_.bind(this);
this.value = config.value;
this.viewProps = config.viewProps;
this.lineCount = config.lineCount;
this.rows = config.rows;
this.placeholder = config.placeholder;

// console.log( this.lineCount )
// console.log( this.rows )

this.view = new TextAreaView(doc, {
value: this.value,
viewProps: this.viewProps,
lineCount: this.lineCount,
rows: this.rows,
placeholder: this.placeholder,
});
this.view.inputElement.addEventListener('keyup', this.onInputChange_);
Expand Down
10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import {TweakpaneTextareaPlugin} from './plugin';
import type {TpPlugin} from 'tweakpane';

import {TweakpaneTextareaPlugin} from './plugin.js';

export const id = 'textarea';

export const css = '__css__';

// Export your plugin(s) as constant `plugins`
export const plugins = [TweakpaneTextareaPlugin];
export const plugins: TpPlugin[] = [TweakpaneTextareaPlugin];
33 changes: 12 additions & 21 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
BaseInputParams,
BindingTarget,
createPlugin,
InputBindingPlugin,
ParamsParsers,
parseParams,
parseRecord,
} from '@tweakpane/core';

import {TextAreaController} from './controller';
import {TextAreaController} from './controller.js';

export interface PluginInputParams extends BaseInputParams {
export interface TextareaPluginInputParams extends BaseInputParams {
view: 'textarea';
lineCount?: number;
rows?: number;
placeholder?: string;
}

Expand All @@ -24,19 +24,11 @@ export interface PluginInputParams extends BaseInputParams {
export const TweakpaneTextareaPlugin: InputBindingPlugin<
string,
string,
PluginInputParams
> = {
TextareaPluginInputParams
> = createPlugin({
id: 'input-template',

// type: The plugin type.
// - 'input': Input binding
// - 'monitor': Monitor binding
type: 'input',

// This plugin template injects a compiled CSS by @rollup/plugin-replace
// See rollup.config.js for details
css: '__css__',

accept(exValue: unknown, params: Record<string, unknown>) {
if (typeof exValue !== 'string') {
// Return null to deny the user input
Expand All @@ -45,13 +37,12 @@ export const TweakpaneTextareaPlugin: InputBindingPlugin<

// Parse parameters object
// console.log(params)
const p = ParamsParsers;
const result = parseParams<PluginInputParams>(params, {
const result = parseRecord<TextareaPluginInputParams>(params, (p) => ({
// `view` option may be useful to provide a custom control for primitive values
view: p.required.constant('textarea'),
lineCount: p.optional.number,
rows: p.optional.number,
placeholder: p.optional.string,
});
}));
if (!result) {
return null;
}
Expand Down Expand Up @@ -84,9 +75,9 @@ export const TweakpaneTextareaPlugin: InputBindingPlugin<
// Create a controller for the plugin
return new TextAreaController(args.document, {
value: args.value,
lineCount: args.params.lineCount ?? 3,
rows: args.params.rows ?? 3,
placeholder: args.params.placeholder ?? 'Enter text here',
viewProps: args.viewProps,
});
},
};
});
17 changes: 8 additions & 9 deletions src/sass/plugin.scss
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
// Import core styles
@import '../../node_modules/@tweakpane/core/lib/sass/plugin';

@use '../../node_modules/@tweakpane/core/lib/sass/tp';

// Additional style for the plugin
.#{$prefix}-txtrv {
.#{tp.$prefix}-txtrv {
// Extend a general input view style
@extend %input;
@extend %tp-input;
display: block;
height: auto; //calc(var(--bld-us) * 4)
height: auto; //calc(#{tp.cssVar('container-unit-size')} * 4)
//margin-bottom: -5px;
padding-bottom: 0;
overflow: hidden;
position: relative;

&.#{$prefix}-v-disabled {
&.#{tp.$prefix}-v-disabled {
opacity: 0.5;
}

.tp-txtrv_i {
font-family: var(--font-family);
background-color: var(--in-bg);
border-radius: var(--elm-br);
background-color: tp.cssVar('input-bg');
border-radius: tp.cssVar('blade-border-radius');
box-sizing: border-box;
color: var(--in-fg);
color: tp.cssVar('input-fg');
font-size: 11px;
padding: 4px;
line-height: 16px;
Expand Down
2 changes: 1 addition & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"lib": ["DOM", "ES2015"],
"moduleResolution": "Node",
"moduleResolution": "Node16",
"strict": true,
"target": "ES6"
}
Expand Down

0 comments on commit 1b52b32

Please sign in to comment.