@pap-it/system-utils
Advanced tools
Comparing version 1.0.10 to 1.0.11
@@ -1,31 +0,1 @@ | ||
export interface QueryOption<T extends Element> { | ||
onload?: string; | ||
selector: string; | ||
load?: (element: T) => void; | ||
} | ||
type queryParam<T extends Element> = string | QueryOption<T>; | ||
export declare function query<T extends Element = HTMLElement>(options: queryParam<T>): (target: HTMLElement, propertyKey: string) => void; | ||
export interface ContextOption { | ||
name?: string; | ||
attribute?: string; | ||
applyattribute?: boolean; | ||
rerender?: boolean; | ||
verbose?: boolean; | ||
onUpdate?: string; | ||
} | ||
export declare function context(options?: ContextOption): (target: any, propertyKey: string) => void; | ||
export interface PropertyOption { | ||
type: Function; | ||
attribute: boolean | string; | ||
rerender: boolean; | ||
onUpdate?: string; | ||
context?: boolean; | ||
verbose?: boolean; | ||
set?: (value: any) => any; | ||
get?: (value: any) => any; | ||
before?: (value: any) => void; | ||
after?: (value: any, old: any) => void; | ||
} | ||
export declare function property(options?: Partial<PropertyOption>): (target: any, propertyKey: string) => void; | ||
export declare function convertFromString(value: string | null, type: Function): any; | ||
export {}; |
@@ -1,239 +0,4 @@ | ||
import { NextParent } from '../functions/helpers'; | ||
export function query(options) { | ||
const selector = typeof options === "string" ? options : options.selector; | ||
return function (target, propertyKey) { | ||
const renderattemptsKey = propertyKey + 'rerender_attempts_'; | ||
const timeoutattemptsKey = propertyKey + 'timeout_attempts_'; | ||
// Store the original connectedCallback, if it exists | ||
const originalConnectedCallback = target.connectedCallback || function () { }; | ||
// Override connectedCallback | ||
target.connectedCallback = function () { | ||
// Call the original connectedCallback | ||
originalConnectedCallback.call(this); | ||
// init the search | ||
initsearch.call(this); | ||
}; | ||
function initsearch() { | ||
if (!search.call(this)) { | ||
rendersearch.call(this); | ||
} | ||
} | ||
function rendersearch() { | ||
let attempts = this[renderattemptsKey] || 0; | ||
attempts++; | ||
if (!search.call(this) && attempts < 5) { | ||
this[timeoutattemptsKey] = 0; | ||
this[renderattemptsKey] = attempts; | ||
setTimeout(() => timeoutsearch.call(this), 100); | ||
if (this.callAfterUpdate) | ||
this.callAfterUpdate.push(() => rendersearch.call(this)); | ||
} | ||
} | ||
function timeoutsearch() { | ||
let attempts = this[timeoutattemptsKey] || 0; | ||
attempts++; | ||
if (!search.call(this) && attempts < 3) { | ||
this[timeoutattemptsKey] = attempts; | ||
setTimeout(() => timeoutsearch.call(this), 100); | ||
} | ||
} | ||
function search() { | ||
if (this[propertyKey]) | ||
return true; | ||
if (this.shadowRoot) { | ||
const element = this.shadowRoot.querySelector(selector); | ||
if (element) { | ||
this[propertyKey] = element; | ||
if (typeof options === "object") { | ||
if (options.onload && this[options.onload]) { | ||
this[options.onload].call(this, element); | ||
} | ||
if (options.load) { | ||
options.load.call(this, element); | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
}; | ||
} | ||
const DefaultContextOption = { | ||
rerender: true, | ||
verbose: false, | ||
}; | ||
export function context(options) { | ||
const _options = JSON.parse(JSON.stringify(options === undefined ? DefaultContextOption : { ...DefaultContextOption, ...options })); | ||
return function (target, propertyKey) { | ||
// assign default values | ||
if (!_options.name) | ||
_options.name = propertyKey; | ||
if (!_options.attribute) | ||
_options.attribute = propertyKey; | ||
// Storing original connectedCallback if it exists | ||
const originalConnectedCallback = target.connectedCallback; | ||
// Override the connectedCallback to set up context subscription | ||
target.connectedCallback = function () { | ||
const me = this; | ||
const contextname = _options.name + "_subcontext"; | ||
me[contextname] = true; | ||
// Call original connectedCallback if it exists | ||
if (originalConnectedCallback) | ||
originalConnectedCallback.call(me); | ||
if (_options.verbose) | ||
console.log("connected-callback", _options); | ||
let parent = NextParent(me); | ||
while (parent) { | ||
// check if parent is our selector | ||
if (_options.verbose) | ||
console.log('finding parent', parent); | ||
// NOTE we need to find the orignal parent so we need to make sure it does not have the name with "{name}_subcontext" also | ||
if (_options.name in parent && !(contextname in parent)) { | ||
break; | ||
} | ||
if (_options.attribute && parent.hasAttribute(_options.attribute) && !(contextname in parent)) { | ||
break; | ||
} | ||
if (_options.verbose) { | ||
console.log('did not find', _options.name, 'in', parent); | ||
} | ||
if (parent === document.documentElement) { | ||
parent = null; | ||
break; | ||
} | ||
parent = NextParent(parent); | ||
} | ||
if (_options.verbose) | ||
console.log('final parent', parent); | ||
if (parent) { | ||
const operation = () => { | ||
if (_options.verbose) | ||
console.log('context-update', _options.name, _options.attribute); | ||
const old = me[_options.name]; | ||
if (_options.name in parent) { | ||
me[_options.name] = parent[_options.name]; | ||
} | ||
else if (_options.attribute && parent.hasAttribute(_options.attribute)) { | ||
me[_options.name] = parent.getAttribute(_options.attribute); | ||
} | ||
if (_options.applyattribute) { | ||
if (me[_options.name] === undefined) { | ||
// TODO need to check if this would cause issues with type:boolean = true values - is value true or undefined? | ||
this.removeAttribute(_options.attribute); | ||
} | ||
else if (!(me[_options.name] instanceof Object)) { | ||
const valuestring = convertToString(me[_options.name], String); | ||
this.setAttribute(_options.attribute, valuestring); | ||
} | ||
} | ||
if (_options.onUpdate) { | ||
me[_options.onUpdate + "_attempts"] = 0; | ||
tryupdate.call(me, _options.onUpdate, me[_options.name], old, !!_options.verbose); | ||
} | ||
if (_options.rerender) { | ||
me.debouncedRequestUpdate(); | ||
} | ||
}; | ||
// init value | ||
operation(); | ||
// Subscribe to context changes | ||
parent.addEventListener(`context-${_options.name}`, operation); | ||
// if (DEV_MODE) parent.addEventListener('context-manual-change', operation); | ||
parent.addEventListener('context-manual-change-banana', operation); | ||
} | ||
else { | ||
console.warn(`Context provider for '${_options.name}' not found.`); | ||
} | ||
}; | ||
}; | ||
} | ||
const DefaultPropertyOptions = { | ||
type: String, | ||
attribute: true, | ||
rerender: true, | ||
verbose: false, | ||
}; | ||
export function property(options) { | ||
const _options = options === undefined ? DefaultPropertyOptions : { ...DefaultPropertyOptions, ...options }; | ||
return function (target, propertyKey) { | ||
const attributeName = (typeof _options.attribute === "string" ? _options.attribute : propertyKey).toLowerCase(); | ||
const constructor = target.constructor; | ||
if (!constructor.Properties) | ||
constructor.Properties = {}; | ||
constructor.Properties[attributeName] = { | ||
type: _options.type, | ||
typeName: _options.type.name, | ||
propertyKey, | ||
attribute: _options.attribute, | ||
}; | ||
// Observe attributes | ||
const observedAttributes = constructor.observedAttributes || []; | ||
observedAttributes.push(attributeName); | ||
// if (target && target.tagName === "PAP-MENU") console.log(observedAttributes) | ||
constructor.observedAttributes = observedAttributes; | ||
// Define property getter and setter | ||
Object.defineProperty(target, propertyKey, { | ||
get() { | ||
const data = this[`_${propertyKey}`]; | ||
return (options === null || options === void 0 ? void 0 : options.get) ? options.get.call(this, data) : data; | ||
}, | ||
set(value) { | ||
if (!constructor.Properties) | ||
constructor.Properties = {}; | ||
if (!constructor.Properties[attributeName]) { | ||
// if (this.tagName === 'PAP-MENU') console.log('setting propertyoptions', attributeName, this.tagName) | ||
constructor.Properties[attributeName] = { | ||
type: _options.type, | ||
typeName: _options.type.name, | ||
propertyKey, | ||
attribute: _options.attribute, | ||
}; | ||
} | ||
// if (this[attributeName + "internal"]) { | ||
// console.log('intenral udpate?') | ||
// delete this[attributeName + "internal"]; | ||
// return; | ||
// } | ||
if (options === null || options === void 0 ? void 0 : options.set) | ||
value = options.set.call(this, value); | ||
const valuestring = convertToString(value, _options.type); | ||
if (this.delayedAttributes[attributeName] && this.delayedAttributes[attributeName] === valuestring) { | ||
return; | ||
} | ||
const oldvaluestring = convertToString(this[`_${propertyKey}`], _options.type); | ||
if (oldvaluestring === valuestring) { | ||
return; | ||
} | ||
if (_options.verbose) | ||
console.log('update'); | ||
if (_options.attribute) { | ||
if (!this.delayedAttributes) | ||
this.delayedAttributes = {}; | ||
if (this.delayedAttributes[attributeName] !== valuestring) { | ||
// if (this.tagName === "PAP-INPUT") console.log("DECORATOR", attributeName) | ||
this.delayedAttributes[attributeName] = valuestring; | ||
if (this.updateAttribute) | ||
this.updateAttribute(); | ||
} | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.before) | ||
options.before.call(this, value); | ||
const old = this[`_${propertyKey}`]; | ||
this[`_${propertyKey}`] = value; | ||
if (options === null || options === void 0 ? void 0 : options.after) | ||
options.after.call(this, value, old); | ||
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); | ||
} | ||
}, | ||
}); | ||
}; | ||
} | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.convertFromString = void 0; | ||
async function tryupdate(update, value, old, verbose) { | ||
@@ -270,3 +35,3 @@ if (verbose) { | ||
} | ||
export function convertFromString(value, type) { | ||
function convertFromString(value, type) { | ||
switch (type.name) { | ||
@@ -288,2 +53,3 @@ case "Boolean": | ||
} | ||
exports.convertFromString = convertFromString; | ||
function convertToString(value, type) { | ||
@@ -290,0 +56,0 @@ switch (type.name) { |
@@ -1,4 +0,8 @@ | ||
export function ifDefined(value) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ifDefined = void 0; | ||
function ifDefined(value) { | ||
return value === undefined ? undefined : String(value); | ||
} | ||
exports.ifDefined = ifDefined; | ||
//# sourceMappingURL=directives.js.map |
@@ -1,2 +0,5 @@ | ||
export function debounce(execute, delay = 300) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.lerpValue = exports.lerp = exports.DetectDevice = exports.FormatNumber = exports.ExtractSlotValue = exports.CumulativeOffset = exports.NextParent = exports.generateUUID = exports.debounce = void 0; | ||
function debounce(execute, delay = 300) { | ||
let timer = null; | ||
@@ -13,3 +16,4 @@ return function (...args) { | ||
} | ||
export function generateUUID() { | ||
exports.debounce = debounce; | ||
function generateUUID() { | ||
let d = new Date().getTime(); | ||
@@ -25,3 +29,4 @@ if (typeof performance !== 'undefined' && typeof performance.now === 'function') { | ||
} | ||
export function NextParent(element) { | ||
exports.generateUUID = generateUUID; | ||
function NextParent(element) { | ||
if (element.parentElement) | ||
@@ -34,3 +39,4 @@ return element.parentElement; | ||
} | ||
export function CumulativeOffset(element) { | ||
exports.NextParent = NextParent; | ||
function CumulativeOffset(element) { | ||
let top = 0, left = 0; | ||
@@ -47,4 +53,5 @@ do { | ||
} | ||
exports.CumulativeOffset = CumulativeOffset; | ||
; | ||
export function ExtractSlotValue(slot) { | ||
function ExtractSlotValue(slot) { | ||
const nodes = slot.assignedNodes(); | ||
@@ -55,2 +62,3 @@ const values = []; | ||
} | ||
exports.ExtractSlotValue = ExtractSlotValue; | ||
function appendLeafValue(node, L) { | ||
@@ -66,3 +74,3 @@ if (node.hasChildNodes()) { | ||
} | ||
export function FormatNumber(num) { | ||
function FormatNumber(num) { | ||
if (Math.abs(num) < 1000) { | ||
@@ -84,3 +92,4 @@ return num.toString(); | ||
} | ||
export function DetectDevice(component) { | ||
exports.FormatNumber = FormatNumber; | ||
function DetectDevice(component) { | ||
var _a, _b, _c; | ||
@@ -110,7 +119,9 @@ if (component.classList.contains("mobile")) | ||
} | ||
exports.DetectDevice = DetectDevice; | ||
// value manipulation | ||
export function lerp(a, b, t) { | ||
function lerp(a, b, t) { | ||
return a + (b - a) * t; | ||
} | ||
export function lerpValue(value, min, max, newmin, newmax) { | ||
exports.lerp = lerp; | ||
function lerpValue(value, min, max, newmin, newmax) { | ||
// Normalize 'value' to a [0, 1] range | ||
@@ -121,2 +132,3 @@ const t = (value - min) / (max - min); | ||
} | ||
exports.lerpValue = lerpValue; | ||
//# sourceMappingURL=helpers.js.map |
@@ -0,3 +1,6 @@ | ||
"use strict"; | ||
// import { prepareElement } from './html-helper'; | ||
export function findComments(element) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ReapplyEventsDeep = exports.ReapplyEvents = exports.html = exports.findComments = void 0; | ||
function findComments(element) { | ||
let arr = []; | ||
@@ -15,2 +18,3 @@ for (let i = 0; i < element.childNodes.length; i++) { | ||
} | ||
exports.findComments = findComments; | ||
function insertElement(parent, comment, indexes, values) { | ||
@@ -32,3 +36,3 @@ if (indexes === null) | ||
} | ||
export function html(strings, ...values) { | ||
function html(strings, ...values) { | ||
let result = ""; | ||
@@ -112,3 +116,4 @@ for (let i = 0; i < values.length; i++) { | ||
} | ||
export function ReapplyEvents(element, clone) { | ||
exports.html = html; | ||
function ReapplyEvents(element, clone) { | ||
if (!clone.__eventListeners) { | ||
@@ -122,3 +127,4 @@ for (const eventname in element.__eventListeners) { | ||
} | ||
export function ReapplyEventsDeep(element, clone) { | ||
exports.ReapplyEvents = ReapplyEvents; | ||
function ReapplyEventsDeep(element, clone) { | ||
ReapplyEvents(element, clone); | ||
@@ -145,2 +151,3 @@ if (element instanceof HTMLSlotElement) { | ||
} | ||
exports.ReapplyEventsDeep = ReapplyEventsDeep; | ||
function InitEventListeners() { | ||
@@ -147,0 +154,0 @@ if (window.eventListenersBeenInitialized) |
@@ -1,5 +0,8 @@ | ||
export * from './decorators'; | ||
export * from './helpers'; | ||
export * from './html'; | ||
export * from './directives'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./decorators"), exports); | ||
tslib_1.__exportStar(require("./helpers"), exports); | ||
tslib_1.__exportStar(require("./html"), exports); | ||
tslib_1.__exportStar(require("./directives"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,2 +1,4 @@ | ||
export * from './decorators'; | ||
export * from './functions'; | ||
export * from './types'; | ||
export * from './class'; |
@@ -1,7 +0,12 @@ | ||
// classes | ||
// export * from './classes'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
// decorators | ||
tslib_1.__exportStar(require("./decorators"), exports); | ||
// funtions | ||
export * from './functions'; | ||
tslib_1.__exportStar(require("./functions"), exports); | ||
// types | ||
export * from './types'; | ||
tslib_1.__exportStar(require("./types"), exports); | ||
// classes | ||
tslib_1.__exportStar(require("./class"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,31 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// export type RenderType = DocumentFragment | string | undefined | string[] | DocumentFragment[]; | ||
// export interface CustomElement extends Omit<HTMLElement, 'style'> { | ||
// style: string[] | string; | ||
// observedAttributes: string[]; | ||
// connectedCallback?(): void; | ||
// disconnectedCallback?(): void; | ||
// attributeChangedCallback?(name: string, newValue: string | null, oldValue: string | null): void; | ||
// firstRender?(): void; | ||
// // required | ||
// render(): RenderType; | ||
// } | ||
// // Interface for the static side of the class, including static properties/methods | ||
// export interface CustomElementConstructor { | ||
// new(...args: any[]): CustomElement; // Constructor signature | ||
// style?: string[]; // Static property | ||
// } | ||
// export interface Base extends CustomElement { | ||
// connectedCallback(): void; | ||
// disconnectedCallback(): void; | ||
// attributeChangedCallback(name: string, newValue: string | null, oldValue: string | null): void; | ||
// observedAttributes(): string[]; | ||
// requestUpdate(): void; | ||
// update(): void; | ||
// getProperties(): PropertyConfig[]; | ||
// addProperty(config: PropertyConfig): void; | ||
// firstRender(): void; | ||
// render(): RenderType; | ||
// } | ||
//# sourceMappingURL=base-types.js.map |
@@ -1,4 +0,7 @@ | ||
export * from './base-types'; | ||
export * from './localisation'; | ||
export * from './theme'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./base-types"), exports); | ||
tslib_1.__exportStar(require("./localisation"), exports); | ||
tslib_1.__exportStar(require("./theme"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,3 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=localisation.js.map |
@@ -1,2 +0,3 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=theme.js.map |
{ | ||
"name": "@pap-it/system-utils", | ||
"version": "1.0.10", | ||
"version": "1.0.11", | ||
"scripts": { | ||
"init": "sh .scripts/init.sh", | ||
"build": "tsc", | ||
"build": "sh .scripts/build.sh", | ||
"start": "sh .scripts/start.sh", | ||
"watch": "tsc --watch", | ||
@@ -33,4 +34,4 @@ "manual-publish": "sh .scripts/publish.sh", | ||
"eslint": "^8.53.0", | ||
"@pap-it/system-showcase": "1.0.11", | ||
"@pap-it/typography": "1.0.11", | ||
"@pap-it/system-showcase": "1.0.18", | ||
"@pap-it/typography": "1.0.18", | ||
"typescript": "^5.0.4" | ||
@@ -37,0 +38,0 @@ }, |
@@ -5,5 +5,6 @@ # UtilsSystem | ||
Version: Version: 1.0.10 | ||
Version: Version: Version: 1.0.11 | ||
## Development | ||
@@ -10,0 +11,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
263118
96
2571
14
1