cx 26.0.12 → 26.0.14
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/build/charts/ScatterGraph.d.ts +4 -4
- package/build/charts/ScatterGraph.js +2 -2
- package/build/data/ArrayElementView.spec.d.ts +1 -0
- package/build/data/ArrayElementView.spec.js +81 -0
- package/build/data/Binding.spec.d.ts +1 -0
- package/build/data/Binding.spec.js +61 -0
- package/build/data/Expression.spec.d.ts +1 -0
- package/build/data/Expression.spec.js +196 -0
- package/build/data/Grouper.spec.d.ts +1 -0
- package/build/data/Grouper.spec.js +48 -0
- package/build/data/Ref.spec.d.ts +1 -0
- package/build/data/Ref.spec.js +72 -0
- package/build/data/Selector.d.ts +1 -1
- package/build/data/Store.spec.d.ts +1 -0
- package/build/data/Store.spec.js +19 -0
- package/build/data/StoreRef.spec.d.ts +1 -0
- package/build/data/StoreRef.spec.js +22 -0
- package/build/data/StringTemplate.spec.d.ts +1 -0
- package/build/data/StringTemplate.spec.js +112 -0
- package/build/data/StructuredSelector.spec.d.ts +1 -0
- package/build/data/StructuredSelector.spec.js +102 -0
- package/build/data/View.spec.d.ts +1 -0
- package/build/data/View.spec.js +44 -0
- package/build/data/ZoomIntoPropertyView.spec.d.ts +1 -0
- package/build/data/ZoomIntoPropertyView.spec.js +54 -0
- package/build/data/comparer.spec.d.ts +1 -0
- package/build/data/comparer.spec.js +50 -0
- package/build/data/computable.d.ts +3 -6
- package/build/data/computable.spec.d.ts +1 -0
- package/build/data/computable.spec.js +56 -0
- package/build/data/createAccessorModelProxy.d.ts +5 -3
- package/build/data/createAccessorModelProxy.spec.d.ts +1 -0
- package/build/data/createAccessorModelProxy.spec.js +30 -0
- package/build/data/createStructuredSelector.spec.d.ts +1 -0
- package/build/data/createStructuredSelector.spec.js +42 -0
- package/build/data/diff/diffs.spec.d.ts +1 -0
- package/build/data/diff/diffs.spec.js +45 -0
- package/build/data/getAccessor.spec.d.ts +1 -0
- package/build/data/getAccessor.spec.js +10 -0
- package/build/data/getSelector.spec.d.ts +1 -0
- package/build/data/getSelector.spec.js +36 -0
- package/build/data/ops/append.spec.d.ts +1 -0
- package/build/data/ops/append.spec.js +24 -0
- package/build/data/ops/filter.spec.d.ts +1 -0
- package/build/data/ops/filter.spec.js +25 -0
- package/build/data/ops/findTreeNode.d.ts +1 -1
- package/build/data/ops/findTreeNode.js +1 -1
- package/build/data/ops/findTreeNode.spec.d.ts +1 -0
- package/build/data/ops/findTreeNode.spec.js +20 -0
- package/build/data/ops/findTreePath.d.ts +1 -1
- package/build/data/ops/merge.spec.d.ts +1 -0
- package/build/data/ops/merge.spec.js +23 -0
- package/build/data/ops/removeTreeNodes.d.ts +1 -1
- package/build/data/ops/removeTreeNodes.js +1 -1
- package/build/data/ops/removeTreeNodes.spec.d.ts +1 -0
- package/build/data/ops/removeTreeNodes.spec.js +35 -0
- package/build/data/ops/updateArray.spec.d.ts +1 -0
- package/build/data/ops/updateArray.spec.js +33 -0
- package/build/data/ops/updateTree.d.ts +1 -1
- package/build/data/ops/updateTree.spec.d.ts +1 -0
- package/build/data/ops/updateTree.spec.js +44 -0
- package/build/hooks/invokeCallback.spec.d.ts +1 -0
- package/build/hooks/invokeCallback.spec.js +44 -0
- package/build/hooks/resolveCallback.spec.d.ts +1 -0
- package/build/hooks/resolveCallback.spec.js +35 -0
- package/build/hooks/store.spec.d.ts +1 -0
- package/build/hooks/store.spec.js +48 -0
- package/build/hooks/useTrigger.spec.d.ts +1 -0
- package/build/hooks/useTrigger.spec.js +59 -0
- package/build/jsx-runtime.d.ts +10 -10
- package/build/jsx-runtime.js +6 -0
- package/build/svg/util/Rect.d.ts +1 -1
- package/build/ui/ContentResolver.d.ts +16 -6
- package/build/ui/Controller.d.ts +7 -0
- package/build/ui/Controller.js +2 -1
- package/build/ui/Controller.spec.d.ts +1 -0
- package/build/ui/Controller.spec.js +247 -0
- package/build/ui/Cx.spec.d.ts +1 -0
- package/build/ui/Cx.spec.js +153 -0
- package/build/ui/DataProxy.spec.d.ts +1 -0
- package/build/ui/DataProxy.spec.js +208 -0
- package/build/ui/Instance.d.ts +1 -1
- package/build/ui/Instance.js +10 -10
- package/build/ui/IsolatedScope.spec.d.ts +1 -0
- package/build/ui/IsolatedScope.spec.js +42 -0
- package/build/ui/Prop.d.ts +12 -1
- package/build/ui/PureContainer.spec.d.ts +1 -0
- package/build/ui/PureContainer.spec.js +149 -0
- package/build/ui/Repeater.d.ts +3 -3
- package/build/ui/Repeater.spec.d.ts +1 -0
- package/build/ui/Repeater.spec.js +109 -0
- package/build/ui/Rescope.spec.d.ts +1 -0
- package/build/ui/Rescope.spec.js +134 -0
- package/build/ui/Restate.spec.d.ts +1 -0
- package/build/ui/Restate.spec.js +257 -0
- package/build/ui/Text.d.ts +14 -2
- package/build/ui/Text.js +3 -0
- package/build/ui/adapter/ArrayAdapter.js +4 -1
- package/build/ui/adapter/ArrayAdapter.spec.d.ts +1 -0
- package/build/ui/adapter/ArrayAdapter.spec.js +44 -0
- package/build/ui/adapter/TreeAdapter.spec.d.ts +1 -0
- package/build/ui/adapter/TreeAdapter.spec.js +71 -0
- package/build/ui/app/Url.spec.d.ts +1 -0
- package/build/ui/app/Url.spec.js +43 -0
- package/build/ui/app/startHotAppLoop.js +1 -1
- package/build/ui/createFunctionalComponent.d.ts +14 -1
- package/build/ui/createFunctionalComponent.js +7 -4
- package/build/ui/createFunctionalComponent.spec.d.ts +1 -0
- package/build/ui/createFunctionalComponent.spec.js +272 -0
- package/build/ui/expr.d.ts +3 -1
- package/build/ui/exprHelpers.d.ts +32 -0
- package/build/ui/exprHelpers.js +61 -0
- package/build/ui/index.d.ts +1 -0
- package/build/ui/index.js +1 -0
- package/build/ui/layout/ContentPlaceholder.spec.d.ts +1 -0
- package/build/ui/layout/ContentPlaceholder.spec.js +333 -0
- package/build/ui/layout/FirstVisibleChildLayout.spec.d.ts +1 -0
- package/build/ui/layout/FirstVisibleChildLayout.spec.js +101 -0
- package/build/util/Console.d.ts +1 -0
- package/build/util/Console.js +7 -3
- package/build/util/Format.spec.d.ts +1 -0
- package/build/util/Format.spec.js +58 -0
- package/build/util/TraversalStack.spec.d.ts +1 -0
- package/build/util/TraversalStack.spec.js +43 -0
- package/build/util/date/upperBoundCheck.spec.d.ts +1 -0
- package/build/util/date/upperBoundCheck.spec.js +22 -0
- package/build/util/getSearchQueryPredicate.spec.d.ts +1 -0
- package/build/util/getSearchQueryPredicate.spec.js +33 -0
- package/build/util/isValidIdentifierName.spec.d.ts +1 -0
- package/build/util/isValidIdentifierName.spec.js +28 -0
- package/build/util/routeAppend.spec.d.ts +1 -0
- package/build/util/routeAppend.spec.js +14 -0
- package/build/widgets/AccessorBindings.spec.d.ts +1 -0
- package/build/widgets/AccessorBindings.spec.js +40 -0
- package/build/widgets/Button.d.ts +3 -6
- package/build/widgets/Button.js +1 -1
- package/build/widgets/DocumentTitle.d.ts +2 -0
- package/build/widgets/Heading.d.ts +2 -2
- package/build/widgets/HtmlElement.d.ts +31 -8
- package/build/widgets/HtmlElement.js +7 -9
- package/build/widgets/HtmlElement.spec.d.ts +1 -0
- package/build/widgets/HtmlElement.spec.js +38 -0
- package/build/widgets/Icon.d.ts +3 -13
- package/build/widgets/List.d.ts +4 -0
- package/build/widgets/ReactElementWrapper.d.ts +29 -0
- package/build/widgets/ReactElementWrapper.js +59 -0
- package/build/widgets/drag-drop/DragSource.d.ts +3 -3
- package/build/widgets/drag-drop/DragSource.js +2 -3
- package/build/widgets/drag-drop/DropZone.d.ts +3 -3
- package/build/widgets/drag-drop/DropZone.js +2 -3
- package/build/widgets/form/Checkbox.d.ts +2 -0
- package/build/widgets/form/ColorField.d.ts +2 -0
- package/build/widgets/form/DateTimeField.d.ts +2 -0
- package/build/widgets/form/Field.d.ts +0 -2
- package/build/widgets/form/LabeledContainer.d.ts +9 -8
- package/build/widgets/form/LabeledContainer.js +9 -9
- package/build/widgets/form/LookupField.d.ts +57 -9
- package/build/widgets/form/MonthField.d.ts +2 -0
- package/build/widgets/form/NumberField.d.ts +2 -0
- package/build/widgets/form/Radio.d.ts +2 -0
- package/build/widgets/form/Select.d.ts +2 -0
- package/build/widgets/form/Slider.d.ts +3 -0
- package/build/widgets/form/Switch.d.ts +2 -0
- package/build/widgets/form/TextField.d.ts +34 -0
- package/build/widgets/form/TimeList.d.ts +16 -1
- package/build/widgets/form/TimeList.js +34 -62
- package/build/widgets/form/UploadButton.d.ts +34 -2
- package/build/widgets/form/UploadButton.js +3 -1
- package/build/widgets/form/ValidationGroup.spec.d.ts +1 -0
- package/build/widgets/form/ValidationGroup.spec.js +62 -0
- package/build/widgets/form/Validator.d.ts +33 -2
- package/build/widgets/form/Validator.js +3 -0
- package/build/widgets/grid/Grid.d.ts +9 -9
- package/build/widgets/grid/TreeNode.d.ts +6 -0
- package/build/widgets/index.d.ts +1 -0
- package/build/widgets/index.js +1 -0
- package/build/widgets/nav/MenuItem.d.ts +3 -2
- package/build/widgets/nav/Route.spec.d.ts +1 -0
- package/build/widgets/nav/Route.spec.js +15 -0
- package/build/widgets/nav/Scroller.d.ts +4 -6
- package/build/widgets/nav/Scroller.js +6 -3
- package/build/widgets/nav/Tab.d.ts +2 -2
- package/build/widgets/overlay/ContextMenu.d.ts +3 -3
- package/build/widgets/overlay/Overlay.d.ts +2 -1
- package/build/widgets/overlay/Overlay.js +1 -1
- package/build/widgets/overlay/createHotPromiseWindowFactory.js +0 -1
- package/build.js +133 -133
- package/dist/data.js +2 -2
- package/dist/jsx-runtime.js +6 -1
- package/dist/manifest.d.ts +1443 -0
- package/dist/manifest.js +761 -713
- package/dist/ui.js +91 -5
- package/dist/util.js +3 -0
- package/dist/widgets.js +520 -162
- package/package.json +46 -20
- package/src/charts/Chart.ts +108 -108
- package/src/charts/ScatterGraph.tsx +6 -6
- package/src/data/ArrayElementView.ts +90 -90
- package/src/data/AugmentedViewBase.ts +88 -88
- package/src/data/Binding.ts +104 -104
- package/src/data/ExposedRecordView.ts +95 -95
- package/src/data/ExposedValueView.ts +89 -89
- package/src/data/Expression.spec.ts +229 -229
- package/src/data/Expression.ts +233 -233
- package/src/data/Grouper.spec.ts +57 -57
- package/src/data/Grouper.ts +158 -158
- package/src/data/NestedDataView.ts +43 -43
- package/src/data/ReadOnlyDataView.ts +39 -39
- package/src/data/Ref.ts +104 -104
- package/src/data/Selector.ts +10 -10
- package/src/data/Store.ts +52 -52
- package/src/data/StoreProxy.ts +19 -19
- package/src/data/StoreRef.ts +66 -66
- package/src/data/StringTemplate.spec.ts +132 -132
- package/src/data/StringTemplate.ts +93 -93
- package/src/data/StructuredSelector.spec.ts +113 -113
- package/src/data/StructuredSelector.ts +146 -146
- package/src/data/SubscribableView.ts +63 -63
- package/src/data/ZoomIntoPropertyView.spec.ts +64 -64
- package/src/data/ZoomIntoPropertyView.ts +45 -45
- package/src/data/computable.spec.ts +87 -62
- package/src/data/computable.ts +3 -6
- package/src/data/createAccessorModelProxy.spec.tsx +102 -1
- package/src/data/createAccessorModelProxy.ts +9 -3
- package/src/data/createStructuredSelector.ts +62 -62
- package/src/data/getAccessor.spec.ts +11 -11
- package/src/data/getAccessor.ts +74 -74
- package/src/data/getSelector.spec.ts +43 -43
- package/src/data/getSelector.ts +66 -66
- package/src/data/ops/filter.spec.ts +35 -35
- package/src/data/ops/filter.ts +9 -9
- package/src/data/ops/findTreeNode.ts +1 -5
- package/src/data/ops/findTreePath.ts +1 -1
- package/src/data/ops/merge.ts +13 -13
- package/src/data/ops/removeTreeNodes.spec.ts +37 -37
- package/src/data/ops/removeTreeNodes.ts +2 -2
- package/src/data/ops/updateArray.spec.ts +69 -69
- package/src/data/ops/updateArray.ts +31 -31
- package/src/data/ops/updateTree.ts +1 -1
- package/src/data/test-types.ts +7 -7
- package/src/hooks/resolveCallback.spec.tsx +30 -7
- package/src/hooks/useTrigger.ts +26 -26
- package/src/index.scss +6 -6
- package/src/jsx-dev-runtime.ts +4 -4
- package/src/jsx-runtime.spec.tsx +431 -0
- package/src/jsx-runtime.ts +26 -22
- package/src/svg/BoundedObject.ts +101 -101
- package/src/svg/util/Rect.ts +105 -105
- package/src/ui/CSSHelper.ts +17 -17
- package/src/ui/ContentResolver.spec.tsx +172 -19
- package/src/ui/ContentResolver.ts +16 -8
- package/src/ui/Controller.ts +15 -2
- package/src/ui/Culture.ts +159 -159
- package/src/ui/DataProxy.ts +55 -55
- package/src/ui/FocusManager.ts +171 -171
- package/src/ui/Instance.ts +866 -868
- package/src/ui/Prop.ts +140 -112
- package/src/ui/RenderingContext.ts +99 -99
- package/src/ui/Repeater.ts +3 -12
- package/src/ui/Rescope.ts +49 -49
- package/src/ui/StructuredInstanceDataAccessor.ts +32 -32
- package/src/ui/Text.ts +21 -2
- package/src/ui/VDOM.ts +34 -34
- package/src/ui/adapter/ArrayAdapter.spec.ts +55 -55
- package/src/ui/adapter/ArrayAdapter.ts +4 -1
- package/src/ui/adapter/TreeAdapter.spec.ts +76 -76
- package/src/ui/adapter/TreeAdapter.ts +185 -185
- package/src/ui/app/History.ts +133 -133
- package/src/ui/app/Url.spec.ts +50 -50
- package/src/ui/app/startHotAppLoop.ts +41 -41
- package/src/ui/createFunctionalComponent.spec.tsx +53 -0
- package/src/ui/createFunctionalComponent.ts +86 -65
- package/src/ui/expr.ts +4 -1
- package/src/ui/exprHelpers.spec.ts +379 -0
- package/src/ui/exprHelpers.ts +78 -0
- package/src/ui/index.ts +47 -46
- package/src/ui/layout/Content.ts +30 -30
- package/src/ui/layout/FirstVisibleChildLayout.spec.tsx +1 -1
- package/src/ui/layout/FirstVisibleChildLayout.ts +60 -60
- package/src/ui/selection/KeySelection.ts +153 -153
- package/src/ui/selection/Selection.ts +128 -128
- package/src/util/Console.ts +13 -11
- package/src/util/Format.spec.ts +41 -41
- package/src/util/Format.ts +267 -267
- package/src/util/addEventListenerWithOptions.ts +41 -41
- package/src/util/browserSupportsPassiveEventHandlers.ts +20 -20
- package/src/util/color/rgbToHsl.ts +35 -35
- package/src/util/getActiveElement.ts +4 -4
- package/src/util/hasKey.ts +18 -18
- package/src/util/index.ts +55 -55
- package/src/util/innerTextTrim.ts +10 -10
- package/src/util/isArray.ts +3 -3
- package/src/util/isDataRecord.ts +5 -5
- package/src/util/isDefined.ts +3 -3
- package/src/util/isString.ts +3 -3
- package/src/widgets/AccessorBindings.spec.tsx +26 -0
- package/src/widgets/Button.tsx +5 -17
- package/src/widgets/DocumentTitle.ts +95 -92
- package/src/widgets/Heading.ts +2 -2
- package/src/widgets/HtmlElement.spec.helpers.tsx +108 -0
- package/src/widgets/HtmlElement.spec.tsx +20 -12
- package/src/widgets/HtmlElement.tsx +77 -23
- package/src/widgets/Icon.ts +3 -17
- package/src/widgets/List.tsx +6 -0
- package/src/widgets/ReactElementWrapper.spec.tsx +452 -0
- package/src/widgets/ReactElementWrapper.tsx +108 -0
- package/src/widgets/Sandbox.ts +103 -103
- package/src/widgets/autoFocus.ts +9 -9
- package/src/widgets/cx.ts +63 -63
- package/src/widgets/drag-drop/DragSource.tsx +3 -4
- package/src/widgets/drag-drop/DropZone.tsx +3 -4
- package/src/widgets/form/Checkbox.tsx +3 -0
- package/src/widgets/form/ColorField.tsx +3 -0
- package/src/widgets/form/DateTimeField.tsx +5 -0
- package/src/widgets/form/Field.tsx +0 -3
- package/src/widgets/form/Label.tsx +1 -0
- package/src/widgets/form/LabeledContainer.ts +22 -26
- package/src/widgets/form/LookupField.spec.tsx +93 -0
- package/src/widgets/form/LookupField.tsx +104 -9
- package/src/widgets/form/MonthField.tsx +5 -0
- package/src/widgets/form/NumberField.tsx +3 -0
- package/src/widgets/form/Radio.tsx +5 -0
- package/src/widgets/form/Select.tsx +5 -0
- package/src/widgets/form/Slider.tsx +4 -0
- package/src/widgets/form/Switch.tsx +3 -0
- package/src/widgets/form/TextField.tsx +62 -0
- package/src/widgets/form/TimeList.tsx +84 -73
- package/src/widgets/form/UploadButton.tsx +53 -2
- package/src/widgets/form/Validator.ts +40 -3
- package/src/widgets/grid/Grid.tsx +9 -12
- package/src/widgets/grid/GridCell.ts +143 -143
- package/src/widgets/grid/TreeNode.tsx +9 -0
- package/src/widgets/icons/calendar.tsx +17 -17
- package/src/widgets/icons/check.tsx +13 -13
- package/src/widgets/icons/clear.tsx +15 -15
- package/src/widgets/icons/close.tsx +20 -20
- package/src/widgets/icons/cx.tsx +38 -38
- package/src/widgets/icons/drop-down.tsx +15 -15
- package/src/widgets/icons/file.tsx +13 -13
- package/src/widgets/icons/folder-open.tsx +15 -15
- package/src/widgets/icons/folder.tsx +13 -13
- package/src/widgets/icons/forward.tsx +22 -22
- package/src/widgets/icons/loading.tsx +24 -24
- package/src/widgets/icons/menu.tsx +17 -17
- package/src/widgets/icons/pixel-picker.tsx +18 -18
- package/src/widgets/icons/search.tsx +13 -13
- package/src/widgets/icons/sort-asc.tsx +14 -14
- package/src/widgets/icons/square.tsx +18 -18
- package/src/widgets/index.ts +1 -0
- package/src/widgets/nav/MenuItem.tsx +3 -2
- package/src/widgets/nav/Route.ts +142 -142
- package/src/widgets/nav/Scroller.tsx +8 -9
- package/src/widgets/nav/Tab.ts +2 -2
- package/src/widgets/overlay/ContextMenu.ts +42 -42
- package/src/widgets/overlay/Dropdown.tsx +762 -762
- package/src/widgets/overlay/MsgBox.tsx +141 -141
- package/src/widgets/overlay/Overlay.tsx +5 -4
- package/src/widgets/overlay/Toast.ts +111 -111
- package/src/widgets/overlay/Window.tsx +299 -299
- package/src/widgets/overlay/alerts.ts +46 -46
- package/src/widgets/overlay/captureMouse.ts +195 -195
- package/src/widgets/overlay/createHotPromiseWindowFactory.ts +0 -1
- package/src/widgets/overlay/index.d.ts +11 -11
- package/src/widgets/overlay/index.ts +11 -11
- package/src/widgets/overlay/tooltip-ops.ts +173 -173
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { Store } from '../Store';
|
|
3
|
+
import { append } from './append';
|
|
4
|
+
describe('append', function () {
|
|
5
|
+
it('should add elements to an array', function () {
|
|
6
|
+
let store = new Store({
|
|
7
|
+
data: {
|
|
8
|
+
array: []
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
assert(store.update('array', append, 1));
|
|
12
|
+
assert.deepEqual(store.get('array'), [1]);
|
|
13
|
+
});
|
|
14
|
+
it('should work with undefined arrays', function () {
|
|
15
|
+
let store = new Store();
|
|
16
|
+
assert(store.update('array', append, 1));
|
|
17
|
+
assert.deepEqual(store.get('array'), [1]);
|
|
18
|
+
});
|
|
19
|
+
it('accepts multiple arguments', function () {
|
|
20
|
+
let store = new Store();
|
|
21
|
+
assert(store.update('array', append, 1, 2, 3));
|
|
22
|
+
assert.deepEqual(store.get('array'), [1, 2, 3]);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { Store } from "../Store";
|
|
3
|
+
import { filter } from "./filter";
|
|
4
|
+
describe("filter", function () {
|
|
5
|
+
it("should filter array elements", function () {
|
|
6
|
+
let store = new Store({
|
|
7
|
+
data: {
|
|
8
|
+
array: [1, 2, 3],
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
assert(store.update("array", filter, (x) => x > 1));
|
|
12
|
+
assert.deepEqual(store.get("array"), [2, 3]);
|
|
13
|
+
});
|
|
14
|
+
it("should work with undefined arrays", function () {
|
|
15
|
+
let store = new Store();
|
|
16
|
+
assert.equal(false, store.update("array", filter, (x) => x > 1));
|
|
17
|
+
assert.deepEqual(store.get("array"), undefined);
|
|
18
|
+
});
|
|
19
|
+
it("returns same array if all elements satisfy condition", function () {
|
|
20
|
+
let array = [1, 2, 3];
|
|
21
|
+
let store = new Store({ data: { array } });
|
|
22
|
+
assert.equal(false, store.update("array", filter, (x) => x > 0));
|
|
23
|
+
assert(store.get("array") === array);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function findTreeNode<T
|
|
1
|
+
export declare function findTreeNode<T = any>(array: T[], criteria: (node: T) => boolean, childrenField: keyof T): T | false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { findTreeNode } from './findTreeNode';
|
|
3
|
+
describe('removeTreeNodes', function () {
|
|
4
|
+
it('removes all nodes that satisfy criteria', function () {
|
|
5
|
+
let array = [{
|
|
6
|
+
id: 'n1',
|
|
7
|
+
value: 1,
|
|
8
|
+
children: [{
|
|
9
|
+
id: 'n11',
|
|
10
|
+
value: 2
|
|
11
|
+
}, {
|
|
12
|
+
id: 'n12',
|
|
13
|
+
value: 3
|
|
14
|
+
}]
|
|
15
|
+
}];
|
|
16
|
+
let node = findTreeNode(array, x => x.value == 3, 'children');
|
|
17
|
+
assert(node);
|
|
18
|
+
assert.equal(node.value, 3);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function findTreePath<T
|
|
1
|
+
export declare function findTreePath<T = any>(array: T[] | undefined, criteria: (node: T) => boolean, childrenField?: keyof T, currentPath?: T[]): T[] | false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Store } from "../Store";
|
|
2
|
+
import { merge } from "./merge";
|
|
3
|
+
import assert from "assert";
|
|
4
|
+
describe("merge", function () {
|
|
5
|
+
it("performs multiple set operations", function () {
|
|
6
|
+
let store = new Store({
|
|
7
|
+
data: {
|
|
8
|
+
person: { firstName: "John", lastName: "Doe" },
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
assert(store.update("person", merge, { firstName: "Johny", age: 18 }));
|
|
12
|
+
assert.deepEqual(store.get("person"), { firstName: "Johny", lastName: "Doe", age: 18 });
|
|
13
|
+
});
|
|
14
|
+
it("does not modify data if not necessary", function () {
|
|
15
|
+
let store = new Store({
|
|
16
|
+
data: {
|
|
17
|
+
person: { firstName: "John", lastName: "Doe" },
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
assert(store.update("person", merge, { firstName: "John" }) == false);
|
|
21
|
+
assert.deepEqual(store.get("person"), { firstName: "John", lastName: "Doe" });
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function removeTreeNodes<T
|
|
1
|
+
export declare function removeTreeNodes<T = any>(array: T[] | undefined, criteria: (node: T) => boolean, childrenField: keyof T): T[] | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { updateTree } from "./updateTree";
|
|
2
|
-
export function removeTreeNodes(array, criteria, childrenField
|
|
2
|
+
export function removeTreeNodes(array, criteria, childrenField) {
|
|
3
3
|
return updateTree(array, (x) => x, () => false, childrenField, criteria);
|
|
4
4
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Store } from "../Store";
|
|
2
|
+
import { removeTreeNodes } from "./removeTreeNodes";
|
|
3
|
+
import assert from "assert";
|
|
4
|
+
describe("removeTreeNodes", function () {
|
|
5
|
+
it("removes all nodes that satisfy criteria", function () {
|
|
6
|
+
let store = new Store({
|
|
7
|
+
data: {
|
|
8
|
+
array: [
|
|
9
|
+
{
|
|
10
|
+
id: "n1",
|
|
11
|
+
value: 1,
|
|
12
|
+
children: [
|
|
13
|
+
{
|
|
14
|
+
id: "n11",
|
|
15
|
+
value: 2,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "n12",
|
|
19
|
+
value: 3,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
assert(store.update("array", removeTreeNodes, (x) => x.value > 1, "children"));
|
|
27
|
+
assert.deepEqual(store.get("array"), [
|
|
28
|
+
{
|
|
29
|
+
id: "n1",
|
|
30
|
+
value: 1,
|
|
31
|
+
children: [],
|
|
32
|
+
},
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Store } from "../Store";
|
|
2
|
+
import { updateArray } from "./updateArray";
|
|
3
|
+
import assert from "assert";
|
|
4
|
+
describe("updateArray", function () {
|
|
5
|
+
it("updates all elements that satisfy criteria", function () {
|
|
6
|
+
let store = new Store({
|
|
7
|
+
data: { array: [1, 2, 3, 4, 5, 6] },
|
|
8
|
+
});
|
|
9
|
+
assert(store.update("array", updateArray, (x) => x + 1, (x) => x > 3));
|
|
10
|
+
assert.deepEqual(store.get("array"), [1, 2, 3, 5, 6, 7]);
|
|
11
|
+
});
|
|
12
|
+
it("does not modify data if not necessary", function () {
|
|
13
|
+
let array = [1, 2, 3, 4, 5, 6];
|
|
14
|
+
let store = new Store({
|
|
15
|
+
data: { array },
|
|
16
|
+
});
|
|
17
|
+
assert(false ===
|
|
18
|
+
store.update("array", updateArray, (x) => x + 1, (x) => x > 10));
|
|
19
|
+
assert(store.get("array") === array);
|
|
20
|
+
});
|
|
21
|
+
it("works with null or undefined", function () {
|
|
22
|
+
let store = new Store();
|
|
23
|
+
assert(false ===
|
|
24
|
+
store.update("array", updateArray, (x) => x + 1, (x) => x > 0));
|
|
25
|
+
});
|
|
26
|
+
it("can remove elements given the criteria", function () {
|
|
27
|
+
let store = new Store({
|
|
28
|
+
data: { array: [1, 2, 3, 4, 5, 6] },
|
|
29
|
+
});
|
|
30
|
+
assert(store.update("array", updateArray, (x) => x + 1, (x) => x > 3, (x) => x <= 3));
|
|
31
|
+
assert.deepEqual(store.get("array"), [5, 6, 7]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function updateTree<T
|
|
1
|
+
export declare function updateTree<T = any>(array: T[] | undefined, updateCallback: (item: T) => T, itemFilter: ((item: T) => boolean) | null, childrenField: keyof T, removeFilter?: (item: T) => boolean): T[] | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Store } from "../Store";
|
|
2
|
+
import { updateTree } from "./updateTree";
|
|
3
|
+
import assert from "assert";
|
|
4
|
+
describe("updateTree", function () {
|
|
5
|
+
it("updates all nodes that satisfy criteria", function () {
|
|
6
|
+
let store = new Store({
|
|
7
|
+
data: {
|
|
8
|
+
array: [
|
|
9
|
+
{
|
|
10
|
+
id: "n1",
|
|
11
|
+
value: 1,
|
|
12
|
+
children: [
|
|
13
|
+
{
|
|
14
|
+
id: "n11",
|
|
15
|
+
value: 2,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "n12",
|
|
19
|
+
value: 3,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
assert(store.update("array", updateTree, (x) => ({ ...x, value: x.value + 1 }), (x) => x.value > 1, "children"));
|
|
27
|
+
assert.deepEqual(store.get("array"), [
|
|
28
|
+
{
|
|
29
|
+
id: "n1",
|
|
30
|
+
value: 1,
|
|
31
|
+
children: [
|
|
32
|
+
{
|
|
33
|
+
id: "n11",
|
|
34
|
+
value: 3,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: "n12",
|
|
38
|
+
value: 4,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx } from "cx/jsx-runtime";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
import { Store } from "../data/Store";
|
|
4
|
+
import { createFunctionalComponent } from "../ui/createFunctionalComponent";
|
|
5
|
+
import { createTestRenderer } from "../util/test/createTestRenderer";
|
|
6
|
+
import { invokeCallback } from "./invokeCallback";
|
|
7
|
+
describe("invokeCallback", () => {
|
|
8
|
+
it("works with functions", () => {
|
|
9
|
+
const FComp = createFunctionalComponent(({ onTest }) => {
|
|
10
|
+
invokeCallback(null, onTest, "works");
|
|
11
|
+
return (_jsx("cx", { children: _jsx("div", {}) }));
|
|
12
|
+
});
|
|
13
|
+
let store = new Store();
|
|
14
|
+
let value;
|
|
15
|
+
const component = createTestRenderer(store, {
|
|
16
|
+
type: FComp,
|
|
17
|
+
onTest: (v) => {
|
|
18
|
+
value = v;
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
component.toJSON();
|
|
22
|
+
assert.equal(value, "works");
|
|
23
|
+
});
|
|
24
|
+
it("works with controller methods", () => {
|
|
25
|
+
const FComp = createFunctionalComponent(({ onTest }) => {
|
|
26
|
+
return (_jsx("cx", { children: _jsx("div", { onExplore: (context, instance) => {
|
|
27
|
+
invokeCallback(instance, onTest, "works");
|
|
28
|
+
} }) }));
|
|
29
|
+
});
|
|
30
|
+
let store = new Store();
|
|
31
|
+
let value;
|
|
32
|
+
const component = createTestRenderer(store, {
|
|
33
|
+
type: FComp,
|
|
34
|
+
onTest: "onTest",
|
|
35
|
+
controller: {
|
|
36
|
+
onTest(v) {
|
|
37
|
+
value = v;
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
component.toJSON();
|
|
42
|
+
assert.equal(value, "works");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "cx/jsx-runtime";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
import { Store } from "../data/Store";
|
|
4
|
+
import { createFunctionalComponent } from "../ui/createFunctionalComponent";
|
|
5
|
+
import { createTestRenderer } from "../util/test/createTestRenderer";
|
|
6
|
+
import { resolveCallback } from "./resolveCallback";
|
|
7
|
+
describe("resolveCallback", () => {
|
|
8
|
+
it("works with functions", () => {
|
|
9
|
+
const FComp = createFunctionalComponent(({ onTest }) => {
|
|
10
|
+
let callback = resolveCallback(onTest);
|
|
11
|
+
assert(typeof callback === 'function');
|
|
12
|
+
callback("works");
|
|
13
|
+
return (_jsx("cx", { children: _jsx("div", {}) }));
|
|
14
|
+
});
|
|
15
|
+
let store = new Store();
|
|
16
|
+
let value;
|
|
17
|
+
const component = createTestRenderer(store, _jsx("cx", { children: _jsx(FComp, { onTest: (v) => { value = v; } }) }));
|
|
18
|
+
component.toJSON();
|
|
19
|
+
assert.equal(value, "works");
|
|
20
|
+
});
|
|
21
|
+
it("works with controller methods", () => {
|
|
22
|
+
const FComp = createFunctionalComponent(({ onTest }) => {
|
|
23
|
+
let callback = resolveCallback(onTest);
|
|
24
|
+
assert(typeof callback === 'function');
|
|
25
|
+
return (_jsx("cx", { children: _jsx("div", { onInit: () => { callback("works"); } }) }));
|
|
26
|
+
});
|
|
27
|
+
let store = new Store();
|
|
28
|
+
let value;
|
|
29
|
+
const component = createTestRenderer(store, _jsx("cx", { children: _jsx(FComp, { onTest: "onTest", controller: {
|
|
30
|
+
onTest(v) { value = v; }
|
|
31
|
+
} }) }));
|
|
32
|
+
component.toJSON();
|
|
33
|
+
assert.equal(value, "works");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsx as _jsx } from "cx/jsx-runtime";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
import { createTestRenderer } from "../util/test/createTestRenderer";
|
|
4
|
+
import { computable } from "../data";
|
|
5
|
+
import { Store } from "../data/Store";
|
|
6
|
+
import { createFunctionalComponent } from "../ui/createFunctionalComponent";
|
|
7
|
+
import { ref } from "./store";
|
|
8
|
+
describe("ref", () => {
|
|
9
|
+
it("allows store references in functional components", () => {
|
|
10
|
+
const FComp = createFunctionalComponent(({}) => {
|
|
11
|
+
let testValue = ref({ bind: "x", defaultValue: 10 });
|
|
12
|
+
return (_jsx("cx", { children: _jsx("div", { text: testValue }) }));
|
|
13
|
+
});
|
|
14
|
+
let store = new Store();
|
|
15
|
+
const component = createTestRenderer(store, FComp);
|
|
16
|
+
let tree = component.toJSON();
|
|
17
|
+
assert.deepEqual(tree, {
|
|
18
|
+
type: "div",
|
|
19
|
+
children: ["10"],
|
|
20
|
+
props: {},
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
it("can be used to adapt any prop passed to a functional component", () => {
|
|
24
|
+
const FComp = createFunctionalComponent(({ value }) => {
|
|
25
|
+
return (_jsx("cx", { children: _jsx("div", { text: computable(ref(value), (value) => `x${value}`) }) }));
|
|
26
|
+
});
|
|
27
|
+
let store = new Store({ data: { value: 100 } });
|
|
28
|
+
function test(value, expectation) {
|
|
29
|
+
const component = createTestRenderer(store, _jsx(FComp, { value: value }));
|
|
30
|
+
let tree = component.toJSON();
|
|
31
|
+
assert.deepEqual(tree, {
|
|
32
|
+
type: "div",
|
|
33
|
+
children: [expectation],
|
|
34
|
+
props: {},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
test({ bind: "value" }, "x100");
|
|
38
|
+
test({ expr: "{value}" }, "x100");
|
|
39
|
+
test({ tpl: "{value:n;2}" }, "x100.00");
|
|
40
|
+
test(200, "x200");
|
|
41
|
+
test(() => 500, "x500");
|
|
42
|
+
test(computable("value", (value) => value + 100), "x200");
|
|
43
|
+
test(null, "xnull");
|
|
44
|
+
test(undefined, "xundefined");
|
|
45
|
+
test(0, "x0");
|
|
46
|
+
test(false, "xfalse");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx } from "cx/jsx-runtime";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
import { createTestRenderer } from "../util/test/createTestRenderer";
|
|
4
|
+
import { Store } from "../data/Store";
|
|
5
|
+
import { createFunctionalComponent } from "../ui/createFunctionalComponent";
|
|
6
|
+
import { useTrigger } from "./useTrigger";
|
|
7
|
+
describe("useTrigger", () => {
|
|
8
|
+
it("works", () => {
|
|
9
|
+
let last = null;
|
|
10
|
+
const FComp = createFunctionalComponent(({ ...props }) => {
|
|
11
|
+
useTrigger(["test"], (test) => {
|
|
12
|
+
last = test;
|
|
13
|
+
});
|
|
14
|
+
return (_jsx("cx", { children: _jsx("div", {}) }));
|
|
15
|
+
});
|
|
16
|
+
let store = new Store();
|
|
17
|
+
let test = store.ref("test", 1);
|
|
18
|
+
const component = createTestRenderer(store, FComp);
|
|
19
|
+
component.toJSON();
|
|
20
|
+
assert.equal(last, null); //trigger did not fire because it didn't receive true as the last argument
|
|
21
|
+
test.set(2);
|
|
22
|
+
component.toJSON();
|
|
23
|
+
assert.equal(last, 2);
|
|
24
|
+
});
|
|
25
|
+
it("fires immediately if the last argument is true", () => {
|
|
26
|
+
let last = null;
|
|
27
|
+
const FComp = createFunctionalComponent(({ ...props }) => {
|
|
28
|
+
useTrigger(["test"], (test) => {
|
|
29
|
+
last = test;
|
|
30
|
+
}, true);
|
|
31
|
+
return (_jsx("cx", { children: _jsx("div", {}) }));
|
|
32
|
+
});
|
|
33
|
+
let store = new Store();
|
|
34
|
+
let test = store.ref("test", 1);
|
|
35
|
+
const component = createTestRenderer(store, FComp);
|
|
36
|
+
component.toJSON();
|
|
37
|
+
assert.equal(last, 1);
|
|
38
|
+
test.set(2);
|
|
39
|
+
component.toJSON();
|
|
40
|
+
assert.equal(last, 2);
|
|
41
|
+
});
|
|
42
|
+
it("accepts refs as arguments", () => {
|
|
43
|
+
let last = null;
|
|
44
|
+
let store = new Store();
|
|
45
|
+
let test = store.ref("test", 1);
|
|
46
|
+
const FComp = createFunctionalComponent(({ ...props }) => {
|
|
47
|
+
useTrigger([test], (test) => {
|
|
48
|
+
last = test;
|
|
49
|
+
}, true);
|
|
50
|
+
return (_jsx("cx", { children: _jsx("div", {}) }));
|
|
51
|
+
});
|
|
52
|
+
const component = createTestRenderer(store, FComp);
|
|
53
|
+
component.toJSON();
|
|
54
|
+
assert.equal(last, 1);
|
|
55
|
+
test.set(2);
|
|
56
|
+
component.toJSON();
|
|
57
|
+
assert.equal(last, 2);
|
|
58
|
+
});
|
|
59
|
+
});
|
package/build/jsx-runtime.d.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import type { JSX as ReactJSX } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import type { ClassProp, Prop } from "./ui/Prop";
|
|
1
|
+
import type { ComponentClass, FunctionComponent, JSX as ReactJSX } from "react";
|
|
2
|
+
import type { CxFunctionalComponent } from "./ui/createFunctionalComponent";
|
|
4
3
|
import { Widget } from "./ui/Widget";
|
|
5
4
|
import { HtmlElementConfig } from "./widgets/HtmlElement";
|
|
6
|
-
import {
|
|
5
|
+
import { ReactElementWrapperConfig } from "./widgets/ReactElementWrapper";
|
|
7
6
|
export declare function jsx(typeName: any, props: any, key?: string): any;
|
|
8
7
|
export declare const jsxs: typeof jsx;
|
|
9
8
|
type ReactIntrinsicElements = ReactJSX.IntrinsicElements;
|
|
10
|
-
type IsEventHandler<K, T> = K extends `on${string}` ? (T extends Function ? true : false) : false;
|
|
11
|
-
type CxEventHandler<T> = T extends (event: infer E) => any ? string | ((event: E, instance: Instance) => void) : string | T;
|
|
12
|
-
type CxIntrinsicElement<T> = {
|
|
13
|
-
[K in keyof T]: K extends "children" ? ChildNode | ChildNode[] : K extends "className" | "class" ? ClassProp : IsEventHandler<K, T[K]> extends true ? CxEventHandler<T[K]> : Prop<T[K]>;
|
|
14
|
-
} & HtmlElementConfig;
|
|
15
9
|
type CxIntrinsicElements = {
|
|
16
|
-
[K in keyof ReactIntrinsicElements]:
|
|
10
|
+
[K in keyof ReactIntrinsicElements]: HtmlElementConfig<K>;
|
|
17
11
|
};
|
|
12
|
+
type TransformReactComponentProps<C, P> = [C] extends [CxFunctionalComponent<any>] ? P : [C] extends [FunctionComponent<any>] ? ReactElementWrapperConfig<P> : [C] extends [ComponentClass<any>] ? ReactElementWrapperConfig<P> : P;
|
|
18
13
|
export declare namespace JSX {
|
|
19
14
|
/**
|
|
20
15
|
* Base class for JSX element instances.
|
|
@@ -28,5 +23,10 @@ export declare namespace JSX {
|
|
|
28
23
|
interface IntrinsicElements extends CxIntrinsicElements {
|
|
29
24
|
cx: any;
|
|
30
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Transform props for React function components used in CxJS JSX.
|
|
28
|
+
* Adds standard WidgetConfig properties and transforms React props to Prop<X>.
|
|
29
|
+
*/
|
|
30
|
+
type LibraryManagedAttributes<C, P> = TransformReactComponentProps<C, P>;
|
|
31
31
|
}
|
|
32
32
|
export {};
|
package/build/jsx-runtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isArray } from "./util/isArray";
|
|
2
2
|
import { isString } from "./util/isString";
|
|
3
3
|
import { HtmlElement } from "./widgets/HtmlElement";
|
|
4
|
+
import { ReactElementWrapper } from "./widgets/ReactElementWrapper";
|
|
4
5
|
export function jsx(typeName, props, key) {
|
|
5
6
|
if (isArray(typeName))
|
|
6
7
|
return typeName;
|
|
@@ -18,6 +19,11 @@ export function jsx(typeName, props, key) {
|
|
|
18
19
|
props.tag = typeName;
|
|
19
20
|
typeName = HtmlElement;
|
|
20
21
|
}
|
|
22
|
+
// React components (functions/classes without isComponentType and not CxJS functional components) should go through ReactElementWrapper
|
|
23
|
+
else if (typeof typeName === "function" && !typeName.isComponentType && !typeName.$isComponentFactory) {
|
|
24
|
+
props.componentType = typeName;
|
|
25
|
+
typeName = ReactElementWrapper;
|
|
26
|
+
}
|
|
21
27
|
return {
|
|
22
28
|
$type: typeName,
|
|
23
29
|
...props,
|
package/build/svg/util/Rect.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class Rect implements IRect {
|
|
|
21
21
|
height(): number;
|
|
22
22
|
valid(): boolean;
|
|
23
23
|
makeValid(): Rect;
|
|
24
|
-
isEqual(r
|
|
24
|
+
isEqual(r?: Rect): boolean;
|
|
25
25
|
static add(a: Rect, b: Rect): Rect;
|
|
26
26
|
static multiply(a: Rect, b: Rect): Rect;
|
|
27
27
|
static margin(r: Rect, m?: RectMargin): Rect;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PureContainerBase, PureContainerConfig } from "./PureContainer";
|
|
2
2
|
import { RenderingContext } from "./RenderingContext";
|
|
3
|
-
import { BooleanProp, StructuredProp,
|
|
3
|
+
import { BooleanProp, StructuredProp, ResolvePropType } from "./Prop";
|
|
4
4
|
import { Instance } from "./Instance";
|
|
5
5
|
/**
|
|
6
6
|
* Configuration for ContentResolver widget.
|
|
@@ -9,9 +9,11 @@ import { Instance } from "./Instance";
|
|
|
9
9
|
* - Literal values (numbers, strings, booleans) preserve their types
|
|
10
10
|
* - AccessorChain<T> resolves to T
|
|
11
11
|
* - Bind/Tpl/Expr resolve to any (type cannot be determined at compile time)
|
|
12
|
+
* - Structured props (objects) have each property resolved individually
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```typescript
|
|
16
|
+
* // Structured params (object)
|
|
15
17
|
* <ContentResolver
|
|
16
18
|
* params={{
|
|
17
19
|
* count: 42, // number
|
|
@@ -21,26 +23,34 @@ import { Instance } from "./Instance";
|
|
|
21
23
|
* // params.count is number, params.name is string
|
|
22
24
|
* }}
|
|
23
25
|
* />
|
|
26
|
+
*
|
|
27
|
+
* // Simple param (single value)
|
|
28
|
+
* <ContentResolver
|
|
29
|
+
* params={model.user.name} // AccessorChain<string>
|
|
30
|
+
* onResolve={(name) => {
|
|
31
|
+
* // name is string
|
|
32
|
+
* }}
|
|
33
|
+
* />
|
|
24
34
|
* ```
|
|
25
35
|
*/
|
|
26
|
-
export interface ContentResolverConfig<P
|
|
27
|
-
/** Parameters that trigger content resolution when changed. */
|
|
36
|
+
export interface ContentResolverConfig<P = StructuredProp> extends PureContainerConfig {
|
|
37
|
+
/** Parameters that trigger content resolution when changed. Can be a structured object or a single Prop. */
|
|
28
38
|
params?: P;
|
|
29
39
|
/**
|
|
30
40
|
* Callback function that resolves content based on params. Can return content directly or a Promise.
|
|
31
41
|
* The params type is inferred from the params property - literal values and AccessorChain<T>
|
|
32
42
|
* preserve their types, while bindings (bind/tpl/expr) resolve to `any`.
|
|
33
43
|
*/
|
|
34
|
-
onResolve?: string | ((params:
|
|
44
|
+
onResolve?: string | ((params: ResolvePropType<P>, instance: Instance) => any);
|
|
35
45
|
/** How to combine resolved content with initial content. Default is 'replace'. */
|
|
36
46
|
mode?: "replace" | "prepend" | "append";
|
|
37
47
|
/** Indicates if content is being loaded. */
|
|
38
48
|
loading?: BooleanProp;
|
|
39
49
|
}
|
|
40
|
-
export declare class ContentResolver<P
|
|
50
|
+
export declare class ContentResolver<P = StructuredProp> extends PureContainerBase<ContentResolverConfig<P>> {
|
|
41
51
|
constructor(config?: ContentResolverConfig<P>);
|
|
42
52
|
mode: "replace" | "prepend" | "append";
|
|
43
|
-
onResolve?: string | ((params:
|
|
53
|
+
onResolve?: string | ((params: ResolvePropType<P>, instance: Instance) => any);
|
|
44
54
|
initialItems: any;
|
|
45
55
|
declareData(...args: any[]): void;
|
|
46
56
|
init(): void;
|
package/build/ui/Controller.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { RenderingContext } from "./RenderingContext";
|
|
|
4
4
|
import { View, ViewMethods } from "../data/View";
|
|
5
5
|
import { Widget } from "./Widget";
|
|
6
6
|
import { Instance } from "./Instance";
|
|
7
|
+
import { AccessorChain } from "../data/createAccessorModelProxy";
|
|
7
8
|
interface ComputableEntry {
|
|
8
9
|
name: string;
|
|
9
10
|
selector: any;
|
|
@@ -17,6 +18,9 @@ export interface ControllerMethods {
|
|
|
17
18
|
addTrigger<Selectors extends readonly ComputableSelector[]>(name: string, args: [...Selectors], callback: (...values: {
|
|
18
19
|
[K in keyof Selectors]: InferSelectorValue<Selectors[K]>;
|
|
19
20
|
}) => any, autoRun?: boolean): void;
|
|
21
|
+
addComputable<T, Selectors extends readonly ComputableSelector[]>(name: AccessorChain<T>, args: [...Selectors], callback: (...values: {
|
|
22
|
+
[K in keyof Selectors]: InferSelectorValue<Selectors[K]>;
|
|
23
|
+
}) => T): void;
|
|
20
24
|
addComputable<Selectors extends readonly ComputableSelector[]>(name: string, args: [...Selectors], callback: (...values: {
|
|
21
25
|
[K in keyof Selectors]: InferSelectorValue<Selectors[K]>;
|
|
22
26
|
}) => any): void;
|
|
@@ -50,6 +54,9 @@ export declare class Controller<D = any> extends Component implements Controller
|
|
|
50
54
|
explore(context: RenderingContext): void;
|
|
51
55
|
prepare(context: RenderingContext): void;
|
|
52
56
|
cleanup(context: RenderingContext): void;
|
|
57
|
+
addComputable<T, Selectors extends readonly ComputableSelector[]>(name: AccessorChain<T>, args: [...Selectors], callback: (...values: {
|
|
58
|
+
[K in keyof Selectors]: InferSelectorValue<Selectors[K]>;
|
|
59
|
+
}) => T): void;
|
|
53
60
|
addComputable<Selectors extends readonly ComputableSelector[]>(name: string, args: [...Selectors], callback: (...values: {
|
|
54
61
|
[K in keyof Selectors]: InferSelectorValue<Selectors[K]>;
|
|
55
62
|
}) => any): void;
|
package/build/ui/Controller.js
CHANGED
|
@@ -54,7 +54,8 @@ export class Controller extends Component {
|
|
|
54
54
|
let selector = computable(...args, callback).memoize();
|
|
55
55
|
if (!this.computables)
|
|
56
56
|
this.computables = {};
|
|
57
|
-
|
|
57
|
+
let nameStr = String(name);
|
|
58
|
+
this.computables[computablePrefix + nameStr] = { name: nameStr, selector, type: "computable" };
|
|
58
59
|
}
|
|
59
60
|
addTrigger(name, args, callback, autoRun) {
|
|
60
61
|
if (!isArray(args))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|