pixi-text-input icon indicating copy to clipboard operation
pixi-text-input copied to clipboard

[Suggestion] Export the package as module

Open yordan-kanchelov opened this issue 5 years ago • 34 comments

It would be really easy and convenient if this is exported as npm package and to be able to import it in a project via the esnext import statement for example

yordan-kanchelov avatar May 27 '19 20:05 yordan-kanchelov

The newest version is compatible with nodejs. By that I mean it's possible to import it as a module const TextInput = require('./PIXI.TextInput') Is that sufficient for it to work with esnext imports?

Mwni avatar May 31 '19 01:05 Mwni

Can u add more documentation about how to download and and use this please? I have no idea how to use this, struggling more than an hour now :/

(I'm using React)

buryo avatar May 31 '19 02:05 buryo

It's simply meant to be included in the html page. Grab the PIXI.TextInput.min.js from the dist folder and include it via a script a tag. But I'm afraid you can't simply do that with react, it all gets compiled down and the html ist being generated for you, right?

Mwni avatar May 31 '19 02:05 Mwni

That's true, I already tried that =)

buryo avatar May 31 '19 02:05 buryo

How are you including pixi.js?

Mwni avatar May 31 '19 02:05 Mwni

Downloaded with NPM and including like: import * as PIXI from 'pixi.js';

buryo avatar May 31 '19 09:05 buryo

@Mwni My thought was to include it as npm package so you could be able to let's say

npm install pixi-text-input

and then include it like that

import { TextInput } from "pixi-text-input" ( or something like that )

Here is an example for a published project like that - https://github.com/jkanchelov/pixi-console and here is an example project where it could be easily consumed https://github.com/jkanchelov/flappy-bird-pixijs

yordan-kanchelov avatar May 31 '19 11:05 yordan-kanchelov

@Mwni if you want invite to pixijs slack, send an email to [email protected] , i'll send an invite.

There are people who can help with those kind of things.

ivanpopelyshev avatar May 31 '19 14:05 ivanpopelyshev

Okay first attempt of a npm package is online. npm install pixi-text-input then const TextInput = require('pixi-text-input') or import 'pixi-text-input' as TextInput (not sure though)

Does it work? Can't test it inside node due to node not being a browser and don't have the browserify environment either.

Mwni avatar Jun 01 '19 03:06 Mwni

I think the npm package is okay but now we need to know how to use it I'm getting the following error:

I did:

  • npm install pixi-text-input
  • import TextInput from 'pixi-text-input';

Screenshot_3

Getting the error: Attempted import error: 'TextInput' is not exported from 'pixi.js' (imported as 'PIXI').

buryo avatar Jun 01 '19 08:06 buryo

Lets meet in the middle. Its obviously that plugin creators who dont use React/Webpack and that stuff cnat get you everything. If we put something in npm and import kinda works - that's enough.

Import the module after you import pixi.js. Do not import classes.

Use PIXI.TextInput.

ivanpopelyshev avatar Jun 01 '19 09:06 ivanpopelyshev

I already tried almost everything Ivan, I think it doesn't inherit PIXI

buryo avatar Jun 01 '19 09:06 buryo

@buryo can you try and then confirm if let's say this package works for you https://github.com/jkanchelov/pixi-fps

yordan-kanchelov avatar Jun 01 '19 11:06 yordan-kanchelov

@jkanchelov Works like a charm! =) https://i.imgur.com/e3y7M25.png

buryo avatar Jun 01 '19 12:06 buryo

Later today or tomorrow I will push the things you need to make it work and will go with pull request and if @Mwni approves it and publish the package you won't have problems afterward

yordan-kanchelov avatar Jun 01 '19 12:06 yordan-kanchelov

@jkanchelov Thanks for the effort hero

buryo avatar Jun 01 '19 12:06 buryo

#8

yordan-kanchelov avatar Jun 01 '19 14:06 yordan-kanchelov

Any luck with people using this in a typescript project?

Kurt-Montanaro avatar Jun 14 '19 01:06 Kurt-Montanaro

@Kurt-Montanaro its not big, you can make typings for it.

ivanpopelyshev avatar Jun 14 '19 08:06 ivanpopelyshev

@Kurt-Montanaro i am using it from my fork but it’s still in a very ugly and early phase

yordan-kanchelov avatar Jun 15 '19 14:06 yordan-kanchelov

lets work on the npm module. someone already made it: https://github.com/jkanchelov/PIXI.TextInput

jjhesk avatar Jun 29 '19 09:06 jjhesk

no luck. i have got

having:

import TextInput from "pixi-text-input"

"Uncaught TypeError: pixi_text_input__WEBPACK_IMPORTED_MODULE_1___default.a is not a constructor"

jjhesk avatar Jun 30 '19 06:06 jjhesk

@jjhesk I could publish it in its current state, but currently, I don't have time to improve it

yordan-kanchelov avatar Jun 30 '19 07:06 yordan-kanchelov

yes, try my new PR i took 2 hours to made it done. https://github.com/ONode/pixi-textinput usage: import Textput from "pixi-textinput"

jjhesk avatar Jun 30 '19 08:06 jjhesk

This package is a good example on how to support a Node and a drop-in browser target: https://github.com/davidfig/pixi-viewport

Note the two types of file in dist/, and how module: in package.json points to a es.js file that exports its members (instead of polluting the PIXI namespace).

connorjclark avatar Jul 15 '19 02:07 connorjclark

There is no module export in TextInput.js file. So just requiring it should work. PIXI.TextInput = require('pixi-text-input') But then I get another error: "Cannot read property 'call' of undefined" in the _proto.render() function in PIXI.TextInput.js line 185. On further troubleshooting I found that PIXI 4 is a dependency in package.json file of this module and the Container.js file in this dependecy (node_modules\pixi-text-input\node_modules\pixi.js\lib\core\display\Container.js) doesnt have a render() function. Only renderWebGL() and renderCanvas(). Deleting the node_module folder in the 'pixi-text-input' and using pixi 5 fixed the issue for me.

Has anyone else faced this issue? I think it only works with PIXI 5. If thats the case can you please update the dependecy in the npm package to PIXI 5?

karamvirs avatar Oct 02 '19 02:10 karamvirs

I have the same error, I am using pixi V5 (5.2.1). I installed "pixi-text-input" (now it is 1.0.4) feature, and created an instance of that and added to the stage, afterwards I run into that error related to rendering things. I think it is because now rendere was moved out of Display object?

HusakYurii avatar Apr 26 '20 19:04 HusakYurii

it wasnt , its still there. Also all objects are Containers, displayobject is base abstraction , not being used directly.

ivanpopelyshev avatar Apr 26 '20 20:04 ivanpopelyshev

It's clear, thanks! So, the question to the author then, will it be fixed? Because it is such a great feature!

HusakYurii avatar Apr 26 '20 20:04 HusakYurii

ok, will patch in a few hours. have to add something else anyways.

Mwni avatar Apr 26 '20 20:04 Mwni