p-elements-core 1.2.30 → 1.2.32-rc-10

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 (82) hide show
  1. package/.editorconfig +17 -17
  2. package/.gitlab-ci.yml +18 -18
  3. package/CHANGELOG.md +201 -0
  4. package/demo/sample.js +1 -1
  5. package/demo/screen.css +16 -16
  6. package/demo/theme.css +1 -0
  7. package/dist/p-elements-core-modern.js +1 -1
  8. package/dist/p-elements-core.js +1 -1
  9. package/docs/package-lock.json +6897 -6897
  10. package/docs/package.json +27 -27
  11. package/docs/src/404.md +8 -8
  12. package/docs/src/_data/demos/hello-world/hello-world.tsx +35 -35
  13. package/docs/src/_data/demos/hello-world/index.html +10 -10
  14. package/docs/src/_data/demos/hello-world/project.json +7 -7
  15. package/docs/src/_data/demos/timer/demo-timer.tsx +120 -120
  16. package/docs/src/_data/demos/timer/icons.tsx +62 -62
  17. package/docs/src/_data/demos/timer/index.html +12 -12
  18. package/docs/src/_data/demos/timer/project.json +8 -8
  19. package/docs/src/_data/global.js +13 -13
  20. package/docs/src/_data/helpers.js +19 -19
  21. package/docs/src/_includes/layouts/base.njk +30 -30
  22. package/docs/src/_includes/layouts/playground.njk +40 -40
  23. package/docs/src/_includes/partials/app-header.njk +8 -8
  24. package/docs/src/_includes/partials/head.njk +14 -14
  25. package/docs/src/_includes/partials/nav.njk +19 -19
  26. package/docs/src/_includes/partials/top-nav.njk +51 -51
  27. package/docs/src/documentation/custom-element.md +221 -221
  28. package/docs/src/documentation/decorators/bind.md +71 -71
  29. package/docs/src/documentation/decorators/custom-element-config.md +63 -63
  30. package/docs/src/documentation/decorators/property.md +83 -83
  31. package/docs/src/documentation/decorators/query.md +66 -66
  32. package/docs/src/documentation/decorators/render-property-on-set.md +60 -60
  33. package/docs/src/documentation/decorators.md +9 -9
  34. package/docs/src/documentation/reactive-properties.md +53 -53
  35. package/docs/src/index.d.ts +25 -25
  36. package/docs/src/index.md +3 -3
  37. package/docs/src/scripts/components/app-mode-switch/app-mode-switch.css +78 -78
  38. package/docs/src/scripts/components/app-mode-switch/app-mode-switch.tsx +166 -166
  39. package/docs/src/scripts/components/app-playground/app-playground.tsx +189 -189
  40. package/docs/tsconfig.json +22 -22
  41. package/index.html +15 -2
  42. package/p-elements-core.d.ts +12 -3
  43. package/package.json +11 -4
  44. package/readme.md +206 -206
  45. package/src/custom-element-controller.test.ts +226 -0
  46. package/src/custom-element-controller.ts +31 -31
  47. package/src/custom-element.test.ts +906 -0
  48. package/src/custom-element.ts +471 -188
  49. package/src/custom-style-element.ts +4 -1
  50. package/src/decorators/bind.test.ts +163 -0
  51. package/src/decorators/bind.ts +46 -46
  52. package/src/decorators/custom-element-config.ts +17 -17
  53. package/src/decorators/property.test.ts +279 -0
  54. package/src/decorators/property.ts +822 -150
  55. package/src/decorators/query.test.ts +146 -0
  56. package/src/decorators/query.ts +12 -12
  57. package/src/decorators/render-property-on-set.ts +3 -3
  58. package/src/helpers/css.test.ts +150 -0
  59. package/src/helpers/css.ts +71 -71
  60. package/src/maquette/cache.test.ts +150 -0
  61. package/src/maquette/cache.ts +35 -35
  62. package/src/maquette/dom.test.ts +263 -0
  63. package/src/maquette/dom.ts +115 -115
  64. package/src/maquette/h.test.ts +165 -0
  65. package/src/maquette/h.ts +100 -100
  66. package/src/maquette/index.ts +12 -12
  67. package/src/maquette/interfaces.ts +536 -536
  68. package/src/maquette/jsx.ts +61 -61
  69. package/src/maquette/mapping.test.ts +294 -0
  70. package/src/maquette/mapping.ts +56 -56
  71. package/src/maquette/maquette.test.ts +493 -0
  72. package/src/maquette/projection.test.ts +366 -0
  73. package/src/maquette/projection.ts +666 -666
  74. package/src/maquette/projector.test.ts +351 -0
  75. package/src/maquette/projector.ts +200 -200
  76. package/src/sample/mixin/highlight.tsx +33 -32
  77. package/src/sample/sample.tsx +167 -7
  78. package/src/test-setup.ts +85 -0
  79. package/src/test-utils.ts +223 -0
  80. package/tsconfig.json +1 -0
  81. package/vitest.config.ts +41 -0
  82. package/webpack.config.js +1 -1
