@htmlplus/element 0.7.0 → 0.7.2

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.
@@ -1,6 +1,6 @@
1
1
  import { camelCase, paramCase } from 'change-case';
2
2
  import * as CONSTANTS from '../../constants/index.js';
3
- import { call, fromAttribute, getConfig, getMembers, getTag, isServer, request } from '../utils/index.js';
3
+ import { call, fromAttribute, getConfig, getMembers, getNamespace, getTag, isServer, request } from '../utils/index.js';
4
4
  export function Element() {
5
5
  return function (constructor) {
6
6
  if (isServer())
@@ -44,7 +44,7 @@ export function Element() {
44
44
  connectedCallback() {
45
45
  const instance = this[CONSTANTS.API_INSTANCE];
46
46
  // TODO: experimental for global config
47
- Object.assign(instance, getConfig('component', getTag(instance), 'property'));
47
+ Object.assign(instance, getConfig(getNamespace(instance), 'component', getTag(instance), 'property'));
48
48
  const connect = () => {
49
49
  instance[CONSTANTS.API_CONNECTED] = true;
50
50
  call(instance, CONSTANTS.LIFECYCLE_CONNECTED);
@@ -13,8 +13,8 @@ export function Property(options) {
13
13
  if (next === previous)
14
14
  return;
15
15
  this[symbol] = next;
16
- request(this, name, previous, (skip) => {
17
- if (!(options === null || options === void 0 ? void 0 : options.reflect) || skip)
16
+ request(this, name, previous, (skipped) => {
17
+ if (!(options === null || options === void 0 ? void 0 : options.reflect) || skipped)
18
18
  return;
19
19
  target[CONSTANTS.API_LOCKED] = true;
20
20
  updateAttribute(host(this), name, next);
@@ -6,4 +6,4 @@ export * from './queryAll.js';
6
6
  export * from './slots.js';
7
7
  export * from './styles.js';
8
8
  export * from './toUnit.js';
9
- export { host, isServer, on, off } from '../utils/index.js';
9
+ export { getConfig, host, isServer, on, off, setConfig } from '../utils/index.js';
@@ -6,4 +6,4 @@ export * from './queryAll.js';
6
6
  export * from './slots.js';
7
7
  export * from './styles.js';
8
8
  export * from './toUnit.js';
9
- export { host, isServer, on, off } from '../utils/index.js';
9
+ export { getConfig, host, isServer, on, off, setConfig } from '../utils/index.js';
@@ -7,6 +7,6 @@ interface Options {
7
7
  };
8
8
  };
9
9
  }
10
- export declare const getConfig: (...parameters: string[]) => any;
11
- export declare const setConfig: (config: Options, override?: boolean) => void;
10
+ export declare const getConfig: (namespace: string, ...parameters: string[]) => any;
11
+ export declare const setConfig: (namespace: string, config: Options, override?: boolean) => void;
12
12
  export {};
@@ -1,11 +1,11 @@
1
- import { typeOf } from './typeOf.js';
1
+ import { merge } from './merge.js';
2
2
  let defaults = {
3
3
  component: {}
4
4
  };
5
- export const getConfig = (...parameters) => {
5
+ export const getConfig = (namespace, ...parameters) => {
6
6
  if (typeof window == 'undefined')
7
7
  return;
8
- let config = window['HTMLPLUS'];
8
+ let config = window[namespace];
9
9
  for (const parameter of parameters) {
10
10
  if (!config)
11
11
  break;
@@ -13,27 +13,8 @@ export const getConfig = (...parameters) => {
13
13
  }
14
14
  return config;
15
15
  };
16
- export const setConfig = (config, override) => {
16
+ export const setConfig = (namespace, config, override) => {
17
17
  if (typeof window == 'undefined')
18
18
  return;
19
- window['HTMLPLUS'] = merge({}, defaults, override ? {} : window['HTMLPLUS'], config);
20
- };
21
- const merge = (target, ...sources) => {
22
- for (const source of sources) {
23
- if (!source)
24
- continue;
25
- if (typeOf(source) != 'object') {
26
- target = source;
27
- continue;
28
- }
29
- for (const key of Object.keys(source)) {
30
- if (target[key] instanceof Object && source[key] instanceof Object && target[key] !== source[key]) {
31
- target[key] = merge(target[key], source[key]);
32
- }
33
- else {
34
- target[key] = source[key];
35
- }
36
- }
37
- }
38
- return target;
19
+ window[namespace] = merge({}, defaults, override ? {} : window[namespace], config);
39
20
  };
@@ -0,0 +1,2 @@
1
+ import { PlusElement } from '../../types';
2
+ export declare const getNamespace: (instance: PlusElement) => string;
@@ -0,0 +1,4 @@
1
+ import { getTag } from './getTag.js';
2
+ export const getNamespace = (instance) => {
3
+ return getTag(instance).split('-')[0].toUpperCase();
4
+ };
@@ -7,11 +7,13 @@ export * from './event.js';
7
7
  export * from './fromAttribute.js';
8
8
  export * from './getFramework.js';
9
9
  export * from './getMembers.js';
10
+ export * from './getNamespace.js';
10
11
  export * from './getStyles.js';
11
12
  export * from './getTag.js';
12
13
  export * from './host.js';
13
14
  export * from './isEvent.js';
14
15
  export * from './isServer.js';
16
+ export * from './merge.js';
15
17
  export * from './request.js';
16
18
  export * from './shadowRoot.js';
17
19
  export * from './syncAttributes.js';
@@ -7,11 +7,13 @@ export * from './event.js';
7
7
  export * from './fromAttribute.js';
8
8
  export * from './getFramework.js';
9
9
  export * from './getMembers.js';
10
+ export * from './getNamespace.js';
10
11
  export * from './getStyles.js';
11
12
  export * from './getTag.js';
12
13
  export * from './host.js';
13
14
  export * from './isEvent.js';
14
15
  export * from './isServer.js';
16
+ export * from './merge.js';
15
17
  export * from './request.js';
16
18
  export * from './shadowRoot.js';
17
19
  export * from './syncAttributes.js';
@@ -0,0 +1 @@
1
+ export declare const merge: (target: any, ...sources: any[]) => any;
@@ -0,0 +1,20 @@
1
+ import { typeOf } from './typeOf.js';
2
+ export const merge = (target, ...sources) => {
3
+ for (const source of sources) {
4
+ if (!source)
5
+ continue;
6
+ if (typeOf(source) != 'object') {
7
+ target = source;
8
+ continue;
9
+ }
10
+ for (const key of Object.keys(source)) {
11
+ if (target[key] instanceof Object && source[key] instanceof Object && target[key] !== source[key]) {
12
+ target[key] = merge(target[key], source[key]);
13
+ }
14
+ else {
15
+ target[key] = source[key];
16
+ }
17
+ }
18
+ }
19
+ return target;
20
+ };
@@ -6,4 +6,4 @@ import { PlusElement } from '../../types';
6
6
  * @param previous The previous value of Property/State.
7
7
  * @param callback Invoked when the rendering phase is completed.
8
8
  */
9
- export declare const request: (target: PlusElement, name?: string, previous?: any, callback?: Function) => void;
9
+ export declare const request: (target: PlusElement, name?: string, previous?: any, callback?: ((skipped: boolean) => void) | undefined) => void;
@@ -54,6 +54,15 @@ export const customElement = (options) => {
54
54
  path.replaceWith(t.jsxAttribute(t.jsxIdentifier('class'), value));
55
55
  }
56
56
  });
57
+ // replaces 'tabIndex' attribute with 'tabindex'
58
+ visitor(ast, {
59
+ JSXAttribute(path) {
60
+ const { name, value } = path.node;
61
+ if (name.name != 'tabIndex')
62
+ return;
63
+ path.replaceWith(t.jsxAttribute(t.jsxIdentifier('tabindex'), value));
64
+ }
65
+ });
57
66
  // converts 'jsx' to 'uhtml' syntax
58
67
  visitor(ast, {
59
68
  JSXAttribute: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "author": "Masood Abdolian <m.abdolian@gmail.com>",