@zcomponent/core 1.18.0 → 1.19.0-beta

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.
@@ -2,7 +2,7 @@ import { ActionBehavior, ActionBehaviorConstructorProps } from '../actionbehavio
2
2
  import { Component } from '../component';
3
3
  import { ContextManager } from '../context';
4
4
  /**
5
- * Sets a leye clip to be inactive.
5
+ * Deactivates a layer
6
6
  * @zbehavior
7
7
  * @zicon toggle_off
8
8
  * @zgroup Animation Actions
@@ -1,7 +1,7 @@
1
1
  import { ActionBehavior } from '../actionbehavior';
2
2
  import { registerBehaviorRunAtDesignTime } from '../behavior';
3
3
  /**
4
- * Sets a leye clip to be inactive.
4
+ * Deactivates a layer
5
5
  * @zbehavior
6
6
  * @zicon toggle_off
7
7
  * @zgroup Animation Actions
@@ -73,6 +73,10 @@ export declare class Component<ElementType = any, ConstructorPropsType extends C
73
73
  * The parent of this component.
74
74
  */
75
75
  parent?: Component;
76
+ /**
77
+ * If true, this component can't be selected at design time in the 3D preview.
78
+ */
79
+ locked?: boolean;
76
80
  /**
77
81
  * Creates an instance of Component.
78
82
  * @param contextManager The current ContextManager
@@ -128,6 +132,10 @@ export declare class Component<ElementType = any, ConstructorPropsType extends C
128
132
  * exposed by this component's children.
129
133
  */
130
134
  get elementsResolved(): any[];
135
+ /**
136
+ * Returns true if this component, or any of its parents, are marked as locked.
137
+ */
138
+ get lockedResolved(): boolean;
131
139
  /**
132
140
  * An array of string 'tags' assocated with this component.
133
141
  *
package/lib/component.js CHANGED
@@ -159,6 +159,12 @@ export class Component extends Entity {
159
159
  }
160
160
  return ret;
161
161
  }
162
+ /**
163
+ * Returns true if this component, or any of its parents, are marked as locked.
164
+ */
165
+ get lockedResolved() {
166
+ return (this.locked ?? false) || (this.parent?.lockedResolved ?? false);
167
+ }
162
168
  /**
163
169
  * Dispose of this component and all of its children.
164
170
  */
@@ -151,6 +151,7 @@ export interface BaseTrack {
151
151
  id: string;
152
152
  type: TrackType;
153
153
  entityID: string;
154
+ nameHint?: string;
154
155
  lock?: {
155
156
  track?: boolean;
156
157
  weight?: boolean;
@@ -241,3 +241,6 @@ export interface BehaviorDataCombined extends EntityDataCombined {
241
241
  * @returns A unique label for the node.
242
242
  */
243
243
  export declare function getUniqueLabel(zcomp: ZComponentData, label: string): string;
244
+ export declare function getUniqueName(n: string, requireUniqueIn: string[] | {
245
+ [k: string]: any;
246
+ }): string;
@@ -551,7 +551,6 @@ export function forEachNodeAncestor(zcomp, id, fn) {
551
551
  fn(node.parent.id);
552
552
  forEachNodeAncestor(zcomp, node.parent.id, fn);
553
553
  }
554
- const lastNumberRegex = new RegExp(/[0-9]*$/);
555
554
  /**
556
555
  * Generates a unique label for a node in ZComponentData.
557
556
  *
@@ -560,23 +559,25 @@ const lastNumberRegex = new RegExp(/[0-9]*$/);
560
559
  * @returns A unique label for the node.
561
560
  */
562
561
  export function getUniqueLabel(zcomp, label) {
563
- lastNumberRegex.lastIndex = 0;
564
- let startIndex = 1;
565
- const result = lastNumberRegex.exec(label);
566
- if (result && result.length === 1) {
567
- const num = parseInt(result[0]);
568
- if (!isNaN(num)) {
569
- startIndex = num + 1;
570
- label = label.substring(0, result.index);
571
- }
562
+ return getUniqueName(label, zcomp.entitiesByLabel ?? {});
563
+ }
564
+ export function getUniqueName(n, requireUniqueIn) {
565
+ const existing = new Set(Array.isArray(requireUniqueIn) ? requireUniqueIn : Object.keys(requireUniqueIn));
566
+ if (n === undefined || n.length === 0) {
567
+ n = 'Item';
572
568
  }
573
- const existingLabels = zcomp.entitiesByLabel ?? {};
574
- for (let i = startIndex; i < 10000; i++) {
575
- const testName = i === 1 ? label : `${label} ${i.toString()}`;
576
- if (!Object.prototype.hasOwnProperty.call(existingLabels, testName)) {
577
- label = testName;
578
- break;
579
- }
569
+ if (!existing.has(n)) {
570
+ return n;
571
+ }
572
+ const endNumberString = n.match(/\d+$/)?.[0];
573
+ const nameString = n.slice(0, endNumberString ? endNumberString.length * -1 : undefined);
574
+ let num = parseInt(endNumberString ?? '1');
575
+ if (!isNaN(num)) {
576
+ num++;
577
+ }
578
+ const name = `${nameString}${endNumberString ? '' : ' '}${num}`;
579
+ if (existing.has(name)) {
580
+ return getUniqueName(name, requireUniqueIn);
580
581
  }
581
- return label;
582
+ return name;
582
583
  }
@@ -55,6 +55,7 @@ export interface NodeData {
55
55
  label?: string;
56
56
  scriptName?: string;
57
57
  type: ElementType;
58
+ locked?: boolean;
58
59
  parent?: {
59
60
  id: string;
60
61
  order: string;
package/lib/types.js CHANGED
@@ -146,6 +146,17 @@ export function areTypesCompatible(a, b) {
146
146
  return false;
147
147
  if (a.ret && bt.ret)
148
148
  return areTypesCompatible(a.ret, bt.ret);
149
+ break;
150
+ }
151
+ case 'event': {
152
+ const bt = b;
153
+ if (a.children.length !== bt.children.length)
154
+ return false;
155
+ for (let i = 0; i < a.children.length; i++) {
156
+ if (!areTypesCompatible(a.children[i], bt.children[i]))
157
+ return false;
158
+ }
159
+ return true;
149
160
  }
150
161
  }
151
162
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zcomponent/core",
3
- "version": "1.18.0",
3
+ "version": "1.19.0-beta",
4
4
  "description": "The core component model and built-in functionality for Mattercraft.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",