@@ -1,190 +1,190 @@
1
- @CustomElementConfig({
2
- tagName: "app-playground",
3
- })
4
- export class AppPlaygroundElement extends CustomElement {
5
-
6
- static style = `
7
- :host{
8
- display: block;
9
- height: 100%;
10
- }
11
- .app-playground{
12
- height: 100%;
13
- }
14
- .app-playground-split-panel{
15
- height: 100%;
16
- }
17
- playground-preview{
18
- height: 100%;
19
- position: unset;
20
- }
21
- .app-playground-editor-container{
22
- height: 100%;
23
- display: flex;
24
- flex-direction: column;
25
- }
26
- .app-playground-editor{
27
- height: 100%;
28
- flex: 1;
29
- }
30
- `;
31
-
32
- constructor() {
33
- super();
34
- if (!this.id) {
35
- this.id = "app-playground-" + Math.floor(Math.random() * 1000);
36
- }
37
- }
38
-
39
- #initDone = false;
40
-
41
- static readonly projectorMode = "replace";
42
-
43
- #_playgroundLoaded = false;
44
-
45
- get #playgroundLoaded() {
46
- return this.#_playgroundLoaded;
47
- }
48
-
49
- set #playgroundLoaded(value: boolean) {
50
- this.#_playgroundLoaded = value;
51
- this.scheduleRender();
52
- }
53
-
54
- @Property({ type: "string", attribute: "playground-src", reflect: true })
55
- playgroundSrc: string = null;
56
-
57
- @Property({ type: "string", attribute: "project-src", reflect: true })
58
- projectSrc: string = null;
59
-
60
- @Property({ type: "object" })
61
- files: any = null;
62
-
63
- @Property({ type: "string", attribute: "cdn-base-url", reflect: true })
64
- cdnBaseUrl: string = null;
65
-
66
- updated(propertyName: string, oldValue: any, newValue: any): void {
67
- if (propertyName === "projectSrc" && newValue) {
68
- this.#loadProject(newValue);
69
- }
70
- }
71
-
72
- async #loadProject(projectSrc: string) {
73
- const response = await fetch(projectSrc).catch((e) => e);
74
- if (response instanceof Error || !response.ok) {
75
- console.error("Failed to load project:", response);
76
- return;
77
- }
78
- const data = await response.json();
79
- if (!data) {
80
- console.error("Failed to load project: no data");
81
- return;
82
- }
83
- const configuredFiles: string[] = [];
84
- for (const key in data.files) {
85
- configuredFiles.push(key);
86
- }
87
- const url = new URL(projectSrc, window.location.href);
88
- const projectPath = url.pathname.substring(
89
- 0,
90
- url.pathname.lastIndexOf("/") + 1
91
- );
92
- const fileResponses = await Promise.all(
93
- configuredFiles.map((file: string) => {
94
- const filePath = projectPath + file;
95
- return fetch(filePath)
96
- .then((response) =>
97
- response.ok
98
- ? response.text()
99
- : Promise.reject(Error(response.statusText))
100
- )
101
- .catch((e) => e);
102
- })
103
- );
104
- const files: any = [];
105
- fileResponses.forEach((fileResponse: string | Error, index) => {
106
- if (!(fileResponse instanceof Error)) {
107
- const file = configuredFiles[index];
108
- files.push({
109
- name: file,
110
- content: fileResponse,
111
- });
112
- }
113
- });
114
- this.files = files;
115
- }
116
-
117
- #afterCreate = (e: HTMLDivElement) => {
118
- const esm = this.playgroundSrc;
119
- if (!esm) return;
120
- import(esm)
121
- .then(() => {
122
- this.#playgroundLoaded = true;
123
- })
124
- .catch((error) => {
125
- console.error("Failed to load module:", error);
126
- });
127
- };
128
-
129
- #getType = (file: string) => {
130
- if (file.endsWith(".html")) {
131
- return "sample/html";
132
- } else if (file.endsWith(".tsx") || file.endsWith(".ts")) {
133
- return "sample/ts";
134
- }
135
- return "sample/unknown";
136
- };
137
-
138
- render = () => {
139
- return (
140
- <div afterCreate={this.#afterCreate} class="app-playground">
141
-
142
- <app-split-panel class="app-playground-split-panel">
143
- {this.#playgroundLoaded && (
144
- [
145
- <playground-project
146
- class="app-playground-project"
147
- cdn-base-url={
148
- this.cdnBaseUrl ? this.cdnBaseUrl : "https://cdn.jsdelivr.net/npm"
149
- }
150
- id={"project" + this.id}
151
- >
152
- {this.files?.map((file: any) => {
153
- return (
154
- <script
155
- key={file.name}
156
- type={this.#getType(file.name)}
157
- filename={file.name}
158
- innerHTML={file.content}
159
- ></script>
160
- );
161
- })}
162
- </playground-project>,<playground-preview
163
- slot="primary"
164
- class="app-playground-preview"
165
- project={"project" + this.id}
166
- ></playground-preview>]
167
- )}
168
- <div slot="secondary" class="app-playground-editor-container">
169
- {this.#playgroundLoaded && (
170
- <playground-tab-bar
171
- class="app-playground-tab-bar"
172
- id={"tab-bar" + this.id}
173
- project={"project" + this.id}
174
- editor={"editor" + this.id}
175
- ></playground-tab-bar>
176
- )}
177
- {this.#playgroundLoaded && (
178
- <playground-file-editor
179
- class="app-playground-editor"
180
- id={"editor" + this.id}
181
- project={"project" + this.id}
182
- ></playground-file-editor>
183
- )}
184
- </div>
185
-
186
- </app-split-panel>
187
- </div>
188
- );
189
- };
1
+ @CustomElementConfig({
2
+ tagName: "app-playground",
3
+ })
4
+ export class AppPlaygroundElement extends CustomElement {
5
+
6
+ static style = `
7
+ :host{
8
+ display: block;
9
+ height: 100%;
10
+ }
11
+ .app-playground{
12
+ height: 100%;
13
+ }
14
+ .app-playground-split-panel{
15
+ height: 100%;
16
+ }
17
+ playground-preview{
18
+ height: 100%;
19
+ position: unset;
20
+ }
21
+ .app-playground-editor-container{
22
+ height: 100%;
23
+ display: flex;
24
+ flex-direction: column;
25
+ }
26
+ .app-playground-editor{
27
+ height: 100%;
28
+ flex: 1;
29
+ }
30
+ `;
31
+
32
+ constructor() {
33
+ super();
34
+ if (!this.id) {
35
+ this.id = "app-playground-" + Math.floor(Math.random() * 1000);
36
+ }
37
+ }
38
+
39
+ #initDone = false;
40
+
41
+ static readonly projectorMode = "replace";
42
+
43
+ #_playgroundLoaded = false;
44
+
45
+ get #playgroundLoaded() {
46
+ return this.#_playgroundLoaded;
47
+ }
48
+
49
+ set #playgroundLoaded(value: boolean) {
50
+ this.#_playgroundLoaded = value;
51
+ this.scheduleRender();
52
+ }
53
+
54
+ @Property({ type: "string", attribute: "playground-src", reflect: true })
55
+ playgroundSrc: string = null;
56
+
57
+ @Property({ type: "string", attribute: "project-src", reflect: true })
58
+ projectSrc: string = null;
59
+
60
+ @Property({ type: "object" })
61
+ files: any = null;
62
+
63
+ @Property({ type: "string", attribute: "cdn-base-url", reflect: true })
64
+ cdnBaseUrl: string = null;
65
+
66
+ updated(propertyName: string, oldValue: any, newValue: any): void {
67
+ if (propertyName === "projectSrc" && newValue) {
68
+ this.#loadProject(newValue);
69
+ }
70
+ }
71
+
72
+ async #loadProject(projectSrc: string) {
73
+ const response = await fetch(projectSrc).catch((e) => e);
74
+ if (response instanceof Error || !response.ok) {
75
+ console.error("Failed to load project:", response);
76
+ return;
77
+ }
78
+ const data = await response.json();
79
+ if (!data) {
80
+ console.error("Failed to load project: no data");
81
+ return;
82
+ }
83
+ const configuredFiles: string[] = [];
84
+ for (const key in data.files) {
85
+ configuredFiles.push(key);
86
+ }
87
+ const url = new URL(projectSrc, window.location.href);
88
+ const projectPath = url.pathname.substring(
89
+ 0,
90
+ url.pathname.lastIndexOf("/") + 1
91
+ );
92
+ const fileResponses = await Promise.all(
93
+ configuredFiles.map((file: string) => {
94
+ const filePath = projectPath + file;
95
+ return fetch(filePath)
96
+ .then((response) =>
97
+ response.ok
98
+ ? response.text()
99
+ : Promise.reject(Error(response.statusText))
100
+ )
101
+ .catch((e) => e);
102
+ })
103
+ );
104
+ const files: any = [];
105
+ fileResponses.forEach((fileResponse: string | Error, index) => {
106
+ if (!(fileResponse instanceof Error)) {
107
+ const file = configuredFiles[index];
108
+ files.push({
109
+ name: file,
110
+ content: fileResponse,
111
+ });
112
+ }
113
+ });
114
+ this.files = files;
115
+ }
116
+
117
+ #afterCreate = (e: HTMLDivElement) => {
118
+ const esm = this.playgroundSrc;
119
+ if (!esm) return;
120
+ import(esm)
121
+ .then(() => {
122
+ this.#playgroundLoaded = true;
123
+ })
124
+ .catch((error) => {
125
+ console.error("Failed to load module:", error);
126
+ });
127
+ };
128
+
129
+ #getType = (file: string) => {
130
+ if (file.endsWith(".html")) {
131
+ return "sample/html";
132
+ } else if (file.endsWith(".tsx") || file.endsWith(".ts")) {
133
+ return "sample/ts";
134
+ }
135
+ return "sample/unknown";
136
+ };
137
+
138
+ render = () => {
139
+ return (
140
+ <div afterCreate={this.#afterCreate} class="app-playground">
141
+
142
+ <app-split-panel class="app-playground-split-panel">
143
+ {this.#playgroundLoaded && (
144
+ [
145
+ <playground-project
146
+ class="app-playground-project"
147
+ cdn-base-url={
148
+ this.cdnBaseUrl ? this.cdnBaseUrl : "https://cdn.jsdelivr.net/npm"
149
+ }
150
+ id={"project" + this.id}
151
+ >
152
+ {this.files?.map((file: any) => {
153
+ return (
154
+ <script
155
+ key={file.name}
156
+ type={this.#getType(file.name)}
157
+ filename={file.name}
158
+ innerHTML={file.content}
159
+ ></script>
160
+ );
161
+ })}
162
+ </playground-project>,<playground-preview
163
+ slot="primary"
164
+ class="app-playground-preview"
165
+ project={"project" + this.id}
166
+ ></playground-preview>]
167
+ )}
168
+ <div slot="secondary" class="app-playground-editor-container">
169
+ {this.#playgroundLoaded && (
170
+ <playground-tab-bar
171
+ class="app-playground-tab-bar"
172
+ id={"tab-bar" + this.id}
173
+ project={"project" + this.id}
174
+ editor={"editor" + this.id}
175
+ ></playground-tab-bar>
176
+ )}
177
+ {this.#playgroundLoaded && (
178
+ <playground-file-editor
179
+ class="app-playground-editor"
180
+ id={"editor" + this.id}
181
+ project={"project" + this.id}
182
+ ></playground-file-editor>
183
+ )}
184
+ </div>
185
+
186
+ </app-split-panel>
187
+ </div>
188
+ );
189
+ };
190
190
  }
