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

[QUESTION] Problem with custom component type and table cell #2697

Closed
kuhelbeher opened this issue Apr 2, 2020 · 3 comments
Closed

[QUESTION] Problem with custom component type and table cell #2697

kuhelbeher opened this issue Apr 2, 2020 · 3 comments
Labels

Comments

@kuhelbeher
Copy link
Contributor

Hello! I'm trying to add custom component type:

  domc.addType('image-block', {
    extend: 'cell',
    model: {
      defaults: function () {
        return {
          name: 'Background image',
          type: 'image-block',
          tagName: 'td',
          void: false,
          droppable: true
        }
      }
    },
    isComponent (el) {
      if (el.tagName === 'TD' && el.classList.contains('bg-image')) {
        return { type: 'image-block' }
      }
    }
  })

And also I'm adding new block:

bm.add('image-block', {
    label: 'Background Image',
    category: 'Basic',
    content: `
      <table width="100%" class="bg-image-wrapper">
        <tbody>
          <tr>
            <td class="bg-image">
            </td>
          </tr>
        </tbody>
      </table>
      <style>
        .bg-image-wrapper {
          min-height: 200px;
        }
        .bg-image {
          background-image: url(https://i.pinimg.com/564x/cd/54/01/cd5401f170307b0fbf6cb28fb62e69f7.jpg);
          background-size: cover;
          background-position: center;
          background-repeat: no-repeat;
        }
      </style>
    `

But when I drop this block on the canvas the tag doesn't appear on canvas and DOM. If I remove isComponent function from component definition, it works as expected. Could I get help with this?

@kuhelbeher kuhelbeher changed the title {QUESTION] Problem with custom component type and table cell [QUESTION] Problem with custom component type and table cell Apr 2, 2020
@noogen
Copy link

noogen commented Apr 5, 2020

@kuhelbeher because your component is a table per your content definition above and not a td as defined in your addType of tagName property?

@kuhelbeher
Copy link
Contributor Author

kuhelbeher commented Apr 6, 2020

@noogen I don't think the problem is with this. I tried to define component and block like this:

  domc.addType('custom-cell', {
    extends: 'cell',
    model: {
      defaults: {
        removable: false,
        name: 'Custom cell',
        type: 'custom-cell',
        copyable: false,
        tagName: 'td'
      }
    }
  })

  bm.add('root', {
    label: 'Page Wrapper',
    category: opt.category,
    content: `
        <table width="400px">
          <tbody>
            <tr>
              <td data-gjs-type="custom-cell">
              
              </td>
            </tr>
          </tbody>
        </table>
    `,
  })

But the problem remains - td tag (and all what is inside of it) doesn't appear on canvas, Maybe I'm doing something wrong?
I am trying to create new component type from built-in 'cell' type but it should be in table. Thats why I created new block. Maybe you can suggest some other solution?

@artf
Copy link
Member

artf commented Apr 15, 2020

@kuhelbeher your code is correct (except is extend: 'cell', and not extends: 'cell',), unfortunately, there is a bug (or a bad logic) applied on the row component, so, for now, I'd suggest adding this as a patch:

const modelDefault =  domc.getType('default').model;
domc.addType('row', {
    model: {
      initialize() {
        modelDefault.prototype.initialize.apply(this, arguments);
      },
    }
});

and now it should work: https://jsfiddle.net/corasd1h/

@artf artf added the bug label Apr 15, 2020
@artf artf closed this as completed in 9a3d0e1 Apr 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants