@lrnwebcomponents/schema-behaviors
Advanced tools
Comparing version 2.0.10 to 2.1.0
@@ -11,7 +11,7 @@ { | ||
"start": { | ||
"line": 97, | ||
"line": 5, | ||
"column": 31 | ||
}, | ||
"end": { | ||
"line": 175, | ||
"line": 88, | ||
"column": 1 | ||
@@ -24,161 +24,2 @@ } | ||
], | ||
"metadata": { | ||
"polymer": { | ||
"behaviors": [ | ||
{ | ||
"description": "`SchemaBehaviors`\n\nmakes it easier to wire custom elements for\nschematic metadata by allowing prefixes to be defined in an object\nstructure. This makes it easier to add and remove them then working\nagainst the attribute directly. It also helps with generating\nresource IDs automatically if they don't already exist on the element.", | ||
"summary": "", | ||
"path": "schema-behaviors.js", | ||
"properties": [ | ||
{ | ||
"name": "schemaResourceID", | ||
"type": "string | null | undefined", | ||
"description": "Unique Resource ID, generated when schemaMap processes.", | ||
"privacy": "public", | ||
"sourceRange": { | ||
"start": { | ||
"line": 26, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 29, | ||
"column": 5 | ||
} | ||
}, | ||
"metadata": { | ||
"polymer": { | ||
"attributeType": "String" | ||
} | ||
}, | ||
"defaultValue": "\"\"" | ||
}, | ||
{ | ||
"name": "schemaMap", | ||
"type": "Object | null | undefined", | ||
"description": "Schema Map for this element.", | ||
"privacy": "public", | ||
"sourceRange": { | ||
"start": { | ||
"line": 33, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 46, | ||
"column": 5 | ||
} | ||
}, | ||
"metadata": { | ||
"polymer": { | ||
"observer": "\"_schemaMapChanged\"", | ||
"attributeType": "Object" | ||
} | ||
}, | ||
"defaultValue": "{\"prefix\":{\"oer\":\"http://oerschema.org/\",\"schema\":\"http://schema.org/\",\"dc\":\"http://purl.org/dc/terms/\",\"foaf\":\"http://xmlns.com/foaf/0.1/\",\"cc\":\"http://creativecommons.org/ns#\",\"bib\":\"http://bib.schema.org\"}}" | ||
} | ||
], | ||
"methods": [ | ||
{ | ||
"name": "generateResourceID", | ||
"description": "Generate a uinque ID", | ||
"privacy": "public", | ||
"sourceRange": { | ||
"start": { | ||
"line": 51, | ||
"column": 2 | ||
}, | ||
"end": { | ||
"line": 68, | ||
"column": 3 | ||
} | ||
}, | ||
"metadata": {}, | ||
"params": [] | ||
}, | ||
{ | ||
"name": "_schemaMapChanged", | ||
"description": "Notice the schema map has changed, reprocess attributes.", | ||
"privacy": "protected", | ||
"sourceRange": { | ||
"start": { | ||
"line": 72, | ||
"column": 2 | ||
}, | ||
"end": { | ||
"line": 94, | ||
"column": 3 | ||
} | ||
}, | ||
"metadata": {}, | ||
"params": [ | ||
{ | ||
"name": "newValue" | ||
}, | ||
{ | ||
"name": "oldValue" | ||
} | ||
], | ||
"return": { | ||
"type": "void" | ||
} | ||
} | ||
], | ||
"staticMethods": [], | ||
"demos": [], | ||
"metadata": {}, | ||
"sourceRange": { | ||
"start": { | ||
"line": 21, | ||
"column": 0 | ||
}, | ||
"end": { | ||
"line": 95, | ||
"column": 2 | ||
} | ||
}, | ||
"privacy": "public", | ||
"name": "SchemaBehaviors.Schema", | ||
"attributes": [ | ||
{ | ||
"name": "schema-resource-i-d", | ||
"description": "Unique Resource ID, generated when schemaMap processes.", | ||
"sourceRange": { | ||
"start": { | ||
"line": 26, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 29, | ||
"column": 5 | ||
} | ||
}, | ||
"metadata": {}, | ||
"type": "string | null | undefined" | ||
}, | ||
{ | ||
"name": "schema-map", | ||
"description": "Schema Map for this element.", | ||
"sourceRange": { | ||
"start": { | ||
"line": 33, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 46, | ||
"column": 5 | ||
} | ||
}, | ||
"metadata": {}, | ||
"type": "Object | null | undefined" | ||
} | ||
], | ||
"events": [], | ||
"styling": { | ||
"cssVariables": [], | ||
"selectors": [] | ||
}, | ||
"slots": [] | ||
} | ||
] | ||
} | ||
}, | ||
"classes": [ | ||
@@ -197,7 +38,7 @@ { | ||
"start": { | ||
"line": 130, | ||
"line": 43, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 147, | ||
"line": 60, | ||
"column": 5 | ||
@@ -215,7 +56,7 @@ } | ||
"start": { | ||
"line": 151, | ||
"line": 64, | ||
"column": 4 | ||
}, | ||
"end": { | ||
"line": 173, | ||
"line": 86, | ||
"column": 5 | ||
@@ -243,7 +84,7 @@ } | ||
"start": { | ||
"line": 98, | ||
"line": 6, | ||
"column": 9 | ||
}, | ||
"end": { | ||
"line": 174, | ||
"line": 87, | ||
"column": 3 | ||
@@ -250,0 +91,0 @@ } |
@@ -65,4 +65,8 @@ const gulp = require("gulp"); | ||
// properties available to the custom element for data binding | ||
static get properties() { | ||
return ${props}; | ||
static get properties() { | ||
let props = ${props}; | ||
if (super.properties) { | ||
props = Object.assign(props, super.properties); | ||
} | ||
return props; | ||
}`; | ||
@@ -69,0 +73,0 @@ } |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "2.0.10", | ||
"version": "2.1.0", | ||
"description": "Apply schema helper behaviors to existing Polymer (Legacy) based elements", | ||
@@ -43,6 +43,6 @@ "repository": { | ||
"@lrnwebcomponents/deduping-fix": "^2.0.9", | ||
"@lrnwebcomponents/storybook-utilities": "^2.0.10", | ||
"@lrnwebcomponents/storybook-utilities": "^2.1.0", | ||
"@polymer/iron-component-page": "github:PolymerElements/iron-component-page", | ||
"@polymer/iron-demo-helpers": "^3.1.0", | ||
"@webcomponents/webcomponentsjs": "^2.2.9", | ||
"@webcomponents/webcomponentsjs": "2.2.10", | ||
"concurrently": "4.1.0", | ||
@@ -52,3 +52,3 @@ "gulp-babel": "8.0.0", | ||
"lodash": "4.17.11", | ||
"polymer-cli": "1.9.8", | ||
"polymer-cli": "1.9.9", | ||
"wct-browser-legacy": "1.0.2" | ||
@@ -64,3 +64,3 @@ }, | ||
], | ||
"gitHead": "8571f08ce381877be732c2b5407233bcc3c58d99" | ||
"gitHead": "38a0c3ad00e8447837037bde2dc1172273a3a311" | ||
} |
define(["exports"],function(_exports){"use strict";Object.defineProperty(_exports,"__esModule",{value:!0});_exports.SchemaBehaviors=void 0;/** | ||
* Copyright 2018 The Pennsylvania State University | ||
* @license Apache-2.0, see License.md for full text. | ||
*/ // ensure SchemaBehaviors exists | ||
window.SchemaBehaviors=window.SchemaBehaviors||{};/** | ||
* `SchemaBehaviors` | ||
* | ||
* makes it easier to wire custom elements for | ||
* schematic metadata by allowing prefixes to be defined in an object | ||
* structure. This makes it easier to add and remove them then working | ||
* against the attribute directly. It also helps with generating | ||
* resource IDs automatically if they don't already exist on the element. | ||
* | ||
* @microcopy - language worth noting: | ||
* - | ||
* | ||
* @polymer | ||
* @polymerBehavior SchemaBehaviors.Schema | ||
*/window.SchemaBehaviors.Schema={properties:{/** | ||
* Unique Resource ID, generated when schemaMap processes. | ||
*/schemaResourceID:{type:String,value:""},/** | ||
* Schema Map for this element. | ||
*/schemaMap:{type:Object,value:{prefix:{oer:"http://oerschema.org/",schema:"http://schema.org/",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",bib:"http://bib.schema.org"}},observer:"_schemaMapChanged"}},/** | ||
* Generate a uinque ID | ||
*/generateResourceID:function generateResourceID(){function idPart(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return"#"+idPart()+idPart()+"-"+idPart()+"-"+idPart()+"-"+idPart()},/** | ||
* Notice the schema map has changed, reprocess attributes. | ||
*/_schemaMapChanged:function _schemaMapChanged(newValue,oldValue){if(babelHelpers.typeof(newValue)!==("undefined"===typeof void 0?"undefined":babelHelpers.typeof(void 0))){// use this to tie into schemaResourceID build | ||
this.schemaResourceID=this.getAttribute("resource");// if it still doesn't have one then we have to check | ||
if(""==this.schemaResourceID||null==this.schemaResourceID){this.schemaResourceID=this.generateResourceID();this.setAttribute("resource",this.schemaResourceID)}var prefixes=newValue.prefix,prefix="";// build prefix string | ||
for(var property in prefixes){if(prefixes.hasOwnProperty(property)){prefix+=property+":"+prefixes[property]+" "}}// set prefix on the main element itself | ||
if(""!=prefix){this.setAttribute("prefix",prefix)}}}};var SchemaBehaviors=function SchemaBehaviors(SuperClass){return(/*#__PURE__*/function(_SuperClass){babelHelpers.inherits(_class,_SuperClass);function _class(){babelHelpers.classCallCheck(this,_class);return babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(_class).apply(this,arguments))}babelHelpers.createClass(_class,[{key:"generateResourceID",/** | ||
*/var SchemaBehaviors=function SchemaBehaviors(SuperClass){return(/*#__PURE__*/function(_SuperClass){babelHelpers.inherits(_class,_SuperClass);function _class(){babelHelpers.classCallCheck(this,_class);return babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(_class).apply(this,arguments))}babelHelpers.createClass(_class,[{key:"generateResourceID",/** | ||
* Generate a uinque ID | ||
@@ -39,6 +12,6 @@ */value:function generateResourceID(){function idPart(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return"#"+idPart()+idPart()+"-"+idPart()+"-"+idPart()+"-"+idPart()}/** | ||
for(var property in prefixes){if(prefixes.hasOwnProperty(property)){prefix+=property+":"+prefixes[property]+" "}}// set prefix on the main element itself | ||
if(""!=prefix){this.setAttribute("prefix",prefix)}}}}],[{key:"properties",get:function get(){return{/** | ||
if(""!=prefix){this.setAttribute("prefix",prefix)}}}}],[{key:"properties",get:function get(){var props={/** | ||
* Unique Resource ID, generated when schemaMap processes. | ||
*/schemaResourceID:{type:String,value:""},/** | ||
* Schema Map for this element. | ||
*/schemaMap:{type:Object,value:{prefix:{oer:"http://oerschema.org/",schema:"http://schema.org/",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",bib:"http://bib.schema.org"}},observer:"_schemaMapChanged"}}}}]);return _class}(SuperClass))};_exports.SchemaBehaviors=SchemaBehaviors}); | ||
* Schema Map for the element, used to generate a valid prefix on the fly | ||
*/schemaMap:{type:Object,readOnly:!0,value:{prefix:{oer:"http://oerschema.org/",schema:"http://schema.org/",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",bib:"http://bib.schema.org"}},observer:"_schemaMapChanged"}};if(babelHelpers.get(babelHelpers.getPrototypeOf(_class),"properties",this)){props=Object.assign(props,babelHelpers.get(babelHelpers.getPrototypeOf(_class),"properties",this))}return props}}]);return _class}(SuperClass))};_exports.SchemaBehaviors=SchemaBehaviors}); |
/** | ||
* Copyright 2018 The Pennsylvania State University | ||
* @license Apache-2.0, see License.md for full text. | ||
*/ // ensure SchemaBehaviors exists | ||
window.SchemaBehaviors=window.SchemaBehaviors||{};/** | ||
* `SchemaBehaviors` | ||
* | ||
* makes it easier to wire custom elements for | ||
* schematic metadata by allowing prefixes to be defined in an object | ||
* structure. This makes it easier to add and remove them then working | ||
* against the attribute directly. It also helps with generating | ||
* resource IDs automatically if they don't already exist on the element. | ||
* | ||
* @microcopy - language worth noting: | ||
* - | ||
* | ||
* @polymer | ||
* @polymerBehavior SchemaBehaviors.Schema | ||
*/window.SchemaBehaviors.Schema={properties:{/** | ||
* Unique Resource ID, generated when schemaMap processes. | ||
*/schemaResourceID:{type:String,value:""},/** | ||
* Schema Map for this element. | ||
*/schemaMap:{type:Object,value:{prefix:{oer:"http://oerschema.org/",schema:"http://schema.org/",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",bib:"http://bib.schema.org"}},observer:"_schemaMapChanged"}},/** | ||
* Generate a uinque ID | ||
*/generateResourceID:function(){function idPart(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return"#"+idPart()+idPart()+"-"+idPart()+"-"+idPart()+"-"+idPart()},/** | ||
* Notice the schema map has changed, reprocess attributes. | ||
*/_schemaMapChanged:function(newValue,oldValue){if(typeof newValue!==typeof void 0){// use this to tie into schemaResourceID build | ||
this.schemaResourceID=this.getAttribute("resource");// if it still doesn't have one then we have to check | ||
if(""==this.schemaResourceID||null==this.schemaResourceID){this.schemaResourceID=this.generateResourceID();this.setAttribute("resource",this.schemaResourceID)}let prefixes=newValue.prefix,prefix="";// build prefix string | ||
for(var property in prefixes){if(prefixes.hasOwnProperty(property)){prefix+=property+":"+prefixes[property]+" "}}// set prefix on the main element itself | ||
if(""!=prefix){this.setAttribute("prefix",prefix)}}}};export const SchemaBehaviors=function(SuperClass){return class extends SuperClass{static get properties(){return{/** | ||
*/export const SchemaBehaviors=function(SuperClass){return class extends SuperClass{static get properties(){let props={/** | ||
* Unique Resource ID, generated when schemaMap processes. | ||
*/schemaResourceID:{type:String,value:""},/** | ||
* Schema Map for this element. | ||
*/schemaMap:{type:Object,value:{prefix:{oer:"http://oerschema.org/",schema:"http://schema.org/",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",bib:"http://bib.schema.org"}},observer:"_schemaMapChanged"}}}/** | ||
* Schema Map for the element, used to generate a valid prefix on the fly | ||
*/schemaMap:{type:Object,readOnly:!0,value:{prefix:{oer:"http://oerschema.org/",schema:"http://schema.org/",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",bib:"http://bib.schema.org"}},observer:"_schemaMapChanged"}};if(super.properties){props=Object.assign(props,super.properties)}return props}/** | ||
* Generate a uinque ID | ||
@@ -37,0 +10,0 @@ */generateResourceID(){function idPart(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return"#"+idPart()+idPart()+"-"+idPart()+"-"+idPart()+"-"+idPart()}/** |
@@ -5,94 +5,2 @@ /** | ||
*/ | ||
// ensure SchemaBehaviors exists | ||
window.SchemaBehaviors = window.SchemaBehaviors || {}; | ||
/** | ||
* `SchemaBehaviors` | ||
* | ||
* makes it easier to wire custom elements for | ||
* schematic metadata by allowing prefixes to be defined in an object | ||
* structure. This makes it easier to add and remove them then working | ||
* against the attribute directly. It also helps with generating | ||
* resource IDs automatically if they don't already exist on the element. | ||
* | ||
* @microcopy - language worth noting: | ||
* - | ||
* | ||
* @polymer | ||
* @polymerBehavior SchemaBehaviors.Schema | ||
*/ | ||
window.SchemaBehaviors.Schema = { | ||
properties: { | ||
/** | ||
* Unique Resource ID, generated when schemaMap processes. | ||
*/ | ||
schemaResourceID: { | ||
type: String, | ||
value: "" | ||
}, | ||
/** | ||
* Schema Map for this element. | ||
*/ | ||
schemaMap: { | ||
type: Object, | ||
value: { | ||
prefix: { | ||
oer: "http://oerschema.org/", | ||
schema: "http://schema.org/", | ||
dc: "http://purl.org/dc/terms/", | ||
foaf: "http://xmlns.com/foaf/0.1/", | ||
cc: "http://creativecommons.org/ns#", | ||
bib: "http://bib.schema.org" | ||
} | ||
}, | ||
observer: "_schemaMapChanged" | ||
} | ||
}, | ||
/** | ||
* Generate a uinque ID | ||
*/ | ||
generateResourceID: function() { | ||
function idPart() { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1); | ||
} | ||
return ( | ||
"#" + | ||
idPart() + | ||
idPart() + | ||
"-" + | ||
idPart() + | ||
"-" + | ||
idPart() + | ||
"-" + | ||
idPart() | ||
); | ||
}, | ||
/** | ||
* Notice the schema map has changed, reprocess attributes. | ||
*/ | ||
_schemaMapChanged: function(newValue, oldValue) { | ||
if (typeof newValue !== typeof undefined) { | ||
// use this to tie into schemaResourceID build | ||
this.schemaResourceID = this.getAttribute("resource"); | ||
// if it still doesn't have one then we have to check | ||
if (this.schemaResourceID == "" || this.schemaResourceID == null) { | ||
this.schemaResourceID = this.generateResourceID(); | ||
this.setAttribute("resource", this.schemaResourceID); | ||
} | ||
let prefixes = newValue.prefix; | ||
let prefix = ""; | ||
// build prefix string | ||
for (var property in prefixes) { | ||
if (prefixes.hasOwnProperty(property)) { | ||
prefix += property + ":" + prefixes[property] + " "; | ||
} | ||
} | ||
// set prefix on the main element itself | ||
if (prefix != "") { | ||
this.setAttribute("prefix", prefix); | ||
} | ||
} | ||
} | ||
}; | ||
@@ -102,3 +10,3 @@ export const SchemaBehaviors = function(SuperClass) { | ||
static get properties() { | ||
return { | ||
let props = { | ||
/** | ||
@@ -112,6 +20,7 @@ * Unique Resource ID, generated when schemaMap processes. | ||
/** | ||
* Schema Map for this element. | ||
* Schema Map for the element, used to generate a valid prefix on the fly | ||
*/ | ||
schemaMap: { | ||
type: Object, | ||
readOnly: true, | ||
value: { | ||
@@ -130,2 +39,6 @@ prefix: { | ||
}; | ||
if (super.properties) { | ||
props = Object.assign(props, super.properties); | ||
} | ||
return props; | ||
} | ||
@@ -132,0 +45,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).SchemaBehaviors={})}(this,function(e){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}window.SchemaBehaviors=window.SchemaBehaviors||{},window.SchemaBehaviors.Schema={properties:{schemaResourceID:{type:String,value:""},schemaMap:{type:Object,value:{prefix:{oer:"http://oerschema.org/",schema:"http://schema.org/",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",bib:"http://bib.schema.org"}},observer:"_schemaMapChanged"}},generateResourceID:function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return"#"+e()+e()+"-"+e()+"-"+e()+"-"+e()},_schemaMapChanged:function(e,r){if("undefined"!==t(e)){this.schemaResourceID=this.getAttribute("resource"),""!=this.schemaResourceID&&null!=this.schemaResourceID||(this.schemaResourceID=this.generateResourceID(),this.setAttribute("resource",this.schemaResourceID));var o=e.prefix,n="";for(var c in o)o.hasOwnProperty(c)&&(n+=c+":"+o[c]+" ");""!=n&&this.setAttribute("prefix",n)}}};e.SchemaBehaviors=function(e){return function(s){function i(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,i),c(this,o(i).apply(this,arguments))}var u,a,h;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&n(e,t)}(i,e),u=i,h=[{key:"properties",get:function(){return{schemaResourceID:{type:String,value:""},schemaMap:{type:Object,value:{prefix:{oer:"http://oerschema.org/",schema:"http://schema.org/",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",bib:"http://bib.schema.org"}},observer:"_schemaMapChanged"}}}}],(a=[{key:"generateResourceID",value:function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return"#"+e()+e()+"-"+e()+"-"+e()+"-"+e()}},{key:"_schemaMapChanged",value:function(e,r){if("undefined"!==t(e)){this.schemaResourceID=this.getAttribute("resource"),""!=this.schemaResourceID&&null!=this.schemaResourceID||(this.schemaResourceID=this.generateResourceID(),this.setAttribute("resource",this.schemaResourceID));var o=e.prefix,n="";for(var c in o)o.hasOwnProperty(c)&&(n+=c+":"+o[c]+" ");""!=n&&this.setAttribute("prefix",n)}}}])&&r(u.prototype,a),h&&r(u,h),i}()},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).SchemaBehaviors={})}(this,function(e){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function r(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function i(e,t,r){return(i="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,r){var n=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=o(e)););return e}(e,t);if(n){var c=Object.getOwnPropertyDescriptor(n,t);return c.get?c.get.call(r):c.value}})(e,t,r||e)}e.SchemaBehaviors=function(e){return function(u){function s(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,s),c(this,o(s).apply(this,arguments))}var f,a,p;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&n(e,t)}(s,e),f=s,p=[{key:"properties",get:function(){var e={schemaResourceID:{type:String,value:""},schemaMap:{type:Object,readOnly:!0,value:{prefix:{oer:"http://oerschema.org/",schema:"http://schema.org/",dc:"http://purl.org/dc/terms/",foaf:"http://xmlns.com/foaf/0.1/",cc:"http://creativecommons.org/ns#",bib:"http://bib.schema.org"}},observer:"_schemaMapChanged"}};return i(o(s),"properties",this)&&(e=Object.assign(e,i(o(s),"properties",this))),e}}],(a=[{key:"generateResourceID",value:function(){function e(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return"#"+e()+e()+"-"+e()+"-"+e()+"-"+e()}},{key:"_schemaMapChanged",value:function(e,r){if("undefined"!==t(e)){this.schemaResourceID=this.getAttribute("resource"),""!=this.schemaResourceID&&null!=this.schemaResourceID||(this.schemaResourceID=this.generateResourceID(),this.setAttribute("resource",this.schemaResourceID));var o=e.prefix,n="";for(var c in o)o.hasOwnProperty(c)&&(n+=c+":"+o[c]+" ");""!=n&&this.setAttribute("prefix",n)}}}])&&r(f.prototype,a),p&&r(f,p),s}()},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=schema-behaviors.umd.js.map |
@@ -5,94 +5,2 @@ /** | ||
*/ | ||
// ensure SchemaBehaviors exists | ||
window.SchemaBehaviors = window.SchemaBehaviors || {}; | ||
/** | ||
* `SchemaBehaviors` | ||
* | ||
* makes it easier to wire custom elements for | ||
* schematic metadata by allowing prefixes to be defined in an object | ||
* structure. This makes it easier to add and remove them then working | ||
* against the attribute directly. It also helps with generating | ||
* resource IDs automatically if they don't already exist on the element. | ||
* | ||
* @microcopy - language worth noting: | ||
* - | ||
* | ||
* @polymer | ||
* @polymerBehavior SchemaBehaviors.Schema | ||
*/ | ||
window.SchemaBehaviors.Schema = { | ||
properties: { | ||
/** | ||
* Unique Resource ID, generated when schemaMap processes. | ||
*/ | ||
schemaResourceID: { | ||
type: String, | ||
value: "" | ||
}, | ||
/** | ||
* Schema Map for this element. | ||
*/ | ||
schemaMap: { | ||
type: Object, | ||
value: { | ||
prefix: { | ||
oer: "http://oerschema.org/", | ||
schema: "http://schema.org/", | ||
dc: "http://purl.org/dc/terms/", | ||
foaf: "http://xmlns.com/foaf/0.1/", | ||
cc: "http://creativecommons.org/ns#", | ||
bib: "http://bib.schema.org" | ||
} | ||
}, | ||
observer: "_schemaMapChanged" | ||
} | ||
}, | ||
/** | ||
* Generate a uinque ID | ||
*/ | ||
generateResourceID: function() { | ||
function idPart() { | ||
return Math.floor((1 + Math.random()) * 0x10000) | ||
.toString(16) | ||
.substring(1); | ||
} | ||
return ( | ||
"#" + | ||
idPart() + | ||
idPart() + | ||
"-" + | ||
idPart() + | ||
"-" + | ||
idPart() + | ||
"-" + | ||
idPart() | ||
); | ||
}, | ||
/** | ||
* Notice the schema map has changed, reprocess attributes. | ||
*/ | ||
_schemaMapChanged: function(newValue, oldValue) { | ||
if (typeof newValue !== typeof undefined) { | ||
// use this to tie into schemaResourceID build | ||
this.schemaResourceID = this.getAttribute("resource"); | ||
// if it still doesn't have one then we have to check | ||
if (this.schemaResourceID == "" || this.schemaResourceID == null) { | ||
this.schemaResourceID = this.generateResourceID(); | ||
this.setAttribute("resource", this.schemaResourceID); | ||
} | ||
let prefixes = newValue.prefix; | ||
let prefix = ""; | ||
// build prefix string | ||
for (var property in prefixes) { | ||
if (prefixes.hasOwnProperty(property)) { | ||
prefix += property + ":" + prefixes[property] + " "; | ||
} | ||
} | ||
// set prefix on the main element itself | ||
if (prefix != "") { | ||
this.setAttribute("prefix", prefix); | ||
} | ||
} | ||
} | ||
}; | ||
@@ -102,3 +10,3 @@ export const SchemaBehaviors = function(SuperClass) { | ||
static get properties() { | ||
return { | ||
let props = { | ||
/** | ||
@@ -112,6 +20,7 @@ * Unique Resource ID, generated when schemaMap processes. | ||
/** | ||
* Schema Map for this element. | ||
* Schema Map for the element, used to generate a valid prefix on the fly | ||
*/ | ||
schemaMap: { | ||
type: Object, | ||
readOnly: true, | ||
value: { | ||
@@ -130,2 +39,6 @@ prefix: { | ||
}; | ||
if (super.properties) { | ||
props = Object.assign(props, super.properties); | ||
} | ||
return props; | ||
} | ||
@@ -132,0 +45,0 @@ /** |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56319
540