@pap-it/system-utils
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,6 +0,7 @@ | ||
export interface QueryOption<T> { | ||
export interface QueryOption<T extends Element> { | ||
onload?: string; | ||
selector: string; | ||
load?: (element: T) => void; | ||
} | ||
type queryParam<T> = string | QueryOption<T>; | ||
type queryParam<T extends Element> = string | QueryOption<T>; | ||
export declare function query<T extends Element = HTMLElement>(options: queryParam<T>): (target: HTMLElement, propertyKey: string) => void; | ||
@@ -10,2 +11,3 @@ export interface ContextOption { | ||
attribute?: string; | ||
applyattribute?: boolean; | ||
rerender?: boolean; | ||
@@ -16,5 +18,2 @@ verbose?: boolean; | ||
export declare function context(options?: ContextOption): (target: any, propertyKey: string) => void; | ||
export declare enum Spread { | ||
BREAKOUT = 1 | ||
} | ||
export interface PropertyOption { | ||
@@ -27,7 +26,8 @@ type: Function; | ||
verbose?: boolean; | ||
spread?: string | Spread | 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: HTMLElement, propertyKey: string) => void; | ||
export {}; |
@@ -47,6 +47,9 @@ import { NextParent } from '../functions/helpers'; | ||
this[propertyKey] = element; | ||
if (typeof options === "object" && options.onload) { | ||
if (this[options.onload]) { | ||
if (typeof options === "object") { | ||
if (options.onload && this[options.onload]) { | ||
this[options.onload].call(this, element); | ||
} | ||
if (options.load) { | ||
options.load.call(this, element); | ||
} | ||
} | ||
@@ -77,2 +80,4 @@ return true; | ||
const me = this; | ||
const contextname = _options.name + "_subcontext"; | ||
me[contextname] = true; | ||
// Call original connectedCallback if it exists | ||
@@ -88,6 +93,7 @@ if (originalConnectedCallback) | ||
console.log('finding parent', parent); | ||
if (_options.name in 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)) { | ||
if (_options.attribute && parent.hasAttribute(_options.attribute) && !(contextname in parent)) { | ||
break; | ||
@@ -117,2 +123,12 @@ } | ||
} | ||
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) { | ||
@@ -139,7 +155,2 @@ me[_options.onUpdate + "_attempts"] = 0; | ||
} | ||
// property.ts | ||
export var Spread; | ||
(function (Spread) { | ||
Spread[Spread["BREAKOUT"] = 1] = "BREAKOUT"; | ||
})(Spread || (Spread = {})); | ||
const DefaultPropertyOptions = { | ||
@@ -155,3 +166,3 @@ type: String, | ||
const attributeName = (typeof _options.attribute === "string" ? _options.attribute : propertyKey).toLowerCase(); | ||
const spreadAttributeNames = {}; | ||
// const spreadAttributeNames: Record<string, boolean> = {}; | ||
let internal = false; | ||
@@ -163,13 +174,17 @@ // Observe attributes | ||
// 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[propertyKey]); | ||
spreadAttributes(_options.spread === Spread.BREAKOUT ? "" : typeof _options.spread === "string" ? _options.spread : attributeName, target.constructor[propertyKey], (name) => { | ||
console.log('adding spread', name); | ||
observedAttributes.push(name); | ||
spreadAttributeNames[name] = true; | ||
}); | ||
} | ||
else { | ||
observedAttributes.push(attributeName); | ||
} | ||
// 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 { | ||
observedAttributes.push(attributeName); | ||
// } | ||
target.constructor.observedAttributes = observedAttributes; | ||
@@ -181,23 +196,24 @@ // Handle attributeChangedCallback | ||
attributeChanged.call(this, name, oldValue, newValue); | ||
if ((name === attributeName || spreadAttributeNames[name]) && !internal && newValue !== oldValue) { | ||
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 (_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); | ||
// } | ||
} | ||
@@ -209,5 +225,7 @@ }; | ||
const data = this[`_${propertyKey}`]; | ||
return (options === null || options === void 0 ? void 0 : options.get) ? options.get(data) : data; | ||
return (options === null || options === void 0 ? void 0 : options.get) ? options.get.call(this, data) : data; | ||
}, | ||
set(value) { | ||
if (options === null || options === void 0 ? void 0 : options.set) | ||
value = options.set.call(this, value); | ||
const valuestring = convertToString(value, _options.type); | ||
@@ -218,12 +236,16 @@ const oldvaluestring = convertToString(this[`_${propertyKey}`], _options.type); | ||
} | ||
if (options === null || options === void 0 ? void 0 : options.before) | ||
options.before.call(this, value); | ||
const old = this[`_${propertyKey}`]; | ||
this[`_${propertyKey}`] = (options === null || options === void 0 ? void 0 : options.set) ? options.set(value) : value; | ||
this[`_${propertyKey}`] = value; | ||
if (options === null || options === void 0 ? void 0 : options.after) | ||
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.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; | ||
@@ -319,19 +341,19 @@ if (value === undefined) { | ||
} | ||
function spreadAttributes(parentKey, object, callback) { | ||
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); | ||
} | ||
} | ||
} | ||
// 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 |
@@ -11,4 +11,2 @@ import { Devices } from "../types"; | ||
export declare function FormatNumber(num: number): string; | ||
export declare function DetectLanguage(): string | undefined; | ||
export declare function SetLanguage(language?: string): void; | ||
export declare function DetectDevice(component: HTMLElement): Devices; |
@@ -78,34 +78,2 @@ export function debounce(execute, delay = 300) { | ||
} | ||
export function DetectLanguage() { | ||
var _a, _b; | ||
if (window.papLocalisation) { | ||
if (window.papLocalisation.lang) { | ||
return window.papLocalisation.lang; | ||
} | ||
if ((_a = window.papLocalisation.settings) === null || _a === void 0 ? void 0 : _a.url) { | ||
const langmatch = window.location.pathname.match(/\/([^\/]*)\//); | ||
if (langmatch) { | ||
return langmatch[1]; | ||
} | ||
} | ||
} | ||
const head_lang = document.head.getAttribute("lang"); | ||
if (head_lang) { | ||
return head_lang; | ||
} | ||
const meta_lang = (_b = document.head.querySelector('meta[http-equiv="Content-Language"]')) === null || _b === void 0 ? void 0 : _b.getAttribute("content"); | ||
if (meta_lang) { | ||
return meta_lang; | ||
} | ||
const navigator_lang = navigator.language; | ||
if (navigator_lang) { | ||
return navigator_lang; | ||
} | ||
} | ||
export function SetLanguage(language) { | ||
if (language) { | ||
window.papLocalisation.lang = language; | ||
} | ||
const lang = DetectLanguage(); | ||
} | ||
export function DetectDevice(component) { | ||
@@ -112,0 +80,0 @@ var _a, _b, _c; |
export * from './base-types'; | ||
export * from './localisation'; | ||
export * from './theme'; |
export * from './base-types'; | ||
export * from './localisation'; | ||
export * from './theme'; | ||
//# sourceMappingURL=index.js.map |
@@ -1,28 +0,46 @@ | ||
export type TranslationObject = Record<string, string>; | ||
export type EventCallback = (event: Event) => void; | ||
export interface LanguageSet { | ||
type Meta = { | ||
region: string; | ||
language: string; | ||
}; | ||
type TranslationObject = { | ||
meta?: Meta; | ||
} & Record<string, string>; | ||
export interface BasicLanguageData { | ||
id: string; | ||
name: string; | ||
url?: string; | ||
meta?: Meta; | ||
translations?: TranslationObject; | ||
} | ||
export type EnhancedLanguageData = BasicLanguageData & { | ||
meta: Meta; | ||
translations?: TranslationObject; | ||
}; | ||
export type LanguageData = BasicLanguageData & { | ||
meta: Meta; | ||
translations: TranslationObject; | ||
} | ||
export interface Translation { | ||
}; | ||
export interface Localization { | ||
subscribe(callback: EventCallback): void; | ||
unsubscribe(callback: EventCallback): void; | ||
load(set: LanguageSet): void; | ||
loadAll(array: LanguageSet[]): void; | ||
change(lang: string): void; | ||
map: Map<string, LanguageSet>; | ||
current: LanguageSet; | ||
load(set: BasicLanguageData): void; | ||
/** | ||
* Changes the current language to the specified language. | ||
* @param {string} lang - The language code to switch to. | ||
* @return {Promise<boolean>} Indicates if the change was successful or not. | ||
*/ | ||
change(lang: string): Promise<boolean>; | ||
add(set: BasicLanguageData): void; | ||
addAll(array: BasicLanguageData[]): void; | ||
detect(): string | undefined; | ||
intl?: Intl.DisplayNames; | ||
map: Map<string, EnhancedLanguageData>; | ||
current: LanguageData; | ||
setURL: boolean; | ||
} | ||
export interface Localisation { | ||
settings?: { | ||
url?: boolean; | ||
}; | ||
lang: string; | ||
} | ||
declare global { | ||
interface Window { | ||
papTranslation: Translation; | ||
papLocalisation: Localisation; | ||
papLocalization: Localization; | ||
} | ||
} | ||
export {}; |
{ | ||
"name": "@pap-it/system-utils", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"scripts": { | ||
@@ -9,2 +9,3 @@ "init": "sh .scripts/init.sh", | ||
"manual-publish": "sh .scripts/publish.sh", | ||
"preversion": "sh .scripts/preversion.sh", | ||
"postversion": "sh .scripts/postversion.sh" | ||
@@ -15,3 +16,4 @@ }, | ||
"asset/", | ||
"dist/" | ||
"dist/", | ||
"react/" | ||
], | ||
@@ -34,4 +36,4 @@ "exports": { | ||
"eslint": "^8.53.0", | ||
"@pap-it/system-showcase": "1.0.4", | ||
"@pap-it/typography": "1.0.4", | ||
"@pap-it/system-showcase": "1.0.5", | ||
"@pap-it/typography": "1.0.5", | ||
"typescript": "^5.0.4" | ||
@@ -38,0 +40,0 @@ }, |
@@ -5,3 +5,3 @@ # UtilsSystem | ||
Version: 1.1.0 | ||
Version: 1.0.5 | ||
@@ -8,0 +8,0 @@ ## Development |
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
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
94665
33
783