@rhtml/custom-attributes 0.0.112 → 0.0.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,313 +1,23 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CustomAttributeRegistry = exports.MediaQueryAttribute = exports.createFiltersFromSelector = exports.Breakpoints = exports.MediaMatchers = exports.Attribute = exports.Directive = exports.CustomAttribute = exports.Modifier = exports.Input = void 0;
4
- const noop = function () {
5
- /* */
6
- };
7
- const observe = (target, memberName) => {
8
- const prototype = target.constructor.prototype;
9
- const OnInit = prototype.OnInit || noop;
10
- const OnDestroy = prototype.OnDestroy || noop;
11
- const OnUpdateAttribute = prototype.OnUpdateAttribute || noop;
12
- let observer;
13
- prototype.OnInit = function () {
14
- var _a;
15
- const element = (_a = this.element) !== null && _a !== void 0 ? _a : this;
16
- if (observer) {
17
- observer.disconnect();
18
- }
19
- observer = new MutationObserver(() => {
20
- OnUpdateAttribute.call(this, memberName, element.getAttribute(memberName));
21
- target[memberName] = element.getAttribute(memberName);
22
- });
23
- observer.observe(element, {
24
- attributeFilter: [memberName],
25
- attributes: true
26
- });
27
- return OnInit.call(this);
28
- };
29
- prototype.OnDestroy = function () {
30
- observer.disconnect();
31
- return OnDestroy.call(this);
32
- };
33
- };
34
- /**
35
- * Decorator @Input
36
- * Used to get attribute from element
37
- */
38
- exports.Input = (options) => (target, memberName) => {
39
- const OnInit = target.OnInit || noop;
40
- Object.defineProperty(target, 'OnInit', {
41
- value() {
42
- var _a;
43
- let originalValue = this[memberName];
44
- const element = (_a = this.element) !== null && _a !== void 0 ? _a : this;
45
- Object.defineProperty(this, memberName, {
46
- get: function () {
47
- originalValue = element.getAttribute(memberName.toLowerCase());
48
- return originalValue;
49
- },
50
- set(value) {
51
- element.setAttribute(memberName.toLowerCase(), value);
52
- originalValue = value;
53
- },
54
- configurable: true
55
- });
56
- return OnInit.call(this);
57
- },
58
- configurable: true
59
- });
60
- if (options === null || options === void 0 ? void 0 : options.observe) {
61
- observe(target, memberName);
62
- }
63
- };
64
- /**
65
- * Decorator @Modifier
66
- * Accepts parameter options with selector and registry
67
- */
68
- exports.Modifier = (options) => {
69
- return (target) => {
70
- target['options'] = options;
71
- };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
72
15
  };
