@htmlplus/element 0.4.9 → 0.5.1

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.
Files changed (69) hide show
  1. package/README.md +19 -20
  2. package/client/decorators/attributes.js +2 -3
  3. package/client/decorators/element.js +18 -20
  4. package/client/decorators/listen.d.ts +13 -3
  5. package/client/decorators/listen.js +15 -5
  6. package/client/decorators/property.js +20 -20
  7. package/client/decorators/state.js +5 -9
  8. package/client/decorators/watch.d.ts +6 -4
  9. package/client/decorators/watch.js +18 -19
  10. package/client/helpers/query.js +3 -3
  11. package/client/helpers/queryAll.js +3 -3
  12. package/client/helpers/slots.js +10 -12
  13. package/client/utils/appendToMethod.d.ts +1 -1
  14. package/client/utils/appendToMethod.js +3 -3
  15. package/client/utils/call.d.ts +1 -1
  16. package/client/utils/call.js +2 -2
  17. package/client/utils/config.d.ts +9 -2
  18. package/client/utils/config.js +28 -4
  19. package/client/utils/getMembers.d.ts +8 -0
  20. package/client/utils/getMembers.js +5 -0
  21. package/client/utils/getTag.d.ts +2 -0
  22. package/client/utils/getTag.js +5 -0
  23. package/client/utils/index.d.ts +3 -2
  24. package/client/utils/index.js +3 -2
  25. package/client/utils/request.d.ts +8 -3
  26. package/client/utils/request.js +51 -25
  27. package/client/utils/shadowRoot.d.ts +2 -0
  28. package/client/utils/shadowRoot.js +5 -0
  29. package/client/utils/task.d.ts +4 -4
  30. package/client/utils/task.js +5 -8
  31. package/client/vendors/uhtml.js +1 -2
  32. package/compiler/compiler.js +21 -20
  33. package/compiler/plugins/assets.d.ts +2 -0
  34. package/compiler/plugins/assets.js +11 -4
  35. package/compiler/plugins/copy.d.ts +4 -4
  36. package/compiler/plugins/copy.js +8 -5
  37. package/compiler/plugins/customElement.d.ts +1 -0
  38. package/compiler/plugins/customElement.js +33 -13
  39. package/compiler/plugins/customElementReact/customElementReact.d.ts +10 -3
  40. package/compiler/plugins/customElementReact/customElementReact.js +10 -43
  41. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.compact.ts.hbs +10 -7
  42. package/compiler/plugins/customElementReact/templates/src/components/{{fileName}}.ts.hbs +4 -5
  43. package/compiler/plugins/customElementReact/templates/src/proxy.ts.hbs +29 -38
  44. package/compiler/plugins/document.d.ts +3 -1
  45. package/compiler/plugins/document.js +11 -34
  46. package/compiler/plugins/extract.d.ts +1 -0
  47. package/compiler/plugins/extract.js +4 -6
  48. package/compiler/plugins/index.d.ts +1 -0
  49. package/compiler/plugins/index.js +1 -0
  50. package/compiler/plugins/parse.d.ts +4 -1
  51. package/compiler/plugins/parse.js +8 -7
  52. package/compiler/plugins/read.d.ts +7 -1
  53. package/compiler/plugins/read.js +6 -2
  54. package/compiler/plugins/readme.d.ts +9 -0
  55. package/compiler/plugins/readme.js +23 -0
  56. package/compiler/plugins/style.d.ts +3 -2
  57. package/compiler/plugins/style.js +11 -8
  58. package/compiler/plugins/visualStudioCode.d.ts +1 -0
  59. package/compiler/plugins/visualStudioCode.js +2 -2
  60. package/compiler/plugins/webTypes.d.ts +4 -2
  61. package/compiler/plugins/webTypes.js +17 -17
  62. package/constants/index.d.ts +19 -13
  63. package/constants/index.js +22 -15
  64. package/package.json +18 -13
  65. package/types/context.d.ts +13 -15
  66. package/client/utils/getMemberType.d.ts +0 -2
  67. package/client/utils/getMemberType.js +0 -5
  68. package/client/utils/getMembersKey.d.ts +0 -2
  69. package/client/utils/getMembersKey.js +0 -4
