@player-ui/data-change-listener-plugin 0.4.0 → 0.4.1-next.1
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.cjs.js +35 -6
- package/dist/index.esm.js +35 -6
- package/package.json +10 -2
- package/src/index.ts +22 -7
package/dist/index.cjs.js
CHANGED
|
@@ -2,18 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var player = require('@player-ui/player');
|
|
6
|
+
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __objRest = (source, exclude) => {
|
|
11
|
+
var target = {};
|
|
12
|
+
for (var prop in source)
|
|
13
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
14
|
+
target[prop] = source[prop];
|
|
15
|
+
if (source != null && __getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
17
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
18
|
+
target[prop] = source[prop];
|
|
19
|
+
}
|
|
20
|
+
return target;
|
|
21
|
+
};
|
|
5
22
|
const LISTENER_TYPES = {
|
|
6
23
|
dataChange: "dataChange."
|
|
7
24
|
};
|
|
8
25
|
const WILDCARD_REGEX = /\._\.|\._$/;
|
|
9
|
-
function replaceExpressionIndexes(
|
|
26
|
+
function replaceExpressionIndexes(expression, indexes) {
|
|
10
27
|
if (indexes.length === 0) {
|
|
11
|
-
return
|
|
28
|
+
return expression;
|
|
12
29
|
}
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
30
|
+
if (player.isExpressionNode(expression)) {
|
|
31
|
+
return expression;
|
|
15
32
|
}
|
|
16
|
-
|
|
33
|
+
if (Array.isArray(expression)) {
|
|
34
|
+
return expression.map((subExp) => replaceExpressionIndexes(subExp, indexes));
|
|
35
|
+
}
|
|
36
|
+
let workingExp = String(expression);
|
|
17
37
|
for (let replacementIndex = 0; replacementIndex < indexes.length; replacementIndex += 1) {
|
|
18
38
|
const regex = new RegExp(`_index${replacementIndex === 0 ? "" : replacementIndex.toString()}_`, "g");
|
|
19
39
|
workingExp = workingExp.replace(regex, indexes[replacementIndex].toString());
|
|
@@ -99,7 +119,12 @@ class DataChangeListenerPlugin {
|
|
|
99
119
|
const { silent = false } = options || {};
|
|
100
120
|
if (silent)
|
|
101
121
|
return;
|
|
102
|
-
|
|
122
|
+
const validUpdates = updates.filter((update) => {
|
|
123
|
+
var _a;
|
|
124
|
+
const committedVal = (_a = options == null ? void 0 : options.context) == null ? void 0 : _a.model.get(update.binding);
|
|
125
|
+
return committedVal === update.newValue;
|
|
126
|
+
});
|
|
127
|
+
onFieldUpdateHandler(validUpdates.map((t) => t.binding));
|
|
103
128
|
}));
|
|
104
129
|
const resolveViewInterceptor = {
|
|
105
130
|
call: (view) => {
|
|
@@ -112,6 +137,10 @@ class DataChangeListenerPlugin {
|
|
|
112
137
|
};
|
|
113
138
|
player.hooks.viewController.tap(this.name, (viewController) => {
|
|
114
139
|
viewController.hooks.resolveView.intercept(resolveViewInterceptor);
|
|
140
|
+
viewController.hooks.resolveView.tap(this.name, (view) => {
|
|
141
|
+
const _a = view, withoutListeners = __objRest(_a, ["listeners"]);
|
|
142
|
+
return withoutListeners;
|
|
143
|
+
});
|
|
115
144
|
});
|
|
116
145
|
player.hooks.flowController.tap(this.name, (flowController) => {
|
|
117
146
|
flowController.hooks.flow.tap(this.name, (flow) => {
|
package/dist/index.esm.js
CHANGED
|
@@ -1,15 +1,35 @@
|
|
|
1
|
+
import { isExpressionNode } from '@player-ui/player';
|
|
2
|
+
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var __objRest = (source, exclude) => {
|
|
7
|
+
var target = {};
|
|
8
|
+
for (var prop in source)
|
|
9
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
10
|
+
target[prop] = source[prop];
|
|
11
|
+
if (source != null && __getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
13
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
14
|
+
target[prop] = source[prop];
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
1
18
|
const LISTENER_TYPES = {
|
|
2
19
|
dataChange: "dataChange."
|
|
3
20
|
};
|
|
4
21
|
const WILDCARD_REGEX = /\._\.|\._$/;
|
|
5
|
-
function replaceExpressionIndexes(
|
|
22
|
+
function replaceExpressionIndexes(expression, indexes) {
|
|
6
23
|
if (indexes.length === 0) {
|
|
7
|
-
return
|
|
24
|
+
return expression;
|
|
8
25
|
}
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
26
|
+
if (isExpressionNode(expression)) {
|
|
27
|
+
return expression;
|
|
11
28
|
}
|
|
12
|
-
|
|
29
|
+
if (Array.isArray(expression)) {
|
|
30
|
+
return expression.map((subExp) => replaceExpressionIndexes(subExp, indexes));
|
|
31
|
+
}
|
|
32
|
+
let workingExp = String(expression);
|
|
13
33
|
for (let replacementIndex = 0; replacementIndex < indexes.length; replacementIndex += 1) {
|
|
14
34
|
const regex = new RegExp(`_index${replacementIndex === 0 ? "" : replacementIndex.toString()}_`, "g");
|
|
15
35
|
workingExp = workingExp.replace(regex, indexes[replacementIndex].toString());
|
|
@@ -95,7 +115,12 @@ class DataChangeListenerPlugin {
|
|
|
95
115
|
const { silent = false } = options || {};
|
|
96
116
|
if (silent)
|
|
97
117
|
return;
|
|
98
|
-
|
|
118
|
+
const validUpdates = updates.filter((update) => {
|
|
119
|
+
var _a;
|
|
120
|
+
const committedVal = (_a = options == null ? void 0 : options.context) == null ? void 0 : _a.model.get(update.binding);
|
|
121
|
+
return committedVal === update.newValue;
|
|
122
|
+
});
|
|
123
|
+
onFieldUpdateHandler(validUpdates.map((t) => t.binding));
|
|
99
124
|
}));
|
|
100
125
|
const resolveViewInterceptor = {
|
|
101
126
|
call: (view) => {
|
|
@@ -108,6 +133,10 @@ class DataChangeListenerPlugin {
|
|
|
108
133
|
};
|
|
109
134
|
player.hooks.viewController.tap(this.name, (viewController) => {
|
|
110
135
|
viewController.hooks.resolveView.intercept(resolveViewInterceptor);
|
|
136
|
+
viewController.hooks.resolveView.tap(this.name, (view) => {
|
|
137
|
+
const _a = view, withoutListeners = __objRest(_a, ["listeners"]);
|
|
138
|
+
return withoutListeners;
|
|
139
|
+
});
|
|
111
140
|
});
|
|
112
141
|
player.hooks.flowController.tap(this.name, (flowController) => {
|
|
113
142
|
flowController.hooks.flow.tap(this.name, (flow) => {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-ui/data-change-listener-plugin",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1-next.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@player-ui/player": "0.4.
|
|
9
|
+
"@player-ui/player": "0.4.1-next.1"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/runtime": "7.15.4"
|
|
@@ -52,6 +52,14 @@
|
|
|
52
52
|
{
|
|
53
53
|
"name": "Kelly Harrop",
|
|
54
54
|
"url": "https://github.com/kharrop"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "Alejandro Fimbres",
|
|
58
|
+
"url": "https://github.com/lexfm"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"name": "Rafael Campos",
|
|
62
|
+
"url": "https://github.com/rafbcampos"
|
|
55
63
|
}
|
|
56
64
|
]
|
|
57
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
BindingInstance,
|
|
10
10
|
BindingParser,
|
|
11
11
|
} from '@player-ui/player';
|
|
12
|
+
import { isExpressionNode } from '@player-ui/player';
|
|
12
13
|
|
|
13
14
|
const LISTENER_TYPES = {
|
|
14
15
|
dataChange: 'dataChange.',
|
|
@@ -35,20 +36,24 @@ export type ViewListenerHandler = (
|
|
|
35
36
|
|
|
36
37
|
/** Sub out any _index_ refs with the ones from the supplied list */
|
|
37
38
|
function replaceExpressionIndexes(
|
|
38
|
-
|
|
39
|
+
expression: ExpressionType,
|
|
39
40
|
indexes: Array<string | number>
|
|
40
41
|
): ExpressionType {
|
|
41
42
|
if (indexes.length === 0) {
|
|
42
|
-
return
|
|
43
|
+
return expression;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
if (
|
|
46
|
-
return
|
|
46
|
+
if (isExpressionNode(expression)) {
|
|
47
|
+
return expression;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (Array.isArray(expression)) {
|
|
51
|
+
return expression.map((subExp) =>
|
|
47
52
|
replaceExpressionIndexes(subExp, indexes)
|
|
48
|
-
);
|
|
53
|
+
) as any;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
let workingExp = String(
|
|
56
|
+
let workingExp = String(expression);
|
|
52
57
|
|
|
53
58
|
for (
|
|
54
59
|
let replacementIndex = 0;
|
|
@@ -230,7 +235,11 @@ export class DataChangeListenerPlugin implements PlayerPlugin {
|
|
|
230
235
|
dc.hooks.onUpdate.tap(this.name, (updates, options) => {
|
|
231
236
|
const { silent = false } = options || {};
|
|
232
237
|
if (silent) return;
|
|
233
|
-
|
|
238
|
+
const validUpdates = updates.filter((update) => {
|
|
239
|
+
const committedVal = options?.context?.model.get(update.binding);
|
|
240
|
+
return committedVal === update.newValue;
|
|
241
|
+
});
|
|
242
|
+
onFieldUpdateHandler(validUpdates.map((t) => t.binding));
|
|
234
243
|
})
|
|
235
244
|
);
|
|
236
245
|
|
|
@@ -261,6 +270,12 @@ export class DataChangeListenerPlugin implements PlayerPlugin {
|
|
|
261
270
|
this.name,
|
|
262
271
|
(viewController: ViewController) => {
|
|
263
272
|
viewController.hooks.resolveView.intercept(resolveViewInterceptor);
|
|
273
|
+
|
|
274
|
+
// remove listeners after extracting so that it does not get triggered in subsequent view updates
|
|
275
|
+
viewController.hooks.resolveView.tap(this.name, (view) => {
|
|
276
|
+
const { listeners, ...withoutListeners } = view as any;
|
|
277
|
+
return withoutListeners;
|
|
278
|
+
});
|
|
264
279
|
}
|
|
265
280
|
);
|
|
266
281
|
|