@playcanvas/web-components 0.14.0 → 0.16.0

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/src/entity.ts CHANGED
@@ -4,6 +4,33 @@ import { Entity, Vec3 } from 'playcanvas';
4
4
  import { EntityBaseElement, POINTER_ATTRIBUTES } from './entity-base';
5
5
  import { parseBool, parseTags, parseVec3 } from './parse';
6
6
 
7
+ /**
8
+ * Creates and parents the entities of every descendant `<pc-entity>` of `root`, in two passes so
9
+ * that no parent's existence depends on document order. Called wherever a subtree could not build
10
+ * itself: an element inserted into an application that is already running, and a `<pc-node>` whose
11
+ * children waited for it to bind.
12
+ *
13
+ * Descendants that are not yet custom elements are skipped, because there is nothing useful to do
14
+ * for them and reaching for `_createEntity` would throw. A subtree cloned from a `<template>`
15
+ * arrives entirely unupgraded — template content lives in an inert document, where custom element
16
+ * definitions are never looked up — and appending the clone upgrades its elements in tree order,
17
+ * an element before its descendants. So a sweep from an element's own `connectedCallback` sees
18
+ * plain `HTMLElement`s below it. Each becomes an `EntityElement` moments later and its own
19
+ * `connectedCallback` creates and parents it, by which time the ancestor it parents under has its
20
+ * entity — the same guarantee tree order gives this sweep.
21
+ *
22
+ * @param root - The element whose descendant entities to build.
23
+ * @param app - The application to create the entities in.
24
+ * @internal
25
+ */
26
+ export const buildDescendantEntities = (root: Element, app: AppBase) => {
27
+ const children = Array.from(root.querySelectorAll('pc-entity')).filter(
28
+ (child): child is EntityElement => child instanceof EntityElement
29
+ );
30
+ children.forEach((child) => child._createEntity(app));
31
+ children.forEach((child) => child._buildHierarchy(app));
32
+ };
33
+
7
34
  /**
8
35
  * The EntityElement interface provides properties and methods for manipulating
9
36
  * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-entity/ | `<pc-entity>`} elements.
@@ -172,13 +199,7 @@ class EntityElement extends EntityBaseElement {
172
199
  this._buildHierarchy(app);
173
200
 
174
201
  // Handle any child entities that might exist
175
- const childEntities = this.querySelectorAll<EntityElement>('pc-entity');
176
- childEntities.forEach((child) => {
177
- child._createEntity(app);
178
- });
179
- childEntities.forEach((child) => {
180
- child._buildHierarchy(app);
181
- });
202
+ buildDescendantEntities(this, app);
182
203
  }
183
204
  }
184
205
 
package/src/index.ts CHANGED
@@ -15,12 +15,15 @@ import { ModuleElement } from './module';
15
15
  import { AppElement } from './app';
16
16
  import { EntityElement } from './entity';
17
17
  import { AssetElement } from './asset';
18
+ import { AnimComponentElement } from './components/anim-component';
19
+ import { AnimClipElement } from './components/anim-clip';
18
20
  import { ListenerComponentElement } from './components/listener-component';
19
21
  import { ButtonComponentElement } from './components/button-component';
20
22
  import { CameraComponentElement } from './components/camera-component';
21
23
  import { CollisionComponentElement } from './components/collision-component';
22
24
  import { ComponentElement } from './components/component';
23
25
  import { ElementComponentElement } from './components/element-component';
26
+ import { JointComponentElement } from './components/joint-component';
24
27
  import { LayoutChildComponentElement } from './components/layoutchild-component';
25
28
  import { LayoutGroupComponentElement } from './components/layoutgroup-component';
26
29
  import { LightComponentElement } from './components/light-component';
@@ -50,12 +53,15 @@ import type {
50
53
 
51
54
  declare global {
52
55
  interface HTMLElementEventMap {
56
+ break: CustomEvent;
53
57
  scriptattributeschange: ScriptAttributesChangeEvent;
54
58
  scriptenablechange: ScriptEnableChangeEvent;
55
59
  scriptnamechange: ScriptNameChangeEvent;
56
60
  }
57
61
 
58
62
  interface HTMLElementTagNameMap {
63
+ 'pc-anim': AnimComponentElement;
64
+ 'pc-anim-clip': AnimClipElement;
59
65
  'pc-app': AppElement;
60
66
  'pc-asset': AssetElement;
61
67
  'pc-button': ButtonComponentElement;
@@ -64,6 +70,7 @@ declare global {
64
70
  'pc-element': ElementComponentElement;
65
71
  'pc-entity': EntityElement;
66
72
  'pc-gsplat': GSplatComponentElement;
73
+ 'pc-joint': JointComponentElement;
67
74
  'pc-layoutchild': LayoutChildComponentElement;
68
75
  'pc-layoutgroup': LayoutGroupComponentElement;
69
76
  'pc-light': LightComponentElement;
@@ -93,11 +100,14 @@ export {
93
100
  AppElement,
94
101
  EntityElement,
95
102
  AssetElement,
103
+ AnimComponentElement,
104
+ AnimClipElement,
96
105
  ButtonComponentElement,
97
106
  CameraComponentElement,
98
107
  CollisionComponentElement,
99
108
  ComponentElement,
100
109
  ElementComponentElement,
110
+ JointComponentElement,
101
111
  LayoutChildComponentElement,
102
112
  LayoutGroupComponentElement,
103
113
  ParticleSystemComponentElement,
package/src/model.ts CHANGED
@@ -252,13 +252,6 @@ class ModelElement extends AsyncElement {
252
252
  const entity = container.instantiateRenderEntity();
253
253
  this._entity = entity;
254
254
 
255
- // @ts-ignore
256
- if (container.animations.length > 0) {
257
- entity.addComponent('anim');
258
- // @ts-ignore
259
- entity.anim.assignAnimation('animation', container.animations[0].resource);
260
- }
261
-
262
255
  // The parent's readiness re-arms when it is torn down, so these can resume in a later
263
256
  // connection cycle. The entity is captured above and the generation re-checked, so a
264
257
  // stale resume cannot parent an entity a newer cycle has already destroyed.
package/src/node.ts CHANGED
@@ -2,6 +2,7 @@ import type { Entity, EventHandle, GraphNode, Material, MeshInstance, Quat, Rend
2
2
  import { Vec3 } from 'playcanvas';
3
3
 
4
4
  import { ComponentElement } from './components/component';
5
+ import { buildDescendantEntities } from './entity';
5
6
  import type { EntityElement } from './entity';
6
7
  import { EntityBaseElement, POINTER_ATTRIBUTES } from './entity-base';
7
8
  import { MaterialElement } from './material';
@@ -490,13 +491,7 @@ class NodeElement extends EntityBaseElement {
490
491
  if (!app) {
491
492
  return;
492
493
  }
493
- const childEntities = this.querySelectorAll<EntityElement>('pc-entity');
494
- childEntities.forEach((child) => {
495
- child._createEntity(app);
496
- });
497
- childEntities.forEach((child) => {
498
- child._buildHierarchy(app);
499
- });
494
+ buildDescendantEntities(this, app);
500
495
  }
501
496
 
502
497
  /**