tinybase 3.1.0-beta.1 → 3.1.0-beta.2
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/bin/cli.js +1 -1
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/tools.d.ts +4 -4
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/tools.d.ts +4 -4
- package/lib/debug/tools.d.ts +4 -4
- package/lib/debug/tools.js +363 -35
- package/lib/debug/ui-react.js +2 -2
- package/lib/es6/tools.d.ts +4 -4
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/tools.d.ts +4 -4
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/umd/tools.d.ts +4 -4
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd-es6/tools.d.ts +4 -4
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/package.json +7 -7
- package/readme.md +1 -1
package/lib/debug/tools.js
CHANGED
|
@@ -114,6 +114,8 @@ const getIdsDoc = (idsNoun, parentNoun, sorted = 0) =>
|
|
|
114
114
|
parentNoun;
|
|
115
115
|
const getForEachDoc = (childNoun, parentNoun) =>
|
|
116
116
|
`Calls a function for each ${childNoun} in ` + parentNoun;
|
|
117
|
+
const getPropsDoc = (childNoun) =>
|
|
118
|
+
'The props passed to a component that renders ' + childNoun;
|
|
117
119
|
const getCallbackDoc = (takes) => 'A function that takes ' + takes;
|
|
118
120
|
const getListenerTypeDoc = (childNoun, parentNoun = 0) =>
|
|
119
121
|
A_FUNCTION_FOR +
|
|
@@ -153,6 +155,7 @@ const VERBS = [
|
|
|
153
155
|
GETS_A_CALLBACK_THAT_CAN + 'add',
|
|
154
156
|
GETS_A_CALLBACK_THAT_CAN + 'set part of',
|
|
155
157
|
GETS_A_CALLBACK_THAT_CAN + 'delete',
|
|
158
|
+
'Renders',
|
|
156
159
|
];
|
|
157
160
|
const NOUNS = [
|
|
158
161
|
THE_STORE,
|
|
@@ -543,6 +546,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
543
546
|
mapSet(tablesTypes, tableId, tableTypes);
|
|
544
547
|
addImport(1, moduleDefinition, ...tableTypes);
|
|
545
548
|
});
|
|
549
|
+
addImport(null, 'tinybase', IDS);
|
|
546
550
|
const tablesType = addType(
|
|
547
551
|
TABLES,
|
|
548
552
|
`{${join(
|
|
@@ -1163,6 +1167,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
1163
1167
|
valueIdsListenerType,
|
|
1164
1168
|
valueListenerType,
|
|
1165
1169
|
invalidValueListenerType,
|
|
1170
|
+
...collValues(mapCellOrValueTypes),
|
|
1166
1171
|
);
|
|
1167
1172
|
addImport(0, 'tinybase', 'ValueChange');
|
|
1168
1173
|
arrayPush(
|
|
@@ -1191,16 +1196,7 @@ const getStoreCoreApi = (tablesSchema, valuesSchema, module) => {
|
|
|
1191
1196
|
`Takes a ${type} Cell value and returns another`,
|
|
1192
1197
|
),
|
|
1193
1198
|
);
|
|
1194
|
-
addImport(
|
|
1195
|
-
null,
|
|
1196
|
-
'tinybase',
|
|
1197
|
-
'DoRollback',
|
|
1198
|
-
ID,
|
|
1199
|
-
'IdOrNull',
|
|
1200
|
-
IDS,
|
|
1201
|
-
JSON$1,
|
|
1202
|
-
'Store',
|
|
1203
|
-
);
|
|
1199
|
+
addImport(null, 'tinybase', 'DoRollback', ID, 'IdOrNull', JSON$1, 'Store');
|
|
1204
1200
|
const transactionListenerType = addType(
|
|
1205
1201
|
TRANSACTION + LISTENER,
|
|
1206
1202
|
`(${storeInstance}: ${storeType}, cellsTouched: boolean, valuesTouched: boolean)` +
|
|
@@ -1341,26 +1337,42 @@ const DEPS = 'Deps';
|
|
|
1341
1337
|
const getGet = (noun) => GET + noun;
|
|
1342
1338
|
const getGetAndGetDeps = (noun) =>
|
|
1343
1339
|
getParameterList(getGet(noun), getGet(noun) + DEPS);
|
|
1340
|
+
const getPropsTypeList = (...props) =>
|
|
1341
|
+
'{' +
|
|
1342
|
+
join(
|
|
1343
|
+
arrayMap(props, (prop) => 'readonly ' + prop),
|
|
1344
|
+
'; ',
|
|
1345
|
+
) +
|
|
1346
|
+
'}';
|
|
1347
|
+
const DEBUG_IDS_PROP_TYPE = 'debugIds?: boolean';
|
|
1348
|
+
const DEBUG_IDS_PROP = 'debugIds={debugIds}';
|
|
1349
|
+
const DEPS_SUFFIX = DEPS + '?: React.DependencyList';
|
|
1350
|
+
const THEN_DEPS = 'then' + DEPS_SUFFIX;
|
|
1344
1351
|
const PARAMETER = 'Parameter';
|
|
1345
1352
|
const GETTER_ARGS = ': (parameter: ' + PARAMETER + ', store: Store) => ';
|
|
1353
|
+
const PROVIDER = 'Provider';
|
|
1346
1354
|
const USE_CONTEXT = 'const contextValue = useContext(Context);';
|
|
1347
1355
|
const AND_REGISTERS =
|
|
1348
1356
|
', and registers a listener so that any changes to that result will cause a re-render';
|
|
1349
1357
|
const BASED_ON_A_PARAMETER = ', based on a parameter';
|
|
1350
1358
|
const COLON_SPACE = ': ';
|
|
1359
|
+
const OPTIONAL_COLON = '?: ';
|
|
1360
|
+
const GENERIC_PARAMETER = '<' + PARAMETER + ',>';
|
|
1351
1361
|
const PARAMETERIZED_CALLBACK =
|
|
1352
1362
|
PARAMETER + 'ized' + CALLBACK + '<' + PARAMETER + '>';
|
|
1353
|
-
const
|
|
1354
|
-
const
|
|
1355
|
-
const
|
|
1363
|
+
const PROPS = 'Props';
|
|
1364
|
+
const ROW_ID = 'rowId';
|
|
1365
|
+
const ROW_ID_PROP = 'rowId={rowId}';
|
|
1366
|
+
const SEPARATOR_AND_DEBUG_IDS = ', separator, debugIds';
|
|
1367
|
+
const SEPARATOR_PROP_TYPE = 'separator?: ReactElement | string';
|
|
1356
1368
|
const THEN_PREFIX = 'then?: (store: Store';
|
|
1357
1369
|
const THEN_AND_THEN_DEPS = getParameterList(
|
|
1358
1370
|
THEN_PREFIX + ')' + RETURNS_VOID,
|
|
1359
1371
|
THEN_DEPS,
|
|
1360
1372
|
);
|
|
1361
1373
|
const THEN_AND_THEN_DEPS_IN_CALL = 'then, then' + DEPS;
|
|
1362
|
-
const ROW_ID = 'rowId';
|
|
1363
1374
|
const TYPED_ROW_ID = ROW_ID + COLON_SPACE + ID;
|
|
1375
|
+
const VIEW = 'View';
|
|
1364
1376
|
const getListenerHookParams = (listenerType, ...extraParams) =>
|
|
1365
1377
|
getParameterList(
|
|
1366
1378
|
...extraParams,
|
|
@@ -1399,6 +1411,7 @@ const getStoreUiReactApi = (
|
|
|
1399
1411
|
const storeInstance = camel(storeType);
|
|
1400
1412
|
const StoreOrStoreId = storeType + 'Or' + storeType + ID;
|
|
1401
1413
|
const storeOrStoreId = storeInstance + 'Or' + storeType + ID;
|
|
1414
|
+
const storeProp = storeInstance + `={${storeInstance}}`;
|
|
1402
1415
|
const functions = mapNew();
|
|
1403
1416
|
const addFunction = (
|
|
1404
1417
|
name,
|
|
@@ -1412,7 +1425,7 @@ const getStoreUiReactApi = (
|
|
|
1412
1425
|
return mapUnique(functions, name, [
|
|
1413
1426
|
parameters,
|
|
1414
1427
|
returnType,
|
|
1415
|
-
|
|
1428
|
+
body,
|
|
1416
1429
|
doc,
|
|
1417
1430
|
generic,
|
|
1418
1431
|
]);
|
|
@@ -1441,7 +1454,7 @@ const getStoreUiReactApi = (
|
|
|
1441
1454
|
tinyBaseUiReact,
|
|
1442
1455
|
`use${underlyingName} as use${underlyingName}Core`,
|
|
1443
1456
|
);
|
|
1444
|
-
addHook(
|
|
1457
|
+
return addHook(
|
|
1445
1458
|
name,
|
|
1446
1459
|
getParameterList(preParameters, storeOrStoreIdParameter, postParameters),
|
|
1447
1460
|
returnType,
|
|
@@ -1449,7 +1462,7 @@ const getStoreUiReactApi = (
|
|
|
1449
1462
|
`(${storeOrStoreId}, use${underlyingName}Core, [` +
|
|
1450
1463
|
(preParametersInCall ? preParametersInCall : EMPTY_STRING) +
|
|
1451
1464
|
(postParametersInCall ? '], [' + postParametersInCall : EMPTY_STRING) +
|
|
1452
|
-
'])',
|
|
1465
|
+
']);',
|
|
1453
1466
|
doc,
|
|
1454
1467
|
generic,
|
|
1455
1468
|
);
|
|
@@ -1482,13 +1495,12 @@ const getStoreUiReactApi = (
|
|
|
1482
1495
|
null,
|
|
1483
1496
|
'tinybase',
|
|
1484
1497
|
ID,
|
|
1485
|
-
IDS,
|
|
1486
|
-
'IdOrNull',
|
|
1487
1498
|
'Store',
|
|
1488
1499
|
CALLBACK,
|
|
1489
1500
|
PARAMETER + 'ized' + CALLBACK,
|
|
1490
1501
|
);
|
|
1491
1502
|
addImport(0, tinyBaseUiReact, 'ComponentReturnType');
|
|
1503
|
+
addImport(null, tinyBaseUiReact, 'ExtraProps');
|
|
1492
1504
|
addImport(0, moduleDefinition, storeType);
|
|
1493
1505
|
const storeOrStoreIdType = addType(
|
|
1494
1506
|
StoreOrStoreId,
|
|
@@ -1496,13 +1508,20 @@ const getStoreUiReactApi = (
|
|
|
1496
1508
|
`Used when you need to refer to a ${storeType} in a React hook or component`,
|
|
1497
1509
|
);
|
|
1498
1510
|
const providerPropsType = addType(
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1511
|
+
PROVIDER + PROPS,
|
|
1512
|
+
getPropsTypeList(
|
|
1513
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1514
|
+
storeInstance + `ById?: {[${storeInstance}Id: Id]: ${storeType}}`,
|
|
1515
|
+
),
|
|
1516
|
+
`Used with the ${PROVIDER} component, so that a ` +
|
|
1517
|
+
storeType +
|
|
1518
|
+
' can be passed into the context of an application',
|
|
1502
1519
|
);
|
|
1520
|
+
addImport(0, 'react', 'ReactElement', 'ComponentType');
|
|
1503
1521
|
addImport(1, 'react', 'React');
|
|
1504
1522
|
addImport(1, uiReactModuleDefinition, storeOrStoreIdType, providerPropsType);
|
|
1505
|
-
const storeOrStoreIdParameter =
|
|
1523
|
+
const storeOrStoreIdParameter =
|
|
1524
|
+
storeOrStoreId + OPTIONAL_COLON + storeOrStoreIdType;
|
|
1506
1525
|
addConstant('{createContext, useContext, useMemo}', 'React');
|
|
1507
1526
|
addConstant(
|
|
1508
1527
|
'Context',
|
|
@@ -1520,10 +1539,12 @@ const getStoreUiReactApi = (
|
|
|
1520
1539
|
`id?: Id`,
|
|
1521
1540
|
storeType + OR_UNDEFINED,
|
|
1522
1541
|
[
|
|
1542
|
+
'{',
|
|
1523
1543
|
USE_CONTEXT,
|
|
1524
1544
|
'return id == null ? contextValue[0] : contextValue[1]?.[id];',
|
|
1545
|
+
'}',
|
|
1525
1546
|
],
|
|
1526
|
-
`Get a reference to a ${storeType} from within a
|
|
1547
|
+
`Get a reference to a ${storeType} from within a ${PROVIDER} component context`,
|
|
1527
1548
|
);
|
|
1528
1549
|
const useHook = addInternalFunction(
|
|
1529
1550
|
`useHook`,
|
|
@@ -1535,6 +1556,27 @@ const getStoreUiReactApi = (
|
|
|
1535
1556
|
`? ${storeInstance} : ${storeOrStoreId})?.getStore(), ...postParams)`,
|
|
1536
1557
|
],
|
|
1537
1558
|
);
|
|
1559
|
+
const getProps = addInternalFunction(
|
|
1560
|
+
'getProps',
|
|
1561
|
+
'getProps: ((id: any) => ExtraProps) | undefined, id: Id',
|
|
1562
|
+
'(getProps == null) ? ({} as ExtraProps) : getProps(id)',
|
|
1563
|
+
);
|
|
1564
|
+
const wrap = addInternalFunction(
|
|
1565
|
+
'wrap',
|
|
1566
|
+
getParameterList(
|
|
1567
|
+
'children: any',
|
|
1568
|
+
'separator?: any',
|
|
1569
|
+
'encloseWithId?: boolean',
|
|
1570
|
+
'id?: Id',
|
|
1571
|
+
),
|
|
1572
|
+
[
|
|
1573
|
+
'const separated = separator==null || !Array.isArray(children)',
|
|
1574
|
+
' ? children',
|
|
1575
|
+
' : children.map((child, c) => (c > 0 ? [separator, child] : child));',
|
|
1576
|
+
`return encloseWithId ? [id, ':{', separated, '}'] : separated;`,
|
|
1577
|
+
],
|
|
1578
|
+
);
|
|
1579
|
+
const NullComponent = addConstant('NullComponent', `() => null`);
|
|
1538
1580
|
if (!objIsEmpty(tablesSchema)) {
|
|
1539
1581
|
const [
|
|
1540
1582
|
tablesType,
|
|
@@ -1563,15 +1605,68 @@ const getStoreUiReactApi = (
|
|
|
1563
1605
|
cellIdsListenerType,
|
|
1564
1606
|
cellListenerType,
|
|
1565
1607
|
);
|
|
1566
|
-
addImport(1, tinyBaseUiReact);
|
|
1567
1608
|
addImport(1, moduleDefinition, storeType);
|
|
1609
|
+
addImport(null, 'tinybase', IDS, 'IdOrNull');
|
|
1610
|
+
const tableView = addInternalFunction(
|
|
1611
|
+
'tableView',
|
|
1612
|
+
`{${storeInstance}, rowComponent, getRowComponentProps` +
|
|
1613
|
+
SEPARATOR_AND_DEBUG_IDS +
|
|
1614
|
+
'}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>',
|
|
1615
|
+
[
|
|
1616
|
+
'const Row = rowComponent ?? defaultRowComponent;',
|
|
1617
|
+
`return ${wrap}(rowIds.map((rowId) => (`,
|
|
1618
|
+
'<Row',
|
|
1619
|
+
'{...' + getProps + '(getRowComponentProps, rowId)}',
|
|
1620
|
+
'key={rowId}',
|
|
1621
|
+
'tableId={tableId}',
|
|
1622
|
+
ROW_ID_PROP,
|
|
1623
|
+
storeProp,
|
|
1624
|
+
DEBUG_IDS_PROP,
|
|
1625
|
+
'/>',
|
|
1626
|
+
'))',
|
|
1627
|
+
SEPARATOR_AND_DEBUG_IDS,
|
|
1628
|
+
', tableId,',
|
|
1629
|
+
');',
|
|
1630
|
+
],
|
|
1631
|
+
);
|
|
1632
|
+
const getDefaultTableComponent = addInternalFunction(
|
|
1633
|
+
'getDefaultTableComponent',
|
|
1634
|
+
'tableId: Id',
|
|
1635
|
+
join(
|
|
1636
|
+
mapTablesSchema(
|
|
1637
|
+
(_, tableName, TABLE_ID) =>
|
|
1638
|
+
`tableId == ${TABLE_ID} ? ${tableName}TableView : `,
|
|
1639
|
+
),
|
|
1640
|
+
) + NullComponent,
|
|
1641
|
+
);
|
|
1642
|
+
const getDefaultCellComponent = addInternalFunction(
|
|
1643
|
+
'getDefaultCellComponent',
|
|
1644
|
+
'tableId: Id, cellId: Id',
|
|
1645
|
+
join(
|
|
1646
|
+
mapTablesSchema(
|
|
1647
|
+
(tableId, tableName, TABLE_ID) =>
|
|
1648
|
+
`tableId == ${TABLE_ID} ? ${
|
|
1649
|
+
join(
|
|
1650
|
+
mapCellSchema(
|
|
1651
|
+
tableId,
|
|
1652
|
+
(_, _2, _3, CELL_ID, cellName) =>
|
|
1653
|
+
`cellId == ${CELL_ID} ? ` +
|
|
1654
|
+
tableName +
|
|
1655
|
+
cellName +
|
|
1656
|
+
'CellView : ',
|
|
1657
|
+
),
|
|
1658
|
+
) + NullComponent
|
|
1659
|
+
} : `,
|
|
1660
|
+
),
|
|
1661
|
+
) + NullComponent,
|
|
1662
|
+
);
|
|
1568
1663
|
addProxyHook(
|
|
1569
1664
|
TABLES,
|
|
1570
1665
|
TABLES,
|
|
1571
1666
|
tablesType,
|
|
1572
1667
|
getTheContentOfTheStoreDoc(1, 0) + AND_REGISTERS,
|
|
1573
1668
|
);
|
|
1574
|
-
addProxyHook(
|
|
1669
|
+
const useTableIds = addProxyHook(
|
|
1575
1670
|
TABLE_IDS,
|
|
1576
1671
|
TABLE_IDS,
|
|
1577
1672
|
tableIdType + SQUARE_BRACKETS,
|
|
@@ -1606,6 +1701,58 @@ const getStoreUiReactApi = (
|
|
|
1606
1701
|
THEN_AND_THEN_DEPS,
|
|
1607
1702
|
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1608
1703
|
);
|
|
1704
|
+
const tablesPropsType = addType(
|
|
1705
|
+
TABLES + PROPS,
|
|
1706
|
+
getPropsTypeList(
|
|
1707
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1708
|
+
'tableComponents?: {' +
|
|
1709
|
+
join(
|
|
1710
|
+
mapTablesSchema(
|
|
1711
|
+
(tableId, tableName) =>
|
|
1712
|
+
`'${tableId}'?: ComponentType<${tableName}TableProps>`,
|
|
1713
|
+
),
|
|
1714
|
+
', ',
|
|
1715
|
+
) +
|
|
1716
|
+
'}',
|
|
1717
|
+
`getTableComponentProps?: (tableId: ${tableIdType}) => ExtraProps`,
|
|
1718
|
+
SEPARATOR_PROP_TYPE,
|
|
1719
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1720
|
+
),
|
|
1721
|
+
getPropsDoc(getTheContentOfDoc(1, 1)),
|
|
1722
|
+
);
|
|
1723
|
+
const cellPropsType = addType(
|
|
1724
|
+
CELL + PROPS,
|
|
1725
|
+
getPropsTypeList(
|
|
1726
|
+
'rowId: Id',
|
|
1727
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1728
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1729
|
+
),
|
|
1730
|
+
getPropsDoc('a Cell'),
|
|
1731
|
+
);
|
|
1732
|
+
addImport(1, uiReactModuleDefinition, tablesPropsType, cellPropsType);
|
|
1733
|
+
addComponent(
|
|
1734
|
+
TABLES + VIEW,
|
|
1735
|
+
'{' +
|
|
1736
|
+
storeInstance +
|
|
1737
|
+
', tableComponents, getTableComponentProps' +
|
|
1738
|
+
SEPARATOR_AND_DEBUG_IDS +
|
|
1739
|
+
'}: ' +
|
|
1740
|
+
tablesPropsType,
|
|
1741
|
+
[
|
|
1742
|
+
wrap + `(${useTableIds}(${storeInstance}).map((tableId) => {`,
|
|
1743
|
+
'const Table = tableComponents?.[tableId] ?? ' +
|
|
1744
|
+
getDefaultTableComponent +
|
|
1745
|
+
'(tableId);',
|
|
1746
|
+
'return <Table',
|
|
1747
|
+
`{...${getProps}(getTableComponentProps, tableId)}`,
|
|
1748
|
+
'key={tableId}',
|
|
1749
|
+
storeProp,
|
|
1750
|
+
DEBUG_IDS_PROP,
|
|
1751
|
+
'/>;',
|
|
1752
|
+
'}), separator)',
|
|
1753
|
+
],
|
|
1754
|
+
getTheContentOfTheStoreDoc(1, 13) + AND_REGISTERS,
|
|
1755
|
+
);
|
|
1609
1756
|
mapTablesSchema((tableId, tableName, TABLE_ID) => {
|
|
1610
1757
|
const [tableType, rowType, rowWhenSetType, cellIdType] = mapGet(
|
|
1611
1758
|
tablesTypes,
|
|
@@ -1635,7 +1782,7 @@ const getStoreUiReactApi = (
|
|
|
1635
1782
|
EMPTY_STRING,
|
|
1636
1783
|
TABLE_ID,
|
|
1637
1784
|
);
|
|
1638
|
-
addProxyHook(
|
|
1785
|
+
const useRowIds = addProxyHook(
|
|
1639
1786
|
tableName + ROW_IDS,
|
|
1640
1787
|
ROW_IDS,
|
|
1641
1788
|
IDS,
|
|
@@ -1643,7 +1790,7 @@ const getStoreUiReactApi = (
|
|
|
1643
1790
|
EMPTY_STRING,
|
|
1644
1791
|
TABLE_ID,
|
|
1645
1792
|
);
|
|
1646
|
-
addProxyHook(
|
|
1793
|
+
const useSortedRowIds = addProxyHook(
|
|
1647
1794
|
tableName + SORTED_ROW_IDS,
|
|
1648
1795
|
SORTED_ROW_IDS,
|
|
1649
1796
|
IDS,
|
|
@@ -1661,7 +1808,7 @@ const getStoreUiReactApi = (
|
|
|
1661
1808
|
TYPED_ROW_ID,
|
|
1662
1809
|
getParameterList(TABLE_ID, ROW_ID),
|
|
1663
1810
|
);
|
|
1664
|
-
addProxyHook(
|
|
1811
|
+
const useCellIds = addProxyHook(
|
|
1665
1812
|
tableName + CELL_IDS,
|
|
1666
1813
|
CELL_IDS,
|
|
1667
1814
|
cellIdType + SQUARE_BRACKETS,
|
|
@@ -1767,13 +1914,109 @@ const getStoreUiReactApi = (
|
|
|
1767
1914
|
THEN_AND_THEN_DEPS,
|
|
1768
1915
|
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1769
1916
|
);
|
|
1917
|
+
const rowPropsType = addType(
|
|
1918
|
+
tableName + 'RowProps',
|
|
1919
|
+
getPropsTypeList(
|
|
1920
|
+
'rowId: Id',
|
|
1921
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1922
|
+
'cellComponents?: {' +
|
|
1923
|
+
join(
|
|
1924
|
+
mapCellSchema(
|
|
1925
|
+
tableId,
|
|
1926
|
+
(cellId) => `'${cellId}'?: ComponentType<${cellPropsType}>`,
|
|
1927
|
+
),
|
|
1928
|
+
', ',
|
|
1929
|
+
) +
|
|
1930
|
+
'}',
|
|
1931
|
+
`getCellComponentProps?: (cellId: ${cellIdType}) => ExtraProps`,
|
|
1932
|
+
SEPARATOR_PROP_TYPE,
|
|
1933
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1934
|
+
),
|
|
1935
|
+
getPropsDoc(getRowDoc(tableId)),
|
|
1936
|
+
);
|
|
1937
|
+
const tablePropsType = addType(
|
|
1938
|
+
tableName + 'TableProps',
|
|
1939
|
+
getPropsTypeList(
|
|
1940
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1941
|
+
`rowComponent?: ComponentType<${rowPropsType}>`,
|
|
1942
|
+
`getRowComponentProps?: (rowId: Id) => ExtraProps`,
|
|
1943
|
+
SEPARATOR_PROP_TYPE,
|
|
1944
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1945
|
+
),
|
|
1946
|
+
getPropsDoc(getTableDoc(tableId)),
|
|
1947
|
+
);
|
|
1948
|
+
const sortedTablePropsType = addType(
|
|
1949
|
+
tableName + 'SortedTableProps',
|
|
1950
|
+
getPropsTypeList(
|
|
1951
|
+
'cellId?: ' + cellIdType,
|
|
1952
|
+
'descending?: boolean',
|
|
1953
|
+
'offset?: number',
|
|
1954
|
+
'limit?: number',
|
|
1955
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
1956
|
+
`rowComponent?: ComponentType<${rowPropsType}>`,
|
|
1957
|
+
`getRowComponentProps?: (rowId: Id) => ExtraProps`,
|
|
1958
|
+
SEPARATOR_PROP_TYPE,
|
|
1959
|
+
DEBUG_IDS_PROP_TYPE,
|
|
1960
|
+
),
|
|
1961
|
+
getPropsDoc(getTableDoc(tableId)) + ', sorted',
|
|
1962
|
+
);
|
|
1963
|
+
addImport(
|
|
1964
|
+
1,
|
|
1965
|
+
uiReactModuleDefinition,
|
|
1966
|
+
rowPropsType,
|
|
1967
|
+
tablePropsType,
|
|
1968
|
+
sortedTablePropsType,
|
|
1969
|
+
);
|
|
1970
|
+
const rowView = addComponent(
|
|
1971
|
+
tableName + ROW + VIEW,
|
|
1972
|
+
'{rowId, ' +
|
|
1973
|
+
storeInstance +
|
|
1974
|
+
', cellComponents, getCellComponentProps' +
|
|
1975
|
+
SEPARATOR_AND_DEBUG_IDS +
|
|
1976
|
+
'}: ' +
|
|
1977
|
+
rowPropsType,
|
|
1978
|
+
[
|
|
1979
|
+
wrap + `(${useCellIds}(rowId, ${storeInstance}).map((cellId) => {`,
|
|
1980
|
+
'const Cell = cellComponents?.[cellId] ?? ' +
|
|
1981
|
+
getDefaultCellComponent +
|
|
1982
|
+
`(${TABLE_ID}, cellId);`,
|
|
1983
|
+
'return <Cell',
|
|
1984
|
+
`{...${getProps}(getCellComponentProps, cellId)} `,
|
|
1985
|
+
'key={cellId}',
|
|
1986
|
+
ROW_ID_PROP,
|
|
1987
|
+
storeProp,
|
|
1988
|
+
DEBUG_IDS_PROP,
|
|
1989
|
+
'/>;',
|
|
1990
|
+
'})' + SEPARATOR_AND_DEBUG_IDS + ', rowId)',
|
|
1991
|
+
],
|
|
1992
|
+
getRowContentDoc(tableId, 13) + AND_REGISTERS,
|
|
1993
|
+
);
|
|
1994
|
+
addComponent(
|
|
1995
|
+
tableName + 'Sorted' + TABLE + VIEW,
|
|
1996
|
+
'{cellId, descending, offset, limit, ...props}: ' +
|
|
1997
|
+
sortedTablePropsType,
|
|
1998
|
+
tableView +
|
|
1999
|
+
'(props, ' +
|
|
2000
|
+
useSortedRowIds +
|
|
2001
|
+
`(cellId, descending, offset, limit, props.${storeInstance}), ${TABLE_ID}, ${rowView});`,
|
|
2002
|
+
getTableContentDoc(tableId, 13) + ', sorted' + AND_REGISTERS,
|
|
2003
|
+
);
|
|
2004
|
+
addComponent(
|
|
2005
|
+
tableName + TABLE + VIEW,
|
|
2006
|
+
'props: ' + tablePropsType,
|
|
2007
|
+
tableView +
|
|
2008
|
+
'(props, ' +
|
|
2009
|
+
useRowIds +
|
|
2010
|
+
`(props.${storeInstance}), ${TABLE_ID}, ${rowView});`,
|
|
2011
|
+
getTableContentDoc(tableId, 13) + AND_REGISTERS,
|
|
2012
|
+
);
|
|
1770
2013
|
mapCellSchema(
|
|
1771
2014
|
tableId,
|
|
1772
2015
|
(cellId, type, defaultValue, CELL_ID, cellName) => {
|
|
1773
2016
|
const mapCellType = 'Map' + camel(type, 1);
|
|
1774
2017
|
addImport(0, moduleDefinition, mapCellType);
|
|
1775
2018
|
addImport(1, moduleDefinition, mapCellType);
|
|
1776
|
-
addProxyHook(
|
|
2019
|
+
const useCell = addProxyHook(
|
|
1777
2020
|
tableName + cellName + CELL,
|
|
1778
2021
|
CELL,
|
|
1779
2022
|
type + (isUndefined(defaultValue) ? OR_UNDEFINED : EMPTY_STRING),
|
|
@@ -1811,6 +2054,17 @@ const getStoreUiReactApi = (
|
|
|
1811
2054
|
THEN_AND_THEN_DEPS,
|
|
1812
2055
|
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1813
2056
|
);
|
|
2057
|
+
addComponent(
|
|
2058
|
+
tableName + cellName + CELL + VIEW,
|
|
2059
|
+
`{rowId, ${storeInstance}, debugIds}: ` + cellPropsType,
|
|
2060
|
+
[
|
|
2061
|
+
wrap +
|
|
2062
|
+
`('' + ${useCell}(rowId, ` +
|
|
2063
|
+
storeInstance +
|
|
2064
|
+
`) ?? '', undefined, debugIds, ${CELL_ID})`,
|
|
2065
|
+
],
|
|
2066
|
+
getCellContentDoc(tableId, cellId, 13) + AND_REGISTERS,
|
|
2067
|
+
);
|
|
1814
2068
|
},
|
|
1815
2069
|
);
|
|
1816
2070
|
});
|
|
@@ -1927,13 +2181,24 @@ const getStoreUiReactApi = (
|
|
|
1927
2181
|
valueListenerType,
|
|
1928
2182
|
] = sharedValueTypes;
|
|
1929
2183
|
addImport(null, moduleDefinition, ...sharedValueTypes);
|
|
2184
|
+
addImport(1, moduleDefinition, storeType);
|
|
2185
|
+
const getDefaultValueComponent = addInternalFunction(
|
|
2186
|
+
'getDefaultValueComponent',
|
|
2187
|
+
'valueId: Id',
|
|
2188
|
+
join(
|
|
2189
|
+
mapValuesSchema(
|
|
2190
|
+
(_, _2, _3, VALUE_ID, valueName) =>
|
|
2191
|
+
`valueId == ${VALUE_ID} ? ` + valueName + 'ValueView : ',
|
|
2192
|
+
),
|
|
2193
|
+
) + NullComponent,
|
|
2194
|
+
);
|
|
1930
2195
|
addProxyHook(
|
|
1931
2196
|
VALUES,
|
|
1932
2197
|
VALUES,
|
|
1933
2198
|
valuesType,
|
|
1934
2199
|
getTheContentOfTheStoreDoc(2, 0) + AND_REGISTERS,
|
|
1935
2200
|
);
|
|
1936
|
-
addProxyHook(
|
|
2201
|
+
const useValueIds = addProxyHook(
|
|
1937
2202
|
VALUE_IDS,
|
|
1938
2203
|
VALUE_IDS,
|
|
1939
2204
|
valueIdType + SQUARE_BRACKETS,
|
|
@@ -1986,11 +2251,61 @@ const getStoreUiReactApi = (
|
|
|
1986
2251
|
THEN_AND_THEN_DEPS,
|
|
1987
2252
|
THEN_AND_THEN_DEPS_IN_CALL,
|
|
1988
2253
|
);
|
|
2254
|
+
const valuePropsType = addType(
|
|
2255
|
+
VALUE + PROPS,
|
|
2256
|
+
getPropsTypeList(
|
|
2257
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
2258
|
+
DEBUG_IDS_PROP_TYPE,
|
|
2259
|
+
),
|
|
2260
|
+
getPropsDoc('a Value'),
|
|
2261
|
+
);
|
|
2262
|
+
const valuesPropsType = addType(
|
|
2263
|
+
VALUES + PROPS,
|
|
2264
|
+
getPropsTypeList(
|
|
2265
|
+
storeInstance + OPTIONAL_COLON + storeType,
|
|
2266
|
+
'valueComponents?: {' +
|
|
2267
|
+
join(
|
|
2268
|
+
mapValuesSchema(
|
|
2269
|
+
(valueId) => `'${valueId}'?: ComponentType<${valuePropsType}>`,
|
|
2270
|
+
),
|
|
2271
|
+
', ',
|
|
2272
|
+
) +
|
|
2273
|
+
'}',
|
|
2274
|
+
`getValueComponentProps?: (valueId: ${valueIdType}) => ExtraProps`,
|
|
2275
|
+
SEPARATOR_PROP_TYPE,
|
|
2276
|
+
DEBUG_IDS_PROP_TYPE,
|
|
2277
|
+
),
|
|
2278
|
+
getPropsDoc(getTheContentOfDoc(2, 1)),
|
|
2279
|
+
);
|
|
2280
|
+
addImport(1, uiReactModuleDefinition, valuesPropsType, valuePropsType);
|
|
2281
|
+
addComponent(
|
|
2282
|
+
VALUES + VIEW,
|
|
2283
|
+
'{' +
|
|
2284
|
+
storeInstance +
|
|
2285
|
+
', valueComponents, getValueComponentProps' +
|
|
2286
|
+
SEPARATOR_AND_DEBUG_IDS +
|
|
2287
|
+
'}: ' +
|
|
2288
|
+
valuesPropsType,
|
|
2289
|
+
[
|
|
2290
|
+
wrap + `(${useValueIds}(${storeInstance}).map((valueId) => {`,
|
|
2291
|
+
'const Value = valueComponents?.[valueId] ?? ' +
|
|
2292
|
+
getDefaultValueComponent +
|
|
2293
|
+
'(valueId);',
|
|
2294
|
+
'return <Value',
|
|
2295
|
+
`{...${getProps}(getValueComponentProps, valueId)}`,
|
|
2296
|
+
'key={valueId}',
|
|
2297
|
+
storeProp,
|
|
2298
|
+
DEBUG_IDS_PROP,
|
|
2299
|
+
'/>;',
|
|
2300
|
+
'}), separator)',
|
|
2301
|
+
],
|
|
2302
|
+
getTheContentOfTheStoreDoc(2, 13) + AND_REGISTERS,
|
|
2303
|
+
);
|
|
1989
2304
|
mapValuesSchema((valueId, type, _, VALUE_ID, valueName) => {
|
|
1990
2305
|
const mapValueType = 'Map' + camel(type, 1);
|
|
1991
2306
|
addImport(0, moduleDefinition, mapValueType);
|
|
1992
2307
|
addImport(1, moduleDefinition, mapValueType);
|
|
1993
|
-
addProxyHook(
|
|
2308
|
+
const useValue = addProxyHook(
|
|
1994
2309
|
valueName + VALUE,
|
|
1995
2310
|
VALUE,
|
|
1996
2311
|
type,
|
|
@@ -2027,6 +2342,17 @@ const getStoreUiReactApi = (
|
|
|
2027
2342
|
THEN_AND_THEN_DEPS,
|
|
2028
2343
|
THEN_AND_THEN_DEPS_IN_CALL,
|
|
2029
2344
|
);
|
|
2345
|
+
addComponent(
|
|
2346
|
+
valueName + VALUE + VIEW,
|
|
2347
|
+
`{${storeInstance}, debugIds}: ` + valuePropsType,
|
|
2348
|
+
[
|
|
2349
|
+
wrap +
|
|
2350
|
+
`('' + ${useValue}(` +
|
|
2351
|
+
storeInstance +
|
|
2352
|
+
`) ?? '', undefined, debugIds, ${VALUE_ID})`,
|
|
2353
|
+
],
|
|
2354
|
+
getValueContentDoc(valueId, 13) + AND_REGISTERS,
|
|
2355
|
+
);
|
|
2030
2356
|
});
|
|
2031
2357
|
addProxyHook(
|
|
2032
2358
|
VALUES + LISTENER,
|
|
@@ -2057,21 +2383,23 @@ const getStoreUiReactApi = (
|
|
|
2057
2383
|
);
|
|
2058
2384
|
}
|
|
2059
2385
|
addComponent(
|
|
2060
|
-
|
|
2386
|
+
PROVIDER,
|
|
2061
2387
|
`{${storeInstance}, ${storeInstance}ById, children}: ` +
|
|
2062
2388
|
providerPropsType +
|
|
2063
2389
|
' & {children: React.ReactNode}',
|
|
2064
2390
|
[
|
|
2391
|
+
'{',
|
|
2065
2392
|
USE_CONTEXT,
|
|
2066
2393
|
'return (',
|
|
2067
|
-
'<Context.
|
|
2394
|
+
'<Context.' + PROVIDER,
|
|
2068
2395
|
'value={useMemo(',
|
|
2069
2396
|
`() => [${storeInstance} ?? contextValue[0], {...contextValue[1], ...${storeInstance}ById}],`,
|
|
2070
2397
|
`[${storeInstance}, ${storeInstance}ById, contextValue],`,
|
|
2071
2398
|
')}>',
|
|
2072
2399
|
'{children}',
|
|
2073
|
-
|
|
2400
|
+
`</Context.${PROVIDER}>`,
|
|
2074
2401
|
');',
|
|
2402
|
+
'}',
|
|
2075
2403
|
],
|
|
2076
2404
|
'Wraps part of an application in a context that provides default objects to be used by hooks and components within',
|
|
2077
2405
|
);
|
package/lib/debug/ui-react.js
CHANGED
|
@@ -1126,11 +1126,11 @@ const Provider = ({
|
|
|
1126
1126
|
);
|
|
1127
1127
|
};
|
|
1128
1128
|
const wrap = (children, separator, encloseWithId, id) => {
|
|
1129
|
-
const
|
|
1129
|
+
const separated =
|
|
1130
1130
|
isUndefined(separator) || !isArray(children)
|
|
1131
1131
|
? children
|
|
1132
1132
|
: arrayMap(children, (child, c) => (c > 0 ? [separator, child] : child));
|
|
1133
|
-
return encloseWithId ? [id, ':{',
|
|
1133
|
+
return encloseWithId ? [id, ':{', separated, '}'] : separated;
|
|
1134
1134
|
};
|
|
1135
1135
|
const CellView = ({tableId, rowId, cellId, store, debugIds}) =>
|
|
1136
1136
|
wrap(
|
package/lib/es6/tools.d.ts
CHANGED
|
@@ -342,7 +342,7 @@ export interface Tools {
|
|
|
342
342
|
* price: {type: 'number'},
|
|
343
343
|
* },
|
|
344
344
|
* });
|
|
345
|
-
* const [dTs, ts,
|
|
345
|
+
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
346
346
|
* createTools(store).getStoreApi('shop');
|
|
347
347
|
*
|
|
348
348
|
* const dTsLines = dTs.split('\n');
|
|
@@ -363,7 +363,7 @@ export interface Tools {
|
|
|
363
363
|
* fido: {price: 5},
|
|
364
364
|
* felix: {price: 4},
|
|
365
365
|
* });
|
|
366
|
-
* const [dTs, ts,
|
|
366
|
+
* const [dTs, ts, uiReactDTs, uiReactTsx] =
|
|
367
367
|
* createTools(store).getStoreApi('shop');
|
|
368
368
|
*
|
|
369
369
|
* const dTsLines = dTs.split('\n');
|
|
@@ -423,7 +423,7 @@ export interface Tools {
|
|
|
423
423
|
* },
|
|
424
424
|
* });
|
|
425
425
|
* const tools = createTools(store);
|
|
426
|
-
* const [dTs, ts,
|
|
426
|
+
* const [dTs, ts, uiReactDTs, uiReactTsx] = await createTools(
|
|
427
427
|
* store,
|
|
428
428
|
* ).getPrettyStoreApi('shop');
|
|
429
429
|
*
|
|
@@ -446,7 +446,7 @@ export interface Tools {
|
|
|
446
446
|
* felix: {price: 4},
|
|
447
447
|
* });
|
|
448
448
|
* const tools = createTools(store);
|
|
449
|
-
* const [dTs, ts,
|
|
449
|
+
* const [dTs, ts, uiReactDTs, uiReactTsx] = await createTools(
|
|
450
450
|
* store,
|
|
451
451
|
* ).getPrettyStoreApi('shop');
|
|
452
452
|
*
|