@weaverse/core 5.17.1 → 5.18.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/dist/index.js +43 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -12
- package/dist/index.mjs.map +1 -1
- package/dist/types/core.d.ts +96 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/icon-name.d.ts +217 -0
- package/dist/types/icon-name.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +192 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/event-emitter.d.ts +16 -0
- package/dist/types/utils/event-emitter.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +23 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/package.json +5 -4
- package/src/core.ts +251 -0
- package/src/icon-name.d.ts +215 -0
- package/src/index.ts +11 -0
- package/src/types.ts +264 -0
- package/src/utils/event-emitter.ts +31 -0
- package/src/utils/index.ts +71 -0
- package/dist/index.d.mts +0 -413
- package/dist/index.d.ts +0 -413
package/dist/index.mjs
CHANGED
|
@@ -1453,7 +1453,7 @@ var require_react = __commonJS({
|
|
|
1453
1453
|
var import_react = __toESM(require_react());
|
|
1454
1454
|
|
|
1455
1455
|
// package.json
|
|
1456
|
-
var version = "5.
|
|
1456
|
+
var version = "5.18.0";
|
|
1457
1457
|
|
|
1458
1458
|
// src/utils/index.ts
|
|
1459
1459
|
var isReactNative = typeof navigator === "object" && navigator.product === "ReactNative";
|
|
@@ -1497,17 +1497,22 @@ function loadScript(src) {
|
|
|
1497
1497
|
|
|
1498
1498
|
// src/utils/event-emitter.ts
|
|
1499
1499
|
var EventEmitter = class {
|
|
1500
|
+
/** Functions called when an update is emitted. */
|
|
1500
1501
|
listeners;
|
|
1502
|
+
/** Creates an emitter with no listeners. */
|
|
1501
1503
|
constructor() {
|
|
1502
1504
|
this.listeners = /* @__PURE__ */ new Set();
|
|
1503
1505
|
}
|
|
1506
|
+
/** Adds a listener and returns a function that removes it. */
|
|
1504
1507
|
subscribe = (fn) => {
|
|
1505
1508
|
this.listeners.add(fn);
|
|
1506
1509
|
return () => this.unsubscribe(fn);
|
|
1507
1510
|
};
|
|
1511
|
+
/** Removes a previously subscribed listener. */
|
|
1508
1512
|
unsubscribe = (fn) => {
|
|
1509
1513
|
this.listeners.delete(fn);
|
|
1510
1514
|
};
|
|
1515
|
+
/** Calls every subscribed listener with the supplied data. */
|
|
1511
1516
|
emit = (data) => {
|
|
1512
1517
|
for (const fn of this.listeners) {
|
|
1513
1518
|
fn(data);
|
|
@@ -1517,9 +1522,13 @@ var EventEmitter = class {
|
|
|
1517
1522
|
|
|
1518
1523
|
// src/core.ts
|
|
1519
1524
|
var WeaverseItemStore = class extends EventEmitter {
|
|
1525
|
+
/** The Core runtime that owns this item. */
|
|
1520
1526
|
weaverse;
|
|
1527
|
+
/** React ref for the element's rendered HTML node. */
|
|
1521
1528
|
ref = (0, import_react.createRef)();
|
|
1529
|
+
/** The current serialized state of the element. */
|
|
1522
1530
|
_store = { id: "", type: "" };
|
|
1531
|
+
/** Creates an item store and registers it with the owning runtime. */
|
|
1523
1532
|
constructor(initialData, weaverse) {
|
|
1524
1533
|
super();
|
|
1525
1534
|
const { type, id } = initialData || {};
|
|
@@ -1534,53 +1543,77 @@ var WeaverseItemStore = class extends EventEmitter {
|
|
|
1534
1543
|
}
|
|
1535
1544
|
this._store.css = this.getDefaultCss();
|
|
1536
1545
|
}
|
|
1546
|
+
/** The element's unique identifier. */
|
|
1537
1547
|
get _id() {
|
|
1538
1548
|
return this._store.id;
|
|
1539
1549
|
}
|
|
1550
|
+
/** The element's current rendered HTML node, if mounted. */
|
|
1540
1551
|
get _element() {
|
|
1541
1552
|
return this.ref.current;
|
|
1542
1553
|
}
|
|
1554
|
+
/** The registered component definition for this element type. */
|
|
1543
1555
|
get Element() {
|
|
1544
1556
|
return this.weaverse.elementRegistry.get(this._store.type);
|
|
1545
1557
|
}
|
|
1558
|
+
/** Returns registered default styles merged with the element's saved styles. */
|
|
1546
1559
|
getDefaultCss = () => {
|
|
1547
1560
|
const defaultCss = this.Element?.defaultCss || {};
|
|
1548
1561
|
const currentCss = this._store.css || {};
|
|
1549
1562
|
return merge(defaultCss, currentCss);
|
|
1550
1563
|
};
|
|
1564
|
+
/**
|
|
1565
|
+
* The element's current serialized data. Assigning a value merges it into
|
|
1566
|
+
* the existing data.
|
|
1567
|
+
*/
|
|
1551
1568
|
get data() {
|
|
1552
1569
|
return this._store;
|
|
1553
1570
|
}
|
|
1571
|
+
// Setter behavior is documented on the getter, which owns the property's JSDoc.
|
|
1554
1572
|
set data(update) {
|
|
1555
1573
|
this._store = { ...this._store, ...update };
|
|
1556
1574
|
}
|
|
1575
|
+
/** Applies an element data update and notifies subscribers. */
|
|
1557
1576
|
setData = (update) => {
|
|
1558
1577
|
this.data = update;
|
|
1559
1578
|
this.triggerUpdate();
|
|
1560
1579
|
return this.data;
|
|
1561
1580
|
};
|
|
1581
|
+
/** Returns the element's current serialized data. */
|
|
1562
1582
|
getSnapShot = () => this.data;
|
|
1583
|
+
/** Notifies subscribers with the element's current data. */
|
|
1563
1584
|
triggerUpdate = () => {
|
|
1564
1585
|
this.emit(this._store);
|
|
1565
1586
|
};
|
|
1566
1587
|
};
|
|
1567
1588
|
var Weaverse = class _Weaverse extends EventEmitter {
|
|
1589
|
+
/** The DOM node containing the rendered project, if mounted. */
|
|
1568
1590
|
contentRootElement = null;
|
|
1591
|
+
/** Item stores keyed by element identifier. */
|
|
1569
1592
|
static itemInstances = /* @__PURE__ */ new Map();
|
|
1593
|
+
/** Base URL of the Weaverse Studio host. */
|
|
1570
1594
|
weaverseHost = "https://studio.weaverse.io";
|
|
1595
|
+
/** Version of the Weaverse runtime. */
|
|
1571
1596
|
weaverseVersion = version;
|
|
1597
|
+
/** Version of the installed Core SDK. */
|
|
1572
1598
|
sdkVersion = version;
|
|
1599
|
+
/** Identifier of the project being rendered. */
|
|
1573
1600
|
projectId = "";
|
|
1601
|
+
/** Whether the runtime is connected to Studio design mode. */
|
|
1574
1602
|
isDesignMode = false;
|
|
1603
|
+
/** Whether the runtime is rendering a preview. */
|
|
1575
1604
|
isPreviewMode = false;
|
|
1605
|
+
/** Optional bridge used to communicate with Weaverse Studio. */
|
|
1576
1606
|
studioBridge;
|
|
1607
|
+
/** Component definitions keyed by element type. */
|
|
1577
1608
|
static elementRegistry = /* @__PURE__ */ new Map();
|
|
1609
|
+
/** Media queries used for responsive element styles. */
|
|
1578
1610
|
static mediaBreakPoints = {
|
|
1579
1611
|
desktop: "all",
|
|
1580
1612
|
// max-width need to subtract 0.02px to prevent bug
|
|
1581
1613
|
// ref: https://getbootstrap.com/docs/5.1/layout/breakpoints/#max-width
|
|
1582
1614
|
mobile: "(max-width: 767.98px)"
|
|
1583
1615
|
};
|
|
1616
|
+
/** Creates a Core runtime from serialized project data. */
|
|
1584
1617
|
constructor(params) {
|
|
1585
1618
|
super();
|
|
1586
1619
|
for (const param of Object.entries(params)) {
|
|
@@ -1589,10 +1622,9 @@ var Weaverse = class _Weaverse extends EventEmitter {
|
|
|
1589
1622
|
}
|
|
1590
1623
|
this.initProject();
|
|
1591
1624
|
}
|
|
1625
|
+
/** Returns the project's current serialized data. */
|
|
1592
1626
|
getSnapShot = () => this.data;
|
|
1593
|
-
/**
|
|
1594
|
-
* Create new `WeaverseItemStore` instance for each item in the project.
|
|
1595
|
-
*/
|
|
1627
|
+
/** Creates or updates an item store for every serialized project item. */
|
|
1596
1628
|
initProject = () => {
|
|
1597
1629
|
const { data } = this;
|
|
1598
1630
|
const itemInstances = _Weaverse.itemInstances;
|
|
@@ -1607,31 +1639,30 @@ var Weaverse = class _Weaverse extends EventEmitter {
|
|
|
1607
1639
|
}
|
|
1608
1640
|
}
|
|
1609
1641
|
};
|
|
1642
|
+
/** Item stores keyed by element identifier. */
|
|
1610
1643
|
get itemInstances() {
|
|
1611
1644
|
return _Weaverse.itemInstances;
|
|
1612
1645
|
}
|
|
1646
|
+
/** Creates an item store for serialized element data. */
|
|
1613
1647
|
createItemInstance = (data) => new _Weaverse.ItemConstructor(data, this);
|
|
1614
|
-
/**
|
|
1615
|
-
* Register the custom React Component to Weaverse, store it into Weaverse.elementRegistry
|
|
1616
|
-
*/
|
|
1648
|
+
/** Registers a component definition for an element type. */
|
|
1617
1649
|
static registerElement = registerElement;
|
|
1650
|
+
/** Component definitions keyed by element type. */
|
|
1618
1651
|
get elementRegistry() {
|
|
1619
1652
|
return _Weaverse.elementRegistry;
|
|
1620
1653
|
}
|
|
1654
|
+
/** Replaces the project data reference and notifies subscribers. */
|
|
1621
1655
|
triggerUpdate = () => {
|
|
1622
1656
|
this.data = { ...this.data };
|
|
1623
1657
|
this.emit(this.data);
|
|
1624
1658
|
};
|
|
1659
|
+
/** Notifies subscribers of every registered item store. */
|
|
1625
1660
|
refreshAllItems() {
|
|
1626
1661
|
for (const item of _Weaverse.itemInstances.values()) {
|
|
1627
1662
|
item.triggerUpdate();
|
|
1628
1663
|
}
|
|
1629
1664
|
}
|
|
1630
|
-
/**
|
|
1631
|
-
* Reset the project data and re-initialize all items.
|
|
1632
|
-
* Used when we need to re-render the project with new data (like applying new template)
|
|
1633
|
-
* @param data {WeaverseProjectDataType}
|
|
1634
|
-
*/
|
|
1665
|
+
/** Replaces the project data and initializes its item stores. */
|
|
1635
1666
|
setProjectData = (data) => {
|
|
1636
1667
|
this.data = data;
|
|
1637
1668
|
this.initProject();
|