@@ -3,38 +3,64 @@ import { call } from '../utils/call.js';
3
3
  import { task } from '../utils/task.js';
4
4
  import { html, render } from '../vendors/uhtml.js';
5
5
  import { getStyles } from './getStyles.js';
6
- import { host } from './host.js';
7
- const targets = new Map();
8
- export const request = (target, state) => {
9
- let run = targets.get(target);
10
- if (run)
11
- return run(state);
12
- run = task({
13
- canStart: (states, state) => {
14
- // TODO: hasChange
15
- return true;
16
- },
17
- canRun: (states) => {
18
- // TODO: shouldUpdate
19
- return true;
20
- },
21
- run: (states) => {
6
+ import { shadowRoot } from './shadowRoot.js';
7
+ /**
8
+ * Updates the DOM with a scheduled task.
9
+ * @param target The component instance.
10
+ * @param name Property/State name.
11
+ * @param previous The previous value of Property/State.
12
+ * @param callback Invoked when the rendering phase is completed.
13
+ */
14
+ export const request = (target, name, previous, callback) => {
15
+ var _a, _b;
16
+ // Creates/Gets a stacks.
17
+ const stacks = (target[_a = CONSTANTS.API_STACKS] || (target[_a] = new Map()));
18
+ // Creates/Updates a stack
19
+ const stack = stacks.get(name) || { callbacks: [], previous };
20
+ // Adds the callback to the stack, if exists.
21
+ callback && stack.callbacks.push(callback);
22
+ // Stores the stack.
23
+ stacks.set(name, stack);
24
+ // Creates/Gets a micro task function.
25
+ target[_b = CONSTANTS.API_REQUEST] || (target[_b] = task({
26
+ run: () => {
27
+ // Skips the rendering phase if DOM isn't ready.
28
+ if (!target[CONSTANTS.API_CONNECTED])
29
+ return;
30
+ // Calculates the states to pass into lifecycles' callbacks.
31
+ const states = new Map(Array.from(stacks)
32
+ .filter((stack) => stack[0])
33
+ .map((stack) => [stack[0], stack[1].previous]));
34
+ // Calls the lifecycle's callback before the rendering phase.
22
35
  call(target, CONSTANTS.LIFECYCLE_UPDATE, states);
23
- const element = host(target);
24
- render(element.shadowRoot, () => {
36
+ // Calculates the template.
37
+ const template = () => {
38
+ // Calculates the markup.
25
39
  const markup = call(target, CONSTANTS.METHOD_RENDER);
40
+ // Calculates the styles.
26
41
  const styles = getStyles(target);
27
- if (!styles && !markup)
28
- return html ``;
42
+ // Returns the markup if styles don't exist.
29
43
  if (!styles)
30
44
  return markup;
31
- if (!markup)
32
- return html `<style>${styles}</style>`;
45
+ // Returns the markup and styles together.
33
46
  return html `<style>${styles}</style>${markup}`;
47
+ };
48
+ // Renders template to the DOM.
49
+ render(shadowRoot(target), template);
50
+ // Invokes requests' callback.
51
+ stacks.forEach((state) => {
52
+ state.callbacks.forEach((callback, index, callbacks) => {
53
+ callback(callbacks.length - 1 != index);
54
+ });
34
55
  });
56
+ // Calls the lifecycle's callback after the rendering phase.
35
57
  call(target, CONSTANTS.LIFECYCLE_UPDATED, states);
58
+ // TODO: releated to the @Watch decorator.
59
+ target[CONSTANTS.API_LOADED] = true;
60
+ // Clears stacks.
61
+ stacks.clear();
36
62
  }
37
- });
38
- targets.set(target, run);
39
- return run(state);
63
+ }));
64
+ // Calls the micro task.
65
+ call(target, CONSTANTS.API_REQUEST);
40
66
  };
@@ -0,0 +1,2 @@
1
+ import { PlusElement } from '../../types';
2
+ export declare const shadowRoot: (target: PlusElement) => ShadowRoot | null;
@@ -0,0 +1,5 @@
1
+ import { host } from './host.js';
2
+ export const shadowRoot = (target) => {
3
+ var _a;
4
+ return (_a = host(target)) === null || _a === void 0 ? void 0 : _a.shadowRoot;
5
+ };
@@ -1,6 +1,6 @@
1
1
  export interface QueueOptions {
2
- canStart?: (states: any, state: any) => boolean;
3
- canRun?: (states: any) => boolean;
4
- run: (states: any) => void;
2
+ canStart?: () => boolean;
3
+ canRun?: () => boolean;
4
+ run: () => void;
5
5
  }
6
- export declare const task: (options: QueueOptions) => (state?: any) => Promise<boolean>;
6
+ export declare const task: (options: QueueOptions) => () => Promise<boolean>;
@@ -1,10 +1,8 @@
1
1
  export const task = (options) => {
2
- let isPending, states, updatePromise;
3
- const run = (state) => {
4
- const newStates = Object.assign({}, states, state);
5
- if (options.canStart && !options.canStart(newStates, state))
2
+ let isPending, updatePromise;
3
+ const run = () => {
4
+ if (options.canStart && !options.canStart())
6
5
  return Promise.resolve(false);
7
- states = newStates;
8
6
  if (!isPending)
9
7
  updatePromise = enqueue();
10
8
  return updatePromise;
@@ -21,10 +19,9 @@ export const task = (options) => {
21
19
  if (!isPending)
22
20
  return updatePromise;
23
21
  try {
24
- if (options.canRun && !options.canRun(states))
22
+ if (options.canRun && !options.canRun())
25
23
  return (isPending = false);
26
- options.run(states);
27
- states = undefined;
24
+ options.run();
28
25
  isPending = false;
29
26
  return true;
30
27
  }
@@ -319,8 +319,7 @@ var udomdiff = (parentNode, a, b, get, before) => {
319
319
  };
320
320
  const { isArray, prototype } = Array;
321
321
  const { indexOf } = prototype;
322
- const document = typeof window == 'undefined' ? {} : window.document;
323
- const { createDocumentFragment, createElement, createElementNS, createTextNode, createTreeWalker, importNode } = new Proxy(document, {
322
+ const { createDocumentFragment, createElement, createElementNS, createTextNode, createTreeWalker, importNode } = new Proxy(typeof window == 'undefined' ? {} : window.document, {
324
323
  get: (target, method) => (target[method] || function () { }).bind(target)
325
324
  });
326
325
  const createHTML = (html) => {
@@ -1,22 +1,28 @@
1
1
  import ora from 'ora';
2
+ import path from 'path';
2
3
  const logger = ora({
3
4
  color: 'yellow'
4
5
  });
6
+ const log = (message, persist) => {
7
+ var _a, _b;
8
+ (_b = (_a = logger.start(`${new Date().toLocaleTimeString()} [HTMLPLUS] ${message}`))[persist ? 'succeed' : '']) === null || _b === void 0 ? void 0 : _b.call(_a);
9
+ };
5
10
  export default (...plugins) => {
6
11
  let global = {
7
12
  contexts: []
8
13
  };
9
- logger.start(`${plugins.length} Plugins found.`).succeed();
14
+ log(`Starting...`, true);
15
+ log(`${plugins.length} plugins found.`, true);
10
16
  const start = async () => {
11
- logger.start('Starting...').succeed();
17
+ log(`Plugins are starting...`, true);
12
18
  for (const plugin of plugins) {
13
19
  if (!plugin.start)
14
20
  continue;
15
- logger.start(`Plugin '${plugin.name}' starting...`);
21
+ log(`Plugin '${plugin.name}' is starting...`);
16
22
  await plugin.start(global);
17
- logger.start(`Plugin '${plugin.name}' started successfully.`);
23
+ log(`Plugin '${plugin.name}' started successfully.`);
18
24
  }
19
- logger.start(`Plugins started successfully.`).succeed();
25
+ log(`Plugins started successfully.`, true);
20
26
  };
21
27
  const next = async (filePath) => {
22
28
  var _a;
@@ -24,15 +30,11 @@ export default (...plugins) => {
24
30
  let context = {
25
31
  filePath
26
32
  };
27
- let timeout;
28
33
  for (const plugin of plugins) {
29
34
  if (!plugin.next)
30
35
  continue;
31
- clearTimeout(timeout);
32
- logger.start(`Plugin '${plugin.name}' executing...`);
36
+ log(`Plugin '${plugin.name}' is executing on '${path.basename(filePath)}' file.`);
33
37
  const output = await plugin.next(context, global);
34
- logger.start(`Plugin '${plugin.name}' executed successfully.`);
35
- timeout = setTimeout(() => logger.stop(), 1500);
36
38
  // TODO
37
39
  if (output) {
38
40
  context.outputs = ((_a = context.outputs) !== null && _a !== void 0 ? _a : [])
@@ -49,27 +51,26 @@ export default (...plugins) => {
49
51
  });
50
52
  }
51
53
  global.contexts = global.contexts.filter((current) => current.filePath != context.filePath).concat(context);
54
+ log(`Plugin '${plugin.name}' executed successfully on '${path.basename(filePath)}' file.`);
52
55
  if (context.isInvalid)
53
56
  break;
54
57
  }
58
+ logger.stop();
55
59
  if (context.isInvalid)
56
- logger.start(`File '${key}' break executing because file is invalid.`).succeed();
60
+ log(`File '${key}' break executing because file is invalid.`, true);
57
61
  return context;
58
62
  };
59
63
  const finish = async () => {
60
- logger.start('Finishing...').succeed();
64
+ log(`Plugins are finishing...`, true);
61
65
  for (const plugin of plugins) {
62
66
  if (!plugin.finish)
63
67
  continue;
64
- logger.start(`Plugin '${plugin.name}' finishing...`);
68
+ log(`Plugin '${plugin.name}' is finishing...`);
65
69
  await plugin.finish(global);
66
- logger.start(`Plugin '${plugin.name}' finished successfully.`);
70
+ log(`Plugin '${plugin.name}' finished successfully.`);
67
71
  }
68
- logger.start(`Plugins finished successfully.`).succeed();
69
- };
70
- return {
71
- start,
72
- next,
73
- finish
72
+ log(`Plugins finished successfully.`, true);
73
+ log(`Finished.`, true);
74
74
  };
75
+ return { start, next, finish };
75
76
  };
@@ -1,5 +1,7 @@
1
1
  import { Context } from '../../types';
2
+ export declare const ASSETS_OPTIONS: Partial<AssetsOptions>;
2
3
  export declare type AssetsOptions = {
4
+ once?: boolean;
3
5
  destination: (context: Context) => string;
4
6
  source?: (context: Context) => string;
5
7
  };
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
- const defaults = {
3
+ export const ASSETS_OPTIONS = {
4
+ once: true,
4
5
  destination(context) {
5
6
  return `assets/${context.fileName}`;
6
7
  },
@@ -10,15 +11,21 @@ const defaults = {
10
11
  };
11
12
  export const assets = (options) => {
12
13
  const name = 'assets';
13
- options = Object.assign({}, defaults, options);
14
+ options = Object.assign({}, ASSETS_OPTIONS, options);
15
+ const sources = new Set();
14
16
  const next = (context) => {
15
17
  var _a, _b;
16
- const destination = (_a = options.destination) === null || _a === void 0 ? void 0 : _a.call(options, context);
17
- const source = (_b = options.source) === null || _b === void 0 ? void 0 : _b.call(options, context);
18
+ const source = (_a = options.source) === null || _a === void 0 ? void 0 : _a.call(options, context);
18
19
  if (!source)
19
20
  return;
20
21
  if (!fs.existsSync(source))
21
22
  return;
23
+ if (options.once) {
24
+ if (sources.has(source))
25
+ return;
26
+ sources.add(source);
27
+ }
28
+ const destination = (_b = options.destination) === null || _b === void 0 ? void 0 : _b.call(options, context);
22
29
  fs.copySync(source, destination);
23
30
  context.assets = source;
24
31
  };
@@ -1,13 +1,13 @@
1
+ export declare const COPY_OPTIONS: Partial<CopyOptions>;
1
2
  export interface CopyOptions {
2
- at?: 'finish' | 'start';
3
+ at?: 'start' | 'next' | 'finish';
3
4
  destination: string;
4
5
  source: string;
5
- transformer?: (parameters: {
6
- content: string;
7
- }) => string;
6
+ transformer?: (content: string) => string;
8
7
  }
9
8
  export declare const copy: (options: CopyOptions) => {
10
9
  name: string;
11
10
  start: () => void;
11
+ next: () => void;
12
12
  finish: () => void;
13
13
  };
@@ -1,26 +1,29 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
- const defaults = {
4
- at: 'finish',
3
+ export const COPY_OPTIONS = {
4
+ at: 'start'
5
5
  };
6
6
  export const copy = (options) => {
7
7
  const name = 'copy';
8
- options = Object.assign({}, defaults, options);
8
+ options = Object.assign({}, COPY_OPTIONS, options);
9
9
  const copy = (caller) => {
10
10
  if (options.at != caller)
11
11
  return;
12
12
  let content;
13
13
  content = fs.readFileSync(options.source, 'utf8');
14
14
  if (options.transformer)
15
- content = options.transformer({ content });
15
+ content = options.transformer(content);
16
16
  fs.ensureDirSync(path.dirname(options.destination));
17
17
  fs.writeFileSync(options.destination, content, 'utf8');
18
18
  };
19
19
  const start = () => {
20
20
  copy('start');
21
21
  };
22
+ const next = () => {
23
+ copy('next');
24
+ };
22
25
  const finish = () => {
23
26
  copy('finish');
24
27
  };
25
- return { name, start, finish };
28
+ return { name, start, next, finish };
26
29
  };
@@ -1,4 +1,5 @@
1
1
  import { Context } from '../../types';
2
+ export declare const CUSTOM_ELEMENT_OPTIONS: Partial<CustomElementOptions>;
2
3
  export interface CustomElementOptions {
3
4
  typings?: boolean;
4
5
  }
@@ -2,16 +2,28 @@ import t from '@babel/types';
2
2
  import { pascalCase } from 'change-case';
3
3
  import * as CONSTANTS from '../../constants/index.js';
4
4
  import { addDependency, print, visitor } from '../utils/index.js';
5
- const defaults = {
5
+ export const CUSTOM_ELEMENT_OPTIONS = {
6
+ // prefix: undefined,
6
7
  typings: true
7
8
  };
8
9
  // TODO: support {variable && jsxElement}
9
10
  export const customElement = (options) => {
10
11
  const name = 'customElement';
11
- options = Object.assign({}, defaults, options);
12
+ options = Object.assign({}, CUSTOM_ELEMENT_OPTIONS, options);
12
13
  const next = (context) => {
13
14
  const ast = t.cloneNode(context.fileAST, true);
14
- // attach style mapper for 'style' attribute
15
+ // attaches name
16
+ visitor(ast, {
17
+ ClassDeclaration(path) {
18
+ const { body, id } = path.node;
19
+ if (id.name != context.className)
20
+ return;
21
+ const node = t.classProperty(t.identifier(CONSTANTS.STATIC_TAG), t.stringLiteral(context.componentTag), undefined, undefined, undefined, true);
22
+ t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_PROPERTY, true);
23
+ body.body.unshift(node);
24
+ }
25
+ });
26
+ // attaches style mapper for 'style' attribute
15
27
  visitor(ast, {
16
28
  JSXAttribute(path) {
17
29
  const { name, value } = path.node;
@@ -21,16 +33,13 @@ export const customElement = (options) => {
21
33
  return;
22
34
  if (value.type != 'JSXExpressionContainer')
23
35
  return;
24
- const { local } = addDependency(path, CONSTANTS.PACKAGE_NAME, CONSTANTS.UTILS_STYLE_MAP, CONSTANTS.UTILS_STYLE_MAP);
36
+ const { local } = addDependency(path, CONSTANTS.PACKAGE_NAME, CONSTANTS.UTIL_STYLE_MAPPER, CONSTANTS.UTIL_STYLE_MAPPER);
25
37
  // TODO: remove 'local!'
26
38
  path.replaceWith(t.jsxAttribute(t.jsxIdentifier('style'), t.jsxExpressionContainer(t.callExpression(t.identifier(local), [value.expression]))));
27
39
  path.skip();
28
40
  }
29
41
  });
30
- // TODO
31
- const { node } = addDependency(ast, CONSTANTS.VENDOR_UHTML, 'uhtml');
32
- t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_DEPENDENCY, true);
33
- // replace 'className' attribute to 'class'
42
+ // replaces 'className' attribute with 'class'
34
43
  visitor(ast, {
35
44
  JSXAttribute(path) {
36
45
  const { name, value } = path.node;
@@ -42,7 +51,7 @@ export const customElement = (options) => {
42
51
  path.replaceWith(t.jsxAttribute(t.jsxIdentifier('class'), value));
43
52
  }
44
53
  });
45
- // TODO: convert 'jsx' to 'uhtml' syntax
54
+ // converts 'jsx' to 'uhtml' syntax
46
55
  visitor(ast, {
47
56
  JSXAttribute: {
48
57
  exit(path) {
@@ -86,9 +95,13 @@ export const customElement = (options) => {
86
95
  // TODO
87
96
  path.replaceWith(t.jsxAttribute(t.jsxIdentifier('.dataset'), t.jsxExpressionContainer(path.node.argument)));
88
97
  }
98
+ },
99
+ Program(path) {
100
+ const { node } = addDependency(path, CONSTANTS.VENDOR_UHTML_PATH, 'uhtml');
101
+ t.addComment(node, 'leading', CONSTANTS.COMMENT_AUTO_ADDED_DEPENDENCY, true);
89
102
  }
90
103
  });
91
- // attach members
104
+ // attaches members
92
105
  visitor(ast, {
93
106
  ClassDeclaration(path) {
94
107
  const { body, id } = path.node;
@@ -96,6 +109,7 @@ export const customElement = (options) => {
96
109
  return;
97
110
  const node = t.classProperty(t.identifier(CONSTANTS.STATIC_MEMBERS), t.objectExpression([
98
111
  ...context.classProperties.map((property) => {
112
+ var _a, _b, _c, _d, _e, _f;
99
113
  const properties = [];
100
114
  if (property.value) {
101
115
  properties.push(t.objectProperty(t.identifier(CONSTANTS.STATIC_MEMBERS_INITIALIZER), property.value));
@@ -114,6 +128,12 @@ export const customElement = (options) => {
114
128
  if (type) {
115
129
  properties.push(t.objectProperty(t.identifier(CONSTANTS.STATIC_MEMBERS_TYPE), type));
116
130
  }
131
+ // TODO
132
+ // prettier-ignore
133
+ (_f = (_e = (_d = (_c = (_b = (_a = property === null || property === void 0 ? void 0 : property.decorators) === null || _a === void 0 ? void 0 : _a.find((decorator) => {
134
+ var _a, _b;
135
+ return ((_b = (_a = decorator.expression) === null || _a === void 0 ? void 0 : _a['callee']) === null || _b === void 0 ? void 0 : _b.name) == CONSTANTS.DECORATOR_PROPERTY;
136
+ })) === null || _b === void 0 ? void 0 : _b.expression) === null || _c === void 0 ? void 0 : _c['arguments']) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.properties) === null || _f === void 0 ? void 0 : _f.forEach((property) => properties.push(property));
117
137
  return t.objectProperty(t.identifier(property.key['name']), t.objectExpression(properties));
118
138
  }),
119
139
  ...context.classMethods.map((method) => t.objectProperty(t.identifier(method.key['name']), t.objectExpression([
@@ -124,14 +144,14 @@ export const customElement = (options) => {
124
144
  body.body.unshift(node);
125
145
  }
126
146
  });
127
- // attach typings
147
+ // attaches typings
128
148
  if (options === null || options === void 0 ? void 0 : options.typings) {
129
149
  visitor(ast, {
130
150
  Program(path) {
131
151
  const { body } = path.node;
132
152
  body.push(t.exportNamedDeclaration(t.tsInterfaceDeclaration(
133
153
  // TODO
134
- t.identifier(context.componentClassName + 'JSX'), null, [], t.tsInterfaceBody([
154
+ t.identifier(context.className + 'JSX'), null, [], t.tsInterfaceBody([
135
155
  ...context.classProperties.map((property) => Object.assign(t.tSPropertySignature(property.key, property.typeAnnotation), {
136
156
  optional: property.optional,
137
157
  leadingComments: t.cloneNode(property, true).leadingComments
@@ -171,7 +191,7 @@ export const customElement = (options) => {
171
191
  t.tSModuleDeclaration(t.identifier('JSX'), t.tSModuleBlock([
172
192
  t.tSInterfaceDeclaration(t.identifier('IntrinsicElements'), undefined, undefined, t.tSInterfaceBody([
173
193
  t.tSPropertySignature(t.stringLiteral(context.componentTag), t.tSTypeAnnotation(t.tSIntersectionType([
174
- t.tSTypeReference(t.identifier(context.componentClassName + 'JSX')),
194
+ t.tSTypeReference(t.identifier(context.className + 'JSX')),
175
195
  t.tSTypeLiteral([
176
196
  t.tSIndexSignature([
177
197
  Object.assign({}, t.identifier('key'), {
@@ -1,10 +1,17 @@
1
- import { Global } from '../../../types';
1
+ import { Context, Global } from '../../../types';
2
+ export declare const CUSTOM_ELEMENT_REACT_OPTIONS: Partial<CustomElementReactOptions>;
2
3
  export interface CustomElementReactOptions {
3
4
  compact?: boolean;
4
5
  destination: string;
5
6
  eventName?: (eventName: string) => string;
6
- importerComponent?: (context: any) => string;
7
- importerComponentType?: (context: any) => string;
7
+ importerComponent: (context: Context) => {
8
+ source: string;
9
+ };
10
+ importerComponentType: (context: Context) => {
11
+ source: string;
12
+ imported: string;
13
+ local: string;
14
+ };
8
15
  }
9
16
  export declare const customElementReact: (options: CustomElementReactOptions) => {
10
17
  name: string;
@@ -1,21 +1,9 @@
1
1
  import { pascalCase } from 'change-case';
2
2
  import { __dirname, isDirectoryEmpty, renderTemplate } from '../../utils/index.js';
3
- const defaults = {
4
- compact: false,
5
- destination: '',
6
- eventName(eventName) {
7
- return eventName;
8
- },
9
- importerComponent(context) {
10
- return `YOUR_CORE_PACKAGE_NAME#${context.componentClassName}`;
11
- },
12
- importerComponentType(context) {
13
- return `YOUR_CORE_PACKAGE_NAME#JSX.${context.componentClassName}`;
14
- }
15
- };
3
+ export const CUSTOM_ELEMENT_REACT_OPTIONS = {};
16
4
  export const customElementReact = (options) => {
17
5
  const name = 'customElementReact';
18
- options = Object.assign({}, defaults, options);
6
+ options = Object.assign({}, CUSTOM_ELEMENT_REACT_OPTIONS, options);
19
7
  const finish = (global) => {
20
8
  // TODO
21
9
  const globalNew = {
@@ -25,28 +13,19 @@ export const customElementReact = (options) => {
25
13
  const config = { cwd: __dirname(import.meta.url) };
26
14
  const isEmpty = isDirectoryEmpty(options.destination);
27
15
  const skip = [];
28
- const getKey = (component) => component.componentClassName;
16
+ const getKey = (component) => component.className;
29
17
  for (const key in globalNew.contexts) {
30
18
  const context = globalNew.contexts[key];
31
- const parse = (input) => {
32
- const [source, key] = input.split('#');
33
- const [root, ...sub] = key.split('.');
34
- const variable = ['Type', ...sub].join('.');
35
- return {
36
- source,
37
- variable,
38
- root
39
- };
40
- };
41
19
  const classEvents = context.classEvents.map((classEvent) => {
20
+ var _a, _b;
42
21
  const from = 'on' + pascalCase(classEvent.key.name);
43
- const to = options.eventName(from);
22
+ const to = (_b = (_a = options.eventName) === null || _a === void 0 ? void 0 : _a.call(options, from)) !== null && _b !== void 0 ? _b : from;
44
23
  return Object.assign(Object.assign({}, classEvent), { from,
45
24
  to });
46
25
  });
47
26
  const fileName = context.fileName;
48
- const importerComponent = parse(options.importerComponent(context));
49
- const importerComponentType = parse(options.importerComponentType(context));
27
+ const importerComponent = options.importerComponent(context);
28
+ const importerComponentType = options.importerComponentType(context);
50
29
  const state = Object.assign(Object.assign({}, context), { classEvents,
51
30
  fileName,
52
31
  importerComponent,
@@ -77,26 +56,14 @@ export const customElementReact = (options) => {
77
56
  .reverse()
78
57
  .map((component, index) => {
79
58
  const componentClassNameInCategory = getKey(component).replace(group.key, '');
80
- const parse = (input) => {
81
- const [source, key] = input.split('#');
82
- const [root, ...sub] = key.split('.');
83
- const local = root + (index + 1);
84
- const variable = [local, ...sub].join('.');
85
- return {
86
- source,
87
- variable,
88
- root,
89
- local
90
- };
91
- };
92
- const importerComponent = parse(options.importerComponent(component));
93
- const importerComponentType = parse(options.importerComponentType(component));
59
+ const importerComponent = options.importerComponent(component);
60
+ const importerComponentType = options.importerComponentType(component);
94
61
  return Object.assign(Object.assign({}, component), { componentClassNameInCategory,
95
62
  importerComponent,
96
63
  importerComponentType });
97
64
  })
98
65
  // TODO: experimental
99
- .sort((a, b) => (b.componentClassName < a.componentClassName ? 0 : -1));
66
+ .sort((a, b) => (getKey(b) < getKey(a) ? 0 : -1));
100
67
  return {
101
68
  all,
102
69
  filterd: all.slice(1),
@@ -3,13 +3,16 @@
3
3
  **************************************************/
4
4
 
5
5
  {{#each all}}
6
- import { {{componentClassNamePrune}} } from './{{fileName}}';
6
+ import { {{className}} } from './{{fileName}}';
7
7
  {{/each}}
8
8
 
9
- const All = Object.assign({{root.componentClassNamePrune}}, {
10
- {{#each filterd}}
11
- {{componentClassNameInCategory}}: {{componentClassNamePrune}},
12
- {{/each}}
13
- });
9
+ const All = Object.assign(
10
+ {{root.className}},
11
+ {
12
+ {{#each filterd}}
13
+ {{componentClassNameInCategory}}: {{className}},
14
+ {{/each}}
15
+ }
16
+ );
14
17
 
15
- export { All as {{root.componentClassNamePrune}} }
18
+ export { All as {{root.className}} }
@@ -3,19 +3,18 @@
3
3
  **************************************************/
4
4
 
5
5
  import { proxy } from '../proxy';
6
+ import type { Rename } from '../proxy';
6
7
 
7
8
  import '{{importerComponent.source}}';
8
- import type { {{importerComponentType.root}} as Type } from '{{importerComponentType.source}}';
9
+ import type { {{importerComponentType.imported}} as {{importerComponentType.local}} } from '{{importerComponentType.source}}';
9
10
 
10
- type Rename<T, R extends { [K in keyof R]: K extends keyof T ? PropertyKey : "Error: key not in T" }> = { [P in keyof T as P extends keyof R ? R[P] : P]: T[P] }
11
-
12
- type Renamed = Rename<{{importerComponentType.variable}}, {
11
+ type Renamed = Rename<{{importerComponentType.local}}, {
13
12
  {{#each classEvents}}
14
13
  {{from}}: '{{to}}',
15
14
  {{/each}}
16
15
  }>
17
16
 
18
- export const {{componentClassNamePrune}} = proxy<{{componentInterfaceName}}, Renamed>(
17
+ export const {{className}} = proxy<{{componentInterfaceName}}, Renamed>(
19
18
  '{{componentTag}}',
20
19
  [{{#each classProperties}}'{{key.name}}', {{/each}}],
21
20
  [{{#each classEvents}}'{{key.name}}', {{/each}}],