Giter Club home page Giter Club logo

enonic-ts-codegen's People

Contributors

bfjoren avatar dependabot[bot] avatar garlov avatar tajakobsen avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

enonic-ts-codegen's Issues

Input type "tag" should be array

When generating types from our XML, any input type using the Enonic type tag will generate an interface for a string, but tags are stored as a string only on single values, otherwise it is an array of strings.

What we have:

<input name="tags" type="Tag">
     <label>Tags</label>
     <occurrences minimum="0" maximum="0"/>
</input>

What we get:

  /**
   * Tags
   */
  tags?: string;

Can we fascilitate automatic "forceArray"?

The type of ItemSets are T | Array<T> | undefined, when it would be easier to work with them if they were just Array<T>, but then we have to do forceArray on them, and the interfaces are still not improved.

Could we use a flag in tye .enonic-file that renders out ItemSet-interfaces as Array<T>, and also a list of fieldNames that are ItemSets.

That way we can automatically iterate over the fieldNames, and fix with forceArray.

Old:

export interface Article {
  myField?: Array<{
    name: string;
  }>
}

New:

export interface Article {
  myField: Array<{
    name: string;
  }>
}

export itemSetFieldNames = ['myField']

We can then in enonic-wizardry create something that can be used like this:

import {Article,itemSetFieldNames} from '../../content-types/article/article.ts';
const query = getQueryer<Article>(itemSetFieldNames);

query({
  ...
})

Generated interface for ComboBox should restrict legal values

Input xml:

<input name="invite" type="ComboBox">
  <label>Invitert</label>
  <occurrences minimum="0" maximum="1"/>
  <config>
    <option value="Ja">Ja</option>
    <option value="Nei">Nei</option>
    <option value="Kvalifisering">Kvalifisering</option>
  </config>
</input>

Output ts:

export interface Soknad {
  invite?: "Ja" | "Nei" | "Kvalifisering";
}

Support recursive use of mixins

Amazing library, we use it and it helps us a lot. However, we would love for it to support a not very uncommon scenario: mixins within mixins. It is in cases where we store only a few fields (like a kind-of heavily configured ImageSelector) in a mixin, and then use this one in other, larger, mixins. This is not supported in the generator today, so it ends up like mixinName: mixin, in the generated code.

Could mixins be resolved recursively, and at the very beginning before all types are resolved?

Example Content Type, followed by example mixin level 1, and example mixin level 2:

Content Type:

article.xml

<?xml version="1.0" encoding="UTF-8"?>
<content-type>
    <display-name>Page: Article</display-name>
    <display-name-label>Title</display-name-label>
    <description>Used for writing articles, blogposts, product info.</description>
    <super-type>base:structured</super-type>
    <is-abstract>false</is-abstract>
    <is-final>false</is-final>
    <is-built-in>false</is-built-in>
    <allow-child-content>true</allow-child-content>
    <form>
        <field-set>
            <label>Article</label>
            <items>
                <mixin name="common"></mixin>
            </items>
        </field-set>
   </form>
</content-type>

Mixin Lvl 1

common.xml

<mixin>
  <display-name>Common</display-name>
  <form>
    <input name="title" type="TextLine">
      <label>Title</label>
      <occurrences minimum="0" maximum="1"/>
    </input>
    <input name="preface" type="TextArea">
      <label>Preface</label>
      <occurrences minimum="0" maximum="1"/>
    </input>
    <mixin name="optional-image"/>
  </form>
</mixin>

Mixin Lvl 2

optional-image.xml

<mixin>
    <display-name>Optional Image</display-name>
    <form>
        <option-set name="imageSelector">
            <!-- Too large of a form to include here ... but this structure should give you an idea. -->
        </option-set>
    </form>
</mixin>

Make check for input type case insensitive

Checking against type="Checkbox" instead of type="CheckBox" gives the wrong type for the field, since this application enforces case sensitivity that Enonic does not.

Disable code generation by specifying an attribute in xml

See if a custom xml attribute can be used to disable code generation for a given component.

I hadn't specified whare the xml attribute is, but we should consider having a common prefix, if we add more custom xml attributes later.

Mixins is generating wrong interfaces

Lets say we have the following mixin (/site/mixins/with-description/with-description.xml)

<mixin>
  <display-name>With Description</display-name>

  <form>
    <input name="description" type="TextLine">
      <label>Description</label>
      <occurrences minimum="0" maximum="1"/>
    </input>
  </form>
</mixin>

And it is being used in an content-type (article.xml):

<content-type>
  <display-name>Article</display-name>
  <super-type>base:structured</super-type>

  <form>
    <mixin name="with-description" />
  </form>
</content-type>

It will generate the following (wrong) interface:

export interface Article {
  /**
   * With Description
   */
  'with-description': {
    /**
     * Description
     */
    description?: string;
  };
}

The correct interface to generate would be this:

export interface Article {
  /**
   * Description
   */
  description?: string;
}

No code gen for option-set inside field-set

The option-set in the xml below is not generated:

<field-set>
    <label>Important header</label>
    <items>
      <option-set name="somethingoptionset"> <!-- not generated -->
        <label>options</label>
        <expanded>false</expanded>
        <occurrences minimum="0" maximum="1"/>
        <options minimum="1" maximum="1">
          <option>
          <option>
        </options>
      </option-set>
    </items>
<field-set>

An option-set inside an item-set inside a field-set is generated though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.