@htmlplus/element 0.8.3 → 0.8.4

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,4 +1,4 @@
1
- import { camelCase, paramCase } from 'change-case';
1
+ import { camelCase, kebabCase } from 'change-case';
2
2
  import * as CONSTANTS from '../../constants/index.js';
3
3
  import { call, getConfig, getMembers, getNamespace, getTag, isServer, request, toProperty } from '../utils/index.js';
4
4
  export function Element() {
@@ -26,7 +26,7 @@ export function Element() {
26
26
  static get observedAttributes() {
27
27
  return Object.keys(members)
28
28
  .filter((key) => members[key].type != CONSTANTS.TYPE_FUNCTION)
29
- .map((key) => paramCase(key));
29
+ .map((key) => kebabCase(key));
30
30
  }
31
31
  adoptedCallback() {
32
32
  call(this[CONSTANTS.API_INSTANCE], CONSTANTS.LIFECYCLE_ADOPTED);
@@ -1,4 +1,4 @@
1
- import { paramCase, pascalCase } from 'change-case';
1
+ import { kebabCase, pascalCase } from 'change-case';
2
2
  import { defineProperty, getFramework, host } from '../utils/index.js';
3
3
  export function Event(options = {}) {
4
4
  return function (target, propertyKey) {
@@ -11,11 +11,16 @@ export function Event(options = {}) {
11
11
  (_a = options.bubbles) !== null && _a !== void 0 ? _a : (options.bubbles = false);
12
12
  let name = options.name || String(propertyKey);
13
13
  switch (framework) {
14
+ case 'qwik':
15
+ name = pascalCase(name).toLowerCase();
16
+ break;
17
+ case 'preact':
14
18
  case 'react':
19
+ case 'solid':
15
20
  name = pascalCase(name);
16
21
  break;
17
22
  default:
18
- name = paramCase(name);
23
+ name = kebabCase(name);
19
24
  break;
20
25
  }
21
26
  const event = new CustomEvent(name, Object.assign(Object.assign({}, options), { detail }));
@@ -1,4 +1,4 @@
1
- import { paramCase } from 'change-case';
1
+ import { kebabCase } from 'change-case';
2
2
  import { typeOf } from './typeOf.js';
3
3
  export const classes = (input, smart) => {
4
4
  const result = [];
@@ -16,7 +16,7 @@ export const classes = (input, smart) => {
16
16
  const keys = Object.keys(input);
17
17
  for (const key of keys) {
18
18
  const value = input[key];
19
- const name = paramCase(key);
19
+ const name = kebabCase(key);
20
20
  const type = typeOf(value);
21
21
  if (!smart) {
22
22
  if (!value)
@@ -1,12 +1,16 @@
1
1
  export const getFramework = (target) => {
2
+ if ('_qc_' in target)
3
+ return 'qwik';
4
+ if ('_$owner' in target)
5
+ return 'solid';
6
+ if ('__svelte_meta' in target)
7
+ return 'svelte';
8
+ if ('__vnode' in target)
9
+ return 'vue';
2
10
  const keys = Object.keys(target);
3
- const has = (key) => keys.some((key) => key.startsWith(key));
11
+ const has = (input) => keys.some((key) => key.startsWith(input));
4
12
  if (has('__zone_symbol__'))
5
13
  return 'angular';
6
14
  if (has('__react'))
7
15
  return 'react';
8
- if (has('__svelte'))
9
- return 'svelte';
10
- if (has('__vnode'))
11
- return 'vue';
12
16
  };
@@ -1,4 +1,4 @@
1
- import { paramCase } from 'change-case';
1
+ import { kebabCase } from 'change-case';
2
2
  import { typeOf } from './typeOf.js';
3
3
  export const styles = (input) => {
4
4
  switch (typeOf(input)) {
@@ -7,7 +7,7 @@ export const styles = (input) => {
7
7
  case 'object':
8
8
  return Object.keys(input)
9
9
  .filter((key) => input[key] !== undefined && input[key] !== null)
10
- .map((key) => `${key.startsWith('--') ? '--' : ''}${paramCase(key)}: ${input[key]}`)
10
+ .map((key) => `${key.startsWith('--') ? '--' : ''}${kebabCase(key)}: ${input[key]}`)
11
11
  .join('; ');
12
12
  case 'string':
13
13
  return input;
@@ -1,6 +1,6 @@
1
- import { paramCase } from 'change-case';
1
+ import { kebabCase } from 'change-case';
2
2
  export const updateAttribute = (node, key, value) => {
3
- const name = paramCase(key);
3
+ const name = kebabCase(key);
4
4
  if ([undefined, null, false].includes(value))
5
5
  return node.removeAttribute(name);
6
6
  node.setAttribute(name, value === true ? '' : value);
@@ -1,6 +1,6 @@
1
1
  import template from '@babel/template';
2
2
  import t from '@babel/types';
3
- import { camelCase, paramCase, pascalCase } from 'change-case';
3
+ import { camelCase, kebabCase, pascalCase } from 'change-case';
4
4
  import * as CONSTANTS from '../../constants/index.js';
5
5
  import { addDependency, getType, print, toEventTypeAnnotation, toPropertySignature, visitor } from '../utils/index.js';
6
6
  export const CUSTOM_ELEMENT_OPTIONS = {
@@ -291,13 +291,13 @@ export const customElement = (options) => {
291
291
  const attributeJSX = [
292
292
  ...context.classProperties.map((property) => {
293
293
  return toPropertySignature(property, {
294
- keyTransformer: (key) => paramCase(key)
294
+ keyTransformer: (key) => kebabCase(key)
295
295
  });
296
296
  }),
297
297
  ...context.classEvents.map((event) => {
298
298
  return toPropertySignature(event, {
299
299
  optional: true,
300
- keyTransformer: (key) => 'on' + paramCase(key),
300
+ keyTransformer: (key) => camelCase('on-' + key),
301
301
  typeAnnotationTransformer: toEventTypeAnnotation
302
302
  });
303
303
  })
@@ -15,7 +15,7 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "YOUR_CORE_PACKAGE_NAME": "latest",
18
- "change-case": "^4.1.2"
18
+ "change-case": "^5.1.2"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@rollup/plugin-commonjs": "^15.0.0",
@@ -3,7 +3,7 @@
3
3
  **************************************************/
4
4
  import React from 'react';
5
5
 
6
- import { camelCase, paramCase, pascalCase } from 'change-case';
6
+ import { camelCase, kebabCase, pascalCase } from 'change-case';
7
7
 
8
8
  export type Rename<T, R extends { [K in keyof R]: K extends keyof T ? PropertyKey : 'Error: key not in T' }> = {
9
9
  [P in keyof T as P extends keyof R ? R[P] : P]: T[P];
@@ -107,7 +107,7 @@ const getProps = <ElementType>(ref: React.Ref<ElementType>, props: PropsType<Ele
107
107
  } else if (extra.props?.includes(name)) {
108
108
  if (!isPrimitive(value)) return;
109
109
 
110
- (result as any)[paramCase(name)] = value;
110
+ (result as any)[kebabCase(name)] = value;
111
111
  } else {
112
112
  (result as any)[name] = value;
113
113
  }
@@ -163,10 +163,10 @@ const setEvent = (element: Element, name: string, handler: EventHandlerType) =>
163
163
 
164
164
  const previous = events[name];
165
165
 
166
- previous && element.removeEventListener(paramCase(name), previous);
166
+ previous && element.removeEventListener(kebabCase(name), previous);
167
167
 
168
168
  element.addEventListener(
169
- paramCase(name),
169
+ kebabCase(name),
170
170
  (events[name] = function callback(event: Event) {
171
171
  handler && handler.call(this, event);
172
172
  })
@@ -201,7 +201,7 @@ const setProps = <ElementType>(element: ElementType, props: PropsType<ElementTyp
201
201
  setEvent(element, event, value);
202
202
  } else if (extra.props?.includes(name)) {
203
203
  if (isPrimitive(value)) {
204
- element.setAttribute(paramCase(name), value);
204
+ element.setAttribute(kebabCase(name), value);
205
205
  } else {
206
206
  (element as any)[name] = value;
207
207
  }
@@ -248,7 +248,7 @@ export const proxy = <ElementType, PropType>(
248
248
  Object.keys(events).forEach((name) => {
249
249
  const handler = events[name];
250
250
 
251
- (this.element as any).removeEventListener(paramCase(name), handler);
251
+ (this.element as any).removeEventListener(kebabCase(name), handler);
252
252
  });
253
253
 
254
254
  delete (this.element as any)['$events'];
@@ -1,4 +1,4 @@
1
- import { capitalCase, paramCase } from 'change-case';
1
+ import { capitalCase, kebabCase } from 'change-case';
2
2
  import fs from 'fs-extra';
3
3
  import glob from 'glob';
4
4
  import path from 'path';
@@ -122,7 +122,7 @@ export const document = (options) => {
122
122
  const parts = getTags(context.class, 'part').map((tag) => parseTag(tag));
123
123
  const properties = context.classProperties.map((property) => {
124
124
  var _a, _b, _c;
125
- const attribute = paramCase(property.key['name']);
125
+ const attribute = kebabCase(property.key['name']);
126
126
  const deprecated = hasTag(property, 'deprecated');
127
127
  const description = (_a = getTags(property).find((tag) => !tag.key)) === null || _a === void 0 ? void 0 : _a.value;
128
128
  const experimental = hasTag(property, 'experimental');
@@ -1,5 +1,5 @@
1
1
  import t from '@babel/types';
2
- import { paramCase } from 'change-case';
2
+ import { kebabCase } from 'change-case';
3
3
  import path from 'path';
4
4
  import * as CONSTANTS from '../../constants/index.js';
5
5
  import { hasDecorator, visitor } from '../utils/index.js';
@@ -38,7 +38,7 @@ export const extract = () => {
38
38
  context.fileExtension = path.extname(context.filePath);
39
39
  context.fileName = path.basename(context.filePath, context.fileExtension);
40
40
  context.className = (_b = (_a = context.class) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.name;
41
- context.componentKey = paramCase(context.className);
41
+ context.componentKey = kebabCase(context.className);
42
42
  context.classEvents = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_EVENT));
43
43
  context.classMethods = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_METHOD));
44
44
  context.classProperties = (context.classMembers || []).filter((member) => hasDecorator(member, CONSTANTS.DECORATOR_PROPERTY));
@@ -1,4 +1,4 @@
1
- import { paramCase } from 'change-case';
1
+ import { kebabCase } from 'change-case';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
4
  import { getTags, getType, print } from '../utils/index.js';
@@ -31,7 +31,7 @@ export const visualStudioCode = (options) => {
31
31
  };
32
32
  for (const property of context.classProperties || []) {
33
33
  const attribute = {
34
- name: paramCase(property.key['name']),
34
+ name: kebabCase(property.key['name']),
35
35
  description: (_c = getTags(property).find((tag) => !tag.key)) === null || _c === void 0 ? void 0 : _c.value,
36
36
  values: []
37
37
  };
@@ -1,4 +1,4 @@
1
- import { paramCase } from 'change-case';
1
+ import { kebabCase } from 'change-case';
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
4
  import { getInitializer, getTags, getType, hasTag, parseTag, print } from '../utils/index.js';
@@ -40,7 +40,7 @@ export const webTypes = (options) => {
40
40
  const attributes = (_a = context.classProperties) === null || _a === void 0 ? void 0 : _a.map((property) => {
41
41
  var _a;
42
42
  return Object.assign(common(property), {
43
- name: paramCase(property.key['name']),
43
+ name: kebabCase(property.key['name']),
44
44
  value: {
45
45
  // kind: TODO
46
46
  type: print(getType(context.directoryPath, context.fileAST, (_a = property.typeAnnotation) === null || _a === void 0 ? void 0 : _a['typeAnnotation']))
@@ -52,7 +52,7 @@ export const webTypes = (options) => {
52
52
  });
53
53
  const description = (_b = getTags(context.class).find((tag) => !tag.key)) === null || _b === void 0 ? void 0 : _b.value;
54
54
  const events = (_c = context.classEvents) === null || _c === void 0 ? void 0 : _c.map((event) => Object.assign(common(event), {
55
- name: paramCase(event.key['name']) // TODO
55
+ name: kebabCase(event.key['name']) // TODO
56
56
  // 'value': TODO
57
57
  }));
58
58
  const methods = (_d = context.classMethods) === null || _d === void 0 ? void 0 : _d.map((method) => Object.assign(common(method), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlplus/element",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "author": "Masood Abdolian <m.abdolian@gmail.com>",
@@ -38,7 +38,7 @@
38
38
  "@babel/traverse": "^7.20.1",
39
39
  "@babel/types": "^7.20.2",
40
40
  "@types/node": "^18.11.9",
41
- "change-case": "^4.1.2",
41
+ "change-case": "^5.1.2",
42
42
  "fast-glob": "^3.2.12",
43
43
  "fs-extra": "^10.1.0",
44
44
  "handlebars": "^4.7.7",