{"bugs":{"url":"https://github.com/material-components/material-components-web/issues"},"dist":{"shasum":"405e2e101c8a0e877901f9c532fd210dbc792d28","tarball":"https://registry.npmjs.org/@material/auto-init/-/auto-init-1.0.0-1.tgz","fileCount":10,"integrity":"sha512-vzU0fiYKyWBJmkN94Kz9sRKzmeC8P7I3Fn7Kw2uHVKZMYDwU9xcSBz63C4LUG8pzut78+OXPm0BWX1SvHPbYHQ==","signatures":[{"sig":"MEUCIQDPghZNqx96JEfrbLiV0AvbN4BwrWv+2Mpmtzwi5dmd2gIgEBsVsquJNOanoRBoLKkIbVI4hiPGkPDEs3nFwjWCxuQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":115213,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcfbW1CRA9TVsSAnZWagAAXfEP/RA5etpN7jwnWBhTScSm\nnc3J3RYR/fewop7o2nK8XmrZAcnGlWNHz09sfI9vyPTYzYV2RwDUYhG2E4JY\nM5/Y4AESgB3EPh2swzREAGlCoy6yfk4PcmfyyY/j1NF3yQXsEVayH4+9RNIs\npjuoKDkhvsd7ZCc/J3j24uVFDEBq5VDn0gRbWj0SbCR1jG0ieZGpUptOgBU3\n6tFJLPz9bWIpQGtMbGSq8U5UQM+C5nEqE0I4TR3sp44+v8SDZcKz5t/pAUXh\nUeF4gfEGxazVaeXMv79WwPVVW14c0r02/MvCNa1tmBjm14FTBnwlvSvXYc4Z\nhAXMGGRdMIdtUHIHtdBUjDxJIHTkdaV8C4/SGp8cGbYcYx2g29HedkRNZjDa\nYDUnA/3w84nucULOeykxVeIAr6fxiqWxN9q5gyGRhmkODNH930wHG4HlpleK\nwTvEScpcIKSB0SsWndFFYL5G3wiuHv+/8CWHU6SMxs3D2dtn49tvZqhNEK9i\nEJJbqn/6l5/pFya72rOL3NHTH2c/c15aOC5iSEVfXpgqSL8MYSiB9Cr0UO8W\nd5ccWKe4E45y//5zQUZu6oc3JM0DsfH5zVpKgTPPiPKU0Eb57dxpzaojHfLK\ncprIYWW1xtM0FqfLmnCqTIq+o0SWgOBxxHobdvgEr/W1uqUQ2y3YVDhfUr+X\nsR1M\r\n=up7J\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/mdc.autoInit.js","name":"@material/auto-init","types":"dist/mdc.autoInit.d.ts","module":"index.js","readme":"<!--docs:\ntitle: \"Auto Init\"\nlayout: detail\nsection: components\nexcerpt: \"Utilities for declarative, DOM-based initialization of components on simple web sites.\"\npath: /catalog/auto-init/\n-->\n\n# Auto Init\n\n`mdc-auto-init` is a utility package that provides declarative, DOM-based method of initialization\nfor MDC Web components on simple web sites. Note that for more advanced use-cases and complex sites,\nmanual instantiation of components will give you more flexibility. However, `mdc-auto-init` is great\nfor static websites, prototypes, and other use-cases where simplicity and convenience is most\nappropriate.\n\n## Installation\n\n```\nnpm install @material/auto-init\n```\n\n## Usage\n\n### Using as part of `material-components-web`\n\nIf you are using mdc-auto-init as part of the [material-components-web](../material-components-web)\npackage, simply write the necessary DOM needed for a component, and attach a `data-mdc-auto-init`\nattribute to the root element with its value set to the component's JavaScript class name (e.g.,\n`MDCTextField`). Then, after writing the markup, simply insert a script tag that calls\n`mdc.autoInit()`. Make sure you call `mdc.autoInit()` after all scripts are loaded so it works\nproperly.\n\n```html\n<div class=\"mdc-text-field\" data-mdc-auto-init=\"MDCTextField\">\n  <input class=\"mdc-text-field__input\" type=\"text\" id=\"input\">\n  <label for=\"input\" class=\"mdc-floating-label\">Input Label</label>\n  <div class=\"mdc-line-ripple\"></div>\n</div>\n\n<!-- at the bottom of the page -->\n<script type=\"text/javascript\">\n  window.mdc.autoInit();\n</script>\n```\n\nThis will attach an [MDCTextField](../mdc-textfield) instance to the root `<div>` element.\n\n#### Accessing the component instance\n\nWhen `mdc-auto-init` attaches a component to an element, it assign that instance to the element\nusing a property whose name is the value of `data-mdc-auto-init`. For example, given\n\n```html\n<div class=\"mdc-text-field\" data-mdc-auto-init=\"MDCTextField\">\n  <input class=\"mdc-text-field__input\" type=\"text\" id=\"input\">\n  <label for=\"input\" class=\"mdc-floating-label\">Input Label</label>\n  <div class=\"mdc-line-ripple\"></div>\n</div>\n```\n\nOnce `mdc.autoInit()` is called, you can access the component instance via an `MDCTextField`\nproperty on that element.\n\n```js\ndocument.querySelector('.mdc-text-field').MDCTextField.disabled = true;\n```\n\n### Using as a standalone module\n\n#### Registering Components\n\nIf you are using `mdc-auto-init` outside of `material-components-web`, you must manually provide a\nmapping between `data-mdc-auto-init` attribute values and the components which they map to. This can\nbe achieved via `mdcAutoInit.register`.\n\n```js\nimport mdcAutoInit from '@material/auto-init';\nimport {MDCTextField} from '@material/textfield';\n\nmdcAutoInit.register('MDCTextField', MDCTextField);\n```\n\n`mdcAutoInit.register()` tells `mdc-auto-init` that when it comes across an element with a\n`data-mdc-auto-init` attribute set to `\"MDCTextField\"`, it should initialize an `MDCTextField`\ninstance on that element. The `material-components-web` package does this for all components for\nconvenience.\n\nAlso note that a component can be mapped to any string, not necessarily the name of its constructor.\n\n```js\nimport mdcAutoInit from '@material/auto-init';\nimport {MDCTextField} from '@material/textfield';\n\nmdcAutoInit.register('My amazing text field!!!', MDCTextField);\n```\n\n```html\n<div class=\"mdc-text-field\" data-mdc-auto-init=\"My amazing text field!!!\">\n  <!-- ... -->\n</div>\n<script>window.mdc.autoInit();</script>\n```\n\n### De-registering components\n\nAny component can be deregistered by calling `mdcAutoInit.deregister` with the name used to register\nthe component.\n\n```js\nmdcAutoInit.deregister('MDCTextField');\n```\n\nThis will simply remove the name -> component mapping. It will _not_ affect any already-instantiated\ncomponents on the page.\n\nTo unregister all name -> component mappings, you can use `mdcAutoInit.deregisterAll()`.\n\n## How `mdc-auto-init` works\n\n`mdc-auto-init` maintains a registry object which maps string identifiers, or **names**, to\ncomponent constructors. When the default exported function - `mdcAutoInit()` - is called,\n`mdc-auto-init` queries the DOM for all elements with a `data-mdc-auto-init` attribute. For each\nelement returned, the following steps are taken:\n\n1. If the `data-mdc-auto-init` attribute does not have a value associated with it, throw an error\n2. If the value of `data-mdc-auto-init` cannot be found in the registry, throw an error\n3. If the element has an existing property whose name is the value of `data-mdc-auto-init`, it is\n   assumed to have already been initialized. Therefore it is skipped, and a warning will be logged\n   to the console (this behavior can be overridden).\n4. Let `Ctor` be the component constructor associated with the given name in the register\n5. Let `instance` be the result of calling `Ctor.attachTo()` and passing in the element as an\n   argument.\n6. Create a non-writable, non-enumerable property on the node whose name is the value of\n   `data-mdc-auto-init` and whose value is `instance`.\n\n### Initializing only a certain part of the page\n\nBy default, `mdc-auto-init` will query the entire document to figure out which components to\ninitialize. To override this behavior, you can pass in an optional `root` first argument specifying\nthe root node whose children will be queried for instantiation.\n\n```html\n<div id=\"mdc-section\">\n  <!-- MDC Web Components, etc. -->\n</div>\n<script>window.mdc.autoInit(document.getElementById('mdc-section'));</script>\n```\n\nIn the above example, only elements within `<div id=\"mdc-section\">` will be queried.\n\n### Calling autoInit() multiple times\n\nBy default, `mdc-auto-init` only expects to be called once, at page-load time. However, there may be\ncertain scenarios where one may want to use `mdc-auto-init` and may still need to call it multiple\ntimes, such as on a Wordpress site that contains an infinitely-scrolling list of new blog post\nelements containing MDC Web components. `mdcAutoInit()` takes an optional second argument which is the\nfunction used to warn users when a component is initialized multiple times. By default, this is just\n`console.warn()`. However, to skip over already-initialized components without logging a\nwarning, you could simply pass in a nop.\n\n```html\n<script>window.mdc.autoInit(/* root */ document, () => {});</script>\n```\n\nThis will suppress any warnings about already initialized elements.\n\n### Events\n\n#### MDCAutoInit:End\nTriggered when initialization of all components is complete.\n\n`document.addEventListener(\"MDCAutoInit:End\", () => {...});`\n","license":"MIT","_npmUser":{"name":"kfranqueiro","email":"kenneth.franqueiro@gmail.com"},"homepage":"https://github.com/material-components/material-components-web#readme","repository":{"url":"git+https://github.com/material-components/material-components-web.git","type":"git"},"_npmVersion":"6.7.0","description":"Declarative, easy-to-use auto-initialization for Material Components for the web","directories":{},"maintainers":[{"name":"abhiomkar","email":"abhiomkar@gmail.com"},{"name":"acdvorak","email":"acdvorak@gmail.com"},{"name":"aprigogin","email":"andrey.prigogin@gmail.com"},{"name":"azakus","email":"dfreedm2@gmail.com"},{"name":"bicknellr","email":"bicknellr@gmail.com"},{"name":"bonniez","email":"bonniez@google.com"},{"name":"bwobrien","email":"obrien.test@gmail.com"},{"name":"kfranqueiro","email":"kenneth.franqueiro@gmail.com"},{"name":"lynnjepsen","email":"lynnjepsen@google.com"},{"name":"material-admin","email":"lynnjepsen+npm@google.com"},{"name":"moog16","email":"mattgoo@gmail.com"},{"name":"patrickrodee","email":"prodee@google.com"},{"name":"williamernest","email":"williamernest@google.com"}],"sideEffects":false,"_nodeVersion":"10.9.0","dependencies":{"tslib":"^1.9.3","@material/base":"^1.0.0-1"},"_hasShrinkwrap":false,"readmeFilename":"README.md","_npmOperationalInternal":{"tmp":"tmp/auto-init_1.0.0-1_1551742388582_0.3743176921546749","host":"s3://npm-registry-packages"},"_id":"@material/auto-init@1.0.0-1","version":"1.0.0-1"}