@@ -1,22 +1,22 @@
1
- {
2
- "compilerOptions": {
3
- "experimentalDecorators": true,
4
- "target": "ES6",
5
- "useDefineForClassFields": false,
6
- "module": "ES2020",
7
- "lib": ["ES2020", "DOM", "dom.iterable"],
8
- "jsx": "react",
9
- "jsxFactory": "Maquette.h",
10
- "moduleResolution": "Node",
11
- "strict": true,
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "esModuleInterop": true,
15
- "noUnusedLocals": false,
16
- "noUnusedParameters": false,
17
- "noImplicitReturns": true,
18
- "skipLibCheck": true,
19
- "strictNullChecks": false
20
- },
21
- "include": ["src"]
22
- }
1
+ {
2
+ "compilerOptions": {
3
+ "experimentalDecorators": true,
4
+ "target": "ES6",
5
+ "useDefineForClassFields": false,
6
+ "module": "ES2020",
7
+ "lib": ["ES2020", "DOM", "dom.iterable"],
8
+ "jsx": "react",
9
+ "jsxFactory": "Maquette.h",
10
+ "moduleResolution": "Node",
11
+ "strict": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "esModuleInterop": true,
15
+ "noUnusedLocals": false,
16
+ "noUnusedParameters": false,
17
+ "noImplicitReturns": true,
18
+ "skipLibCheck": true,
19
+ "strictNullChecks": false
20
+ },
21
+ "include": ["src"]
22
+ }
package/index.html CHANGED
@@ -10,8 +10,21 @@
10
10
  </head>