73
- /**
74
- * Decorator @CustomAttribute
75
- * Accepts parameter options with selector and registry
76
- */
77
- exports.CustomAttribute = exports.Modifier;
78
- /**
79
- * Decorator @Directive
80
- * Accepts parameter options with selector and registry
81
- */
82
- exports.Directive = exports.Modifier;
83
- /* */
84
- class Attribute {
85
- setStyles(keys) {
86
- return (div) => {
87
- for (const [key, value] of Object.entries(keys)) {
88
- div['style'][key] = value;
89
- }
90
- };
91
- }
92
- OnInit() {
93
- /* */
94
- }
95
- OnDestroy() {
96
- /* */
97
- }
98
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
99
- OnUpdate(_oldValue, _newValue) {
100
- /* */
101
- }
102
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
103
- OnUpdateAttribute(_name, _value) {
104
- /* */
105
- }
106
- }
107
- exports.Attribute = Attribute;
108
- /**
109
- * Media query Attribute
110
- * for performance reasons it is key value pair
111
- */
112
- exports.MediaMatchers = new Map([
113
- ['screen and (max-width: 599px)', 'xs'],
114
- ['screen and (min-width: 600px) and (max-width: 959px)', 'sm'],
115
- ['screen and (min-width: 960px) and (max-width: 1279px)', 'md'],
116
- ['screen and (min-width: 1280px) and (max-width: 1919px)', 'lg'],
117
- ['screen and (min-width: 1920px) and (max-width: 5000px)', 'xl'],
118
- ['screen and (max-width: 959px)', 'lt-md'],
119
- ['screen and (max-width: 1279px)', 'lt-lg'],
120
- ['screen and (max-width: 1919px)', 'lt-xl'],
121
- ['screen and (min-width: 600px)', 'gt-xs'],
122
- ['screen and (min-width: 960px)', 'gt-sm'],
123
- ['screen and (min-width: 1280px)', 'gt-md'],
124
- ['screen and (min-width: 1920px)', 'gt-lg']
125
- ]);
126
- exports.Breakpoints = [...exports.MediaMatchers.values()];
127
- exports.createFiltersFromSelector = (selector) => [
128
- ...exports.Breakpoints.map(breakpoint => `${selector}.${breakpoint}`),
129
- selector
130
- ];
131
- class MediaQueryAttribute extends Attribute {
132
- constructor() {
133
- super(...arguments);
134
- this.matchers = new Map();
135
- this.cachedAttributes = new Map();
136
- this.listener = (event) => {
137
- const key = `${this.selector.toLowerCase()}.${exports.MediaMatchers.get(event.media)}`;
138
- const attribute = this.cachedAttributes.get(key);
139
- if (event.matches && attribute) {
140
- return this.OnEnterMediaQuery([event, attribute]);
141
- }
142
- return this.OnExitMediaQuery([event, key]);
143
- };
144
- }
145
- OnInit() {
146
- if (this.OnEnterMediaQuery || this.OnExitMediaQuery) {
147
- this.originalValue = this.value;
148
- for (const query of exports.MediaMatchers.keys()) {
149
- const matcher = window.matchMedia(query);
150
- const attr = Object.values(this.element.attributes).find(v => v.name ===
151
- `${this.selector.toLowerCase()}.${exports.MediaMatchers.get(query)}`);
152
- if (attr) {
153
- this.cachedAttributes.set(attr.name, attr);
154
- matcher.addEventListener('change', this.listener);
155
- }
156
- if (attr && matcher.matches) {
157
- this.listener(matcher);
158
- }
159
- this.matchers.set(matcher, matcher);
160
- }
161
- }
162
- }
163
- OnDestroy() {
164
- for (const matcher of this.matchers.values()) {
165
- matcher.removeEventListener('change', this.listener);
166
- }
167
- this.cachedAttributes.clear();
168
- this.matchers.clear();
169
- }
170
- }
171
- exports.MediaQueryAttribute = MediaQueryAttribute;
172
- /* Media query Attribute END */
173
- class CustomAttributeRegistry {
174
- constructor(parent) {
175
- this.parent = parent;
176
- this._attrMap = new Map();
177
- this._elementMap = new Map();
178
- if (!parent) {
179
- throw new Error('Must be given a parent element');
180
- }
181
- this.observe();
182
- }
183
- define(attrName, Constructor) {
184
- this._attrMap.set(attrName.toLowerCase(), Constructor);
185
- this.upgradeAttribute(attrName);
186
- }
187
- get(element, attrName) {
188
- const map = this._elementMap.get(element);
189
- if (!map)
190
- return;
191
- return map.get(attrName.toLowerCase());
192
- }
193
- getConstructor(attrName) {
194
- return this._attrMap.get(attrName.toLowerCase());
195
- }
196
- observe() {
197
- var _a, _b;
198
- this.observer = new MutationObserver(mutations => {
199
- for (const mutation of mutations) {
200
- if (mutation.type === 'attributes') {
201
- const attr = this.getConstructor(mutation.attributeName);
202
- if (attr) {
203
- this.found(mutation.attributeName, mutation.target, mutation.oldValue);
204
- }
205
- }
206
- else {
207
- for (const node of mutation.removedNodes) {
208
- this.downgrade(node);
209
- }
210
- for (const node of mutation.addedNodes) {
211
- this.upgradeElement(node);
212
- }
213
- }
214
- }
215
- });
216
- this.observer.observe((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a['shadowRoot']) !== null && _b !== void 0 ? _b : this.parent, {
217
- childList: true,
218
- subtree: true,
219
- attributes: true,
220
- attributeOldValue: true
221
- });
222
- }
223
- unsubscribe() {
224
- var _a;
225
- (_a = this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
226
- const values = [...this._elementMap.values()];
227
- for (const elModifiers of values) {
228
- const modifiers = [...elModifiers.values()];
229
- for (const modifier of modifiers) {
230
- modifier.OnDestroy();
231
- }
232
- elModifiers.clear();
233
- }
234
- this._elementMap.clear();
235
- }
236
- upgradeAttribute(attrName, doc) {
237
- const parent = doc || this.parent;
238
- const matches = parent.querySelectorAll('[' + attrName + ']');
239
- for (const match of [...matches]) {
240
- this.found(attrName, match);
241
- }
242
- }
243
- upgradeElement(element) {
244
- if (element.nodeType !== 1) {
245
- return;
246
- }
247
- for (const attr of element.attributes) {
248
- if (this.getConstructor(attr.name)) {
249
- this.found(attr.name, element);
250
- }
251
- }
252
- for (const [attr] of this._attrMap) {
253
- this.upgradeAttribute(attr, element);
254
- }
255
- }
256
- downgrade(element) {
257
- const map = this._elementMap.get(element);
258
- if (!map) {
259
- return;
260
- }
261
- for (const [, instance] of map) {
262
- if (instance.OnDestroy) {
263
- instance.OnDestroy();
264
- }
265
- }
266
- this._elementMap.delete(element);
267
- }
268
- found(attributeName, el, oldVal) {
269
- var _a, _b;
270
- let map = this._elementMap.get(el);
271
- if (!map) {
272
- map = new Map();
273
- this._elementMap.set(el, map);
274
- }
275
- const modifier = map.get(attributeName);
276
- const attribute = el.getAttribute(attributeName);
277
- if (!modifier) {
278
- const Modifier = this.getConstructor(attributeName);
279
- const modifier = new Modifier();
280
- if ((_b = (_a = Modifier.options) === null || _a === void 0 ? void 0 : _a.observedAttributes) === null || _b === void 0 ? void 0 : _b.length) {
281
- for (const observedAttribute of Modifier.options.observedAttributes) {
282
- observe(modifier, observedAttribute);
283
- }
284
- }
285
- map.set(attributeName, modifier);
286
- modifier.element = el;
287
- modifier.selector = attributeName;
288
- modifier.value = attribute || modifier.value;
289
- modifier.parent = this.parent;
290
- if (modifier.OnInit) {
291
- modifier.OnInit();
292
- }
293
- return;
294
- }
295
- if (attribute == null && !!modifier.value) {
296
- modifier.value = attribute;
297
- if (modifier.OnDestroy) {
298
- modifier.OnDestroy();
299
- }
300
- map.delete(attributeName);
301
- return;
302
- }
303
- if (attribute !== modifier.value) {
304
- modifier.value = attribute;
305
- if (modifier.OnUpdate) {
306
- modifier.OnUpdate(oldVal, attribute);
307
- }
308
- return;
309
- }
310
- }
311
- }
312
- exports.CustomAttributeRegistry = CustomAttributeRegistry;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./attribute"), exports);
18
+ __exportStar(require("./custom-registry"), exports);
19
+ __exportStar(require("./decorators"), exports);
20
+ __exportStar(require("./helpers"), exports);
21
+ __exportStar(require("./media-attribute"), exports);
22
+ __exportStar(require("./types"), exports);
313
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAMA,MAAM,IAAI,GAAG;IACX,MAAM;AACR,CAAC,CAAC;AAeF,MAAM,OAAO,GAAG,CAAC,MAAe,EAAE,UAAkB,EAAE,EAAE;IACtD,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC;IAC/C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,IAAI,IAAI,CAAC;IACxC,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,IAAI,IAAI,CAAC;IAC9C,MAAM,iBAAiB,GAAG,SAAS,CAAC,iBAAiB,IAAI,IAAI,CAAC;IAE9D,IAAI,QAA0B,CAAC;IAC/B,SAAS,CAAC,MAAM,GAAG;;QACjB,MAAM,OAAO,SAAG,IAAI,CAAC,OAAO,mCAAI,IAAI,CAAC;QACrC,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,UAAU,EAAE,CAAC;SACvB;QACD,QAAQ,GAAG,IAAI,gBAAgB,CAAC,GAAG,EAAE;YACnC,iBAAiB,CAAC,IAAI,CACpB,IAAI,EACJ,UAAU,EACV,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CACjC,CAAC;YACF,MAAM,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE;YACxB,eAAe,EAAE,CAAC,UAAU,CAAC;YAC7B,UAAU,EAAE,IAAI;SACjB,CAAC,CA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A0B;AAC1B,oDAAkC;AAClC,0CAAwB"}
@@ -0,0 +1,23 @@
1
+ import { Attribute } from './attribute';
2
+ /**
3
+ * Media query Attribute
4
+ * for performance reasons it is key value pair
5
+ */
6
+ export declare const MediaMatchers: Map<string, string>;
7
+ export declare type MediaEvent = MediaQueryList | MediaQueryListEvent;
8
+ export declare type MediaQueryEvent = [MediaEvent, Attr];
9
+ export interface OnUpdateMediaQuery {
10
+ OnEnterMediaQuery(tuple: MediaQueryEvent): void;
11
+ OnExitMediaQuery(tuple: MediaQueryEvent): void;
12
+ }
13
+ export declare const Breakpoints: string[];
14
+ export declare const createFiltersFromSelector: (selector: string) => string[];
15
+ export declare abstract class MediaQueryAttribute<T> extends Attribute<T> implements OnUpdateMediaQuery {
16
+ private matchers;
17
+ private cachedAttributes;
18
+ listener: (event: MediaQueryList | MediaQueryListEvent) => void;
19
+ OnInit(): void;
20
+ OnDestroy(): void;
21
+ abstract OnEnterMediaQuery(tuple: MediaQueryEvent): void;
22
+ abstract OnExitMediaQuery(tuple: MediaQueryEvent): void;
23
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediaQueryAttribute = exports.createFiltersFromSelector = exports.Breakpoints = exports.MediaMatchers = void 0;
4
+ const attribute_1 = require("./attribute");
5
+ /**
6
+ * Media query Attribute
7
+ * for performance reasons it is key value pair
8
+ */
9
+ exports.MediaMatchers = new Map([
10
+ ['screen and (max-width: 599px)', 'xs'],
11
+ ['screen and (min-width: 600px) and (max-width: 959px)', 'sm'],
12
+ ['screen and (min-width: 960px) and (max-width: 1279px)', 'md'],
13
+ ['screen and (min-width: 1280px) and (max-width: 1919px)', 'lg'],
14
+ ['screen and (min-width: 1920px) and (max-width: 5000px)', 'xl'],
15
+ ['screen and (max-width: 959px)', 'lt-md'],
16
+ ['screen and (max-width: 1279px)', 'lt-lg'],
17
+ ['screen and (max-width: 1919px)', 'lt-xl'],
18
+ ['screen and (min-width: 600px)', 'gt-xs'],
19
+ ['screen and (min-width: 960px)', 'gt-sm'],
20
+ ['screen and (min-width: 1280px)', 'gt-md'],
21
+ ['screen and (min-width: 1920px)', 'gt-lg'],
22
+ ]);
23
+ exports.Breakpoints = [...exports.MediaMatchers.values()];
24
+ const createFiltersFromSelector = (selector) => [
25
+ ...exports.Breakpoints.map((breakpoint) => `${selector}.${breakpoint}`),
26
+ selector,
27
+ ];
28
+ exports.createFiltersFromSelector = createFiltersFromSelector;
29
+ class MediaQueryAttribute extends attribute_1.Attribute {
30
+ constructor() {
31
+ super(...arguments);
32
+ this.matchers = new Map();
33
+ this.cachedAttributes = new Map();
34
+ this.listener = (event) => {
35
+ const key = `${this.selector.toLowerCase()}.${exports.MediaMatchers.get(event.media)}`;
36
+ const attribute = this.cachedAttributes.get(key);
37
+ if (event.matches && attribute) {
38
+ return this.OnEnterMediaQuery([event, attribute]);
39
+ }
40
+ return this.OnExitMediaQuery([event, attribute]);
41
+ };
42
+ }
43
+ OnInit() {
44
+ if (this.OnEnterMediaQuery || this.OnExitMediaQuery) {
45
+ for (const query of exports.MediaMatchers.keys()) {
46
+ const matcher = window.matchMedia(query);
47
+ const attr = Object.values(this.element.attributes).find((v) => v.name ===
48
+ `${this.selector.toLowerCase()}.${exports.MediaMatchers.get(query)}`);
49
+ if (attr) {
50
+ this.cachedAttributes.set(attr.name, attr);
51
+ matcher.addEventListener('change', this.listener);
52
+ }
53
+ if (attr && matcher.matches) {
54
+ this.listener(matcher);
55
+ }
56
+ this.matchers.set(matcher, matcher);
57
+ }
58
+ }
59
+ }
60
+ OnDestroy() {
61
+ for (const matcher of this.matchers.values()) {
62
+ matcher.removeEventListener('change', this.listener);
63
+ }
64
+ this.cachedAttributes.clear();
65
+ this.matchers.clear();
66
+ }
67
+ }
68
+ exports.MediaQueryAttribute = MediaQueryAttribute;
69
+ //# sourceMappingURL=media-attribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media-attribute.js","sourceRoot":"","sources":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AC,MAAM,EAAE,EAAE;YAC5C,OAAO,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;SACtD;QACD,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CAIF;AArDD,kDAqDC"}
@@ -0,0 +1,30 @@
1
+ import { CustomAttributeRegistry } from './custom-registry';
2
+ export declare type C<T> = new (...args: never[]) => T;
3
+ export interface Constructor<T> extends C<T> {
4
+ options: ModifierOptions;
5
+ }
6
+ export interface ModifierOptions {
7
+ /**
8
+ * Main selector of the attribute
9
+ */
10
+ selector: string;
11
+ /**
12
+ * Define custom attribute registry
13
+ */
14
+ registry?(this: HTMLElement): CustomAttributeRegistry;
15
+ /**
16
+ * Specify attributes to be listened
17
+ */
18
+ observedAttributes?: string[];
19
+ /**
20
+ * Define MutationObserver to listen for parent element changes
21
+ * Defining property will attach observer to this.element
22
+ * */
23
+ observe?: MutationObserverInit;
24
+ }
25
+ export interface InputOptions {
26
+ /**
27
+ * If enabled will trigger OnUpdate method on the Attribute
28
+ * */
29
+ observe: true;
30
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhtml/custom-attributes",
3
- "version": "0.0.112",
3
+ "version": "0.0.115",
4
4
  "description": "Custom Attribute Registry",
5
5
  "scripts": {
6
6
  "start": "npx parcel ./examples/index.html --out-dir build/examples",
@@ -16,16 +16,7 @@
16
16
  "url": "git@github.com:rhtml/rhtml.git"
17
17
  },
18
18
  "dependencies": {},
19
- "devDependencies": {
20
- "eslint": "^6.7.2",
21
- "eslint-config-prettier": "^6.7.0",
22
- "eslint-plugin-prettier": "^3.1.1",
23
- "eslint-plugin-simple-import-sort": "^5.0.0",
24
- "@typescript-eslint/eslint-plugin": "^2.10.0",
25
- "@typescript-eslint/parser": "^2.10.0",
26
- "prettier": "^1.19.1",
27
- "ts-jest": "25.2.1"
28
- },
19
+ "devDependencies": {},
29
20
  "author": "Kristiyan Tachev",
30
21
  "license": "MIT",
31
22
  "browserslist": [
@@ -0,0 +1,35 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ import { ModifierOptions } from './types';
3
+
4
+ /* */
5
+ export abstract class Attribute<T = Record<string, unknown>> {
6
+ public static options: ModifierOptions;
7
+ public element?: HTMLElement;
8
+ public value?: string;
9
+ public selector?: string;
10
+ public parent?: HTMLElement;
11
+ public observer?: MutationObserver;
12
+ setStyles(keys: T) {
13
+ return (div: HTMLElement | Element | HTMLDivElement) => {
14
+ for (const [key, value] of Object.entries(keys)) {
15
+ div['style'][key] = value;
16
+ }
17
+ };
18
+ }
19
+ OnInit(): void {
20
+ /* */
21
+ }
22
+ OnDestroy(): void {
23
+ /* */
24
+ }
25
+ OnUpdate(_oldValue: string, _newValue: string) {
26
+ /* */
27
+ }
28
+ OnUpdateAttribute(_name: string, _value: string) {
29
+ /* */
30
+ }
31
+
32
+ OnChange(_records: MutationRecord[]): void {
33
+ /* */
34
+ }
35
+ }