@pap-it/system-utils
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -30,2 +30,3 @@ export interface QueryOption<T extends Element> { | ||
export declare function property(options?: Partial<PropertyOption>): (target: HTMLElement, propertyKey: string) => void; | ||
export declare function convertFromString(value: string | null, type: Function): any; | ||
export {}; |
@@ -161,54 +161,15 @@ import { NextParent } from '../functions/helpers'; | ||
const attributeName = (typeof _options.attribute === "string" ? _options.attribute : propertyKey).toLowerCase(); | ||
// const spreadAttributeNames: Record<string, boolean> = {}; | ||
let internal = false; | ||
const constructor = target.constructor; | ||
if (!constructor.__propertyOptions) | ||
constructor.__propertyOptions = {}; | ||
// if (constructor.tagName === 'PAP-MENU') console.log('setting propertyoptions', attributeName, constructor.tagName) | ||
constructor.__propertyOptions[attributeName] = { | ||
type: _options.type, | ||
propertyKey, | ||
}; | ||
// Observe attributes | ||
const observedAttributes = target.constructor.observedAttributes || []; | ||
// NOTE spread is not working, at this point the objedct havent been defined yet, | ||
// we need to keep track if we defined this and in the setter we should do this work | ||
// if not done already - so keep track if we did this setup (setup being to add to 'observedAttributes') | ||
// if (_options.spread) { | ||
// console.log('spread yes!', (target.constructor as any)[propertyKey]) | ||
// spreadAttributes( | ||
// _options.spread === Spread.BREAKOUT ? "" : typeof _options.spread === "string" ? _options.spread : attributeName, | ||
// (target.constructor as any)[propertyKey], | ||
// (name) => { | ||
// console.log('adding spread', name) | ||
// observedAttributes.push(name); | ||
// spreadAttributeNames[name] = true; | ||
// } | ||
// ) | ||
// } | ||
// else { | ||
const observedAttributes = constructor.observedAttributes || []; | ||
observedAttributes.push(attributeName); | ||
// } | ||
target.constructor.observedAttributes = observedAttributes; | ||
// Handle attributeChangedCallback | ||
const attributeChanged = target.attributeChangedCallback || function () { }; | ||
target.attributeChangedCallback = function (name, oldValue, newValue) { | ||
// how many times is the same code going to be called? | ||
attributeChanged.call(this, name, oldValue, newValue); | ||
if (name === attributeName && !internal && newValue !== oldValue) { | ||
// if ((name === attributeName || spreadAttributeNames[name]) && !internal && newValue !== oldValue) { | ||
if (_options.verbose) | ||
console.log('attribute is set', attributeName); | ||
// NOTE spread is not working, perhaps with the attribute changes updated this part should work | ||
// if (_options.spread) { | ||
// const keys = name.split("-"); | ||
// let newobject = this[propertyKey]; | ||
// let target = newobject; | ||
// for (let i = 0; i < keys.length; i++) { | ||
// if (i !== keys.length - 1) { | ||
// target = target[keys[i]]; | ||
// } | ||
// else { | ||
// target[keys[i]] = convertFromStringPrimitive(newValue); | ||
// } | ||
// } | ||
// this[propertyKey] = newobject; | ||
// } | ||
// else { | ||
this[propertyKey] = convertFromString(newValue, _options.type); | ||
// } | ||
} | ||
}; | ||
// if (target && target.tagName === "PAP-MENU") console.log(observedAttributes) | ||
constructor.observedAttributes = observedAttributes; | ||
// Define property getter and setter | ||
@@ -221,2 +182,15 @@ Object.defineProperty(target, propertyKey, { | ||
set(value) { | ||
if (!constructor.__propertyOptions) | ||
constructor.__propertyOptions = {}; | ||
if (!constructor.__propertyOptions[attributeName]) { | ||
// if (this.tagName === 'PAP-MENU') console.log('setting propertyoptions', attributeName, this.tagName) | ||
constructor.__propertyOptions[attributeName] = { | ||
type: _options.type, | ||
propertyKey, | ||
}; | ||
} | ||
if (this[attributeName + "internal"]) { | ||
delete this[attributeName + "internal"]; | ||
return; | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.set) | ||
@@ -229,2 +203,11 @@ value = options.set.call(this, value); | ||
} | ||
if (_options.verbose) | ||
console.log('update'); | ||
if (_options.attribute) { | ||
if (!this.delayedAttributes) | ||
this.delayedAttributes = {}; | ||
this.delayedAttributes[attributeName] = valuestring; | ||
if (this.updateAttribute) | ||
this.updateAttribute(); | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.before) | ||
@@ -236,38 +219,11 @@ options.before.call(this, value); | ||
options.after.call(this, value, old); | ||
const operation = () => { | ||
// we want to use spread over attribute (I guess?) | ||
// if (_options.spread) { | ||
// if (_options.verbose) console.log('property is set, setting attribute', attributeName); | ||
// // NOTE for spread we need to assign each attribute | ||
// } | ||
// else if (_options.attribute) { | ||
if (_options.attribute) { | ||
internal = true; | ||
if (value === undefined) { | ||
// TODO need to check if this would cause issues with type:boolean = true values - is value true or undefined? | ||
this.removeAttribute(attributeName); | ||
} | ||
else { | ||
this.setAttribute(attributeName, valuestring); | ||
} | ||
internal = false; | ||
} | ||
if (_options.onUpdate) { | ||
this[_options.onUpdate + "_attempts"] = 0; | ||
tryupdate.call(this, _options.onUpdate, value, old, !!_options.verbose); | ||
} | ||
if (_options.rerender) { | ||
this.debouncedRequestUpdate(); | ||
} | ||
if (_options.verbose) | ||
console.log('update'); | ||
if (_options.context) { | ||
this.dispatchEvent(new Event(`context-${propertyKey}`)); | ||
} | ||
}; | ||
if (!this.connected) { | ||
this._pendingOperations.push(operation); | ||
return; | ||
if (_options.rerender) | ||
this.debouncedRequestUpdate(); | ||
if (_options.context) | ||
this.dispatchEvent(new Event(`context-${propertyKey}`)); | ||
// FIXME delete legacy function | ||
if (_options.onUpdate) { | ||
this[_options.onUpdate + "_attempts"] = 0; | ||
tryupdate.call(this, _options.onUpdate, value, old, !!_options.verbose); | ||
} | ||
operation(); | ||
}, | ||
@@ -287,5 +243,4 @@ }); | ||
let ans = 10; | ||
if (this[update]) { | ||
if (this[update]) | ||
ans = await this[update](value, old); | ||
} | ||
if (typeof ans === "number") { | ||
@@ -310,3 +265,3 @@ if (this[update + "_attempts"] < ans) { | ||
} | ||
function convertFromString(value, type) { | ||
export function convertFromString(value, type) { | ||
switch (type.name) { | ||
@@ -337,19 +292,2 @@ case "Boolean": | ||
} | ||
// function spreadAttributes(parentKey: string, object: Record<string, any>, callback: (name: string) => void) { | ||
// console.log('spread object?', object) | ||
// for (let key in object) { | ||
// console.log('spead jey', key) | ||
// let nextname = parentKey === "" ? key : `${parentKey}-${key}`; | ||
// if (object[key] instanceof Array) { | ||
// // like wtf.. | ||
// throw new Error("[LAZY] since I dont know yet what case this could be I will throw a error until I meet it and fix it then... your're welcome future Henry!"); | ||
// } | ||
// else if (object[key] instanceof Object) { | ||
// spreadAttributes(nextname, object[key], callback); | ||
// } | ||
// else { | ||
// callback(nextname); | ||
// } | ||
// } | ||
// } | ||
//# sourceMappingURL=decorators.js.map |
{ | ||
"name": "@pap-it/system-utils", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"scripts": { | ||
@@ -34,4 +34,4 @@ "init": "sh .scripts/init.sh", | ||
"eslint": "^8.53.0", | ||
"@pap-it/system-showcase": "1.0.8", | ||
"@pap-it/typography": "1.0.8", | ||
"@pap-it/system-showcase": "1.0.9", | ||
"@pap-it/typography": "1.0.9", | ||
"typescript": "^5.0.4" | ||
@@ -38,0 +38,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
87959
722