11
11
  <body>
12
12
 
13
+ <bring-your-own-projector></bring-your-own-projector>
13
14
 
14
- <h1>Sample custom element 1</h1>
15
+ <hr />
16
+
17
+ <bring-your-own-projector-in-shadow-root></bring-your-own-projector-in-shadow-root>
18
+
19
+ <hr />
20
+
21
+ <render-on-set></render-on-set>
22
+
23
+ <hr />
24
+
25
+ <p-bugs-03></p-bugs-03>
26
+
27
+ <hr />
15
28
 
16
29
  <p-foo id="X1" name="Fred" age="64"></p-foo>
17
30
 
@@ -41,6 +54,6 @@
41
54
  <script type="module" src="dist/p-elements-core-modern.js"></script>
42
55
  <script type="module" src="demo/sample.js"></script>
43
56
 
44
-
57
+
45
58
  </body>
46
59
  </html>
@@ -1,11 +1,10 @@
1
1
  /// <reference types="underscore" />
2
2
  /// <reference types="@types/animejs" />
3
3
 
4
- export namespace JSX {
4
+ declare namespace JSX {
5
5
  interface IntrinsicElements {
6
6
  [tagName: string]: VNodeProperties;
7
7
  }
8
- type Element = VNode;
9
8
  }
10
9
 
11
10
  declare interface IElementConfig {
@@ -293,7 +292,17 @@ interface AttributeConverter<T> {
293
292
  fromAttribute?(value: string | null): T;
294
293
  toAttribute?(value: T): string;
295
294
  }
296
- declare type PropertyType = "string" | "number" | "boolean" | "object";
295
+ declare type PropertyType = "string"
296
+ | "number"
297
+ | "boolean"
298
+ | "object"
299
+ | "array"
300
+ | StringConstructor
301
+ | NumberConstructor
302
+ | BooleanConstructor
303
+ | ObjectConstructor
304
+ | ArrayConstructor;
305
+
297
306
 
298
307
  declare const Property: (options?: {
299
308
  attribute?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "p-elements-core",
3
- "version": "1.2.30",
3
+ "version": "1.2.32-rc-10",
4
4
  "description": "P Elements Core V1",
5
5
  "main": "dist/p-elements-core.js",
6
6
  "types": "p-elements-core.d.ts",
@@ -9,7 +9,10 @@
9
9
  "url": "gitlab.com:p-elements/p-element-core.git"
10
10
  },
11
11
  "scripts": {
12
- "test": "echo \"Error: no test specified\" && exit 1",
12
+ "test": "vitest --run",
13
+ "test:watch": "vitest --ui",
14
+ "test:ui": "vitest --ui",
15
+ "test:coverage": "vitest --coverage --run",
13
16
  "dev-docs": "rimraf ./docs/public && cd docs && npm run dev",
14
17
  "clean": "rimraf ./dist",
15
18
  "build-old": "webpack --config older-browsers-webpack.config.js --mode=production",
@@ -24,6 +27,9 @@
24
27
  "@babel/preset-react": "=7.24.7",
25
28
  "@types/animejs": "^3.1.12",
26
29
  "@types/underscore": "^1.11.15",
30
+ "@vitest/browser-playwright": "^4.0.0",
31
+ "@vitest/coverage-v8": "^4.0.0",
32
+ "@vitest/ui": "^4.0.0",
27
33
  "@webreflection/custom-elements-builtin": "^0.4.1",
28
34
  "animejs": "=2.2.0",
29
35
  "babel-loader": "^8.2.3",
@@ -34,8 +40,9 @@
34
40
  "terser-webpack-plugin": "^5.3.0",
35
41
  "ts-loader": "^9.2.6",
36
42
  "typescript": "^5.4.3",
37
- "underscore": "=1.13.1",
38
- "webpack": "=5.65.0",
43
+ "underscore": "=1.13.8",
44
+ "vitest": "^4.0.0",
45
+ "webpack": "^5.105.0",
39
46
  "webpack-cli": "=4.9.1"
40
47
  }
41
48
  }