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

make SCHEMAS extendable #16306

Closed
zh99998 opened this issue Apr 25, 2017 · 2 comments
Closed

make SCHEMAS extendable #16306

zh99998 opened this issue Apr 25, 2017 · 2 comments

Comments

@zh99998
Copy link

zh99998 commented Apr 25, 2017

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

now schemas are not extendable, only hard-coded CUSTOM_ELEMENT_SCHEMA and NO_ERRORS_SCHEMA available. if a user want to add new schema, they have to modify DomElementSchemaRegistry.hasElement,DomElementSchemaRegistry.prototype.hasProperty or other compiler methods to do it. like this
https://github.com/moecube/electron-schema/blob/master/index.ts

Expected behavior

if (schemaMetas.some((schema) => schema.name === NO_ERRORS_SCHEMA.name)) {

make DomElementSchemaRegistry.hasElement,DomElementSchemaRegistry.prototype.hasProperty and other compiler methods to read schemaMetas not only name, but also some contents, for example, a string[] like SCHEMA defined in

then user can just declare something like

const ELECTRON_SCHEMA = ['webview^[HTMLElement]|src,...']

then put it in ngModule.schemas .

@NgModule({
  // ...
  schemas: [ELECTRON_SCHEMA]
})
export class AppModule {
}

for more clearly, it could be a interface rather than a string, like..

interface SchemaData {
  tagName: string
  type: string
  attributes: string[]
  ... // other security-related fields
}

for more dynamic use, it could also be a function-based interface, it can combined with normal SchemaMetadata interface, for example:

interface SchemaMeta {
  name: string
  hasElement?(tagName, schemaMetas): boolean
  hasProperty?(tagName, propName, schemaMetas): boolean
  ... // other security-related methods
}

then CUSTOM_ELEMENTS_SCHEMA and NO_ERROES_SCHEMA could also be a normal SchemaMeta, and don't need hard-code in compiler, like

class NO_ERROES_SCHEMA implements SchemaMetadata {
  name: 'no-errors-schema'
  hasElement(tagName, schemaMetas) {return true}
  hasProperty(tagName, propName, schemaMetas) {return true}
}
@vicb
Copy link
Contributor

vicb commented Apr 25, 2017

Duplicate of #12045

@vicb vicb closed this as completed Apr 25, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants