@player-ui/data-change-listener-plugin 0.3.1-next.1 → 0.3.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 +39 -7
- package/dist/index.esm.js +39 -7
- package/package.json +10 -2
- package/src/index.ts +25 -8
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;
|
|
29
|
+
}
|
|
30
|
+
if (player.isExpressionNode(expression)) {
|
|
31
|
+
return expression;
|
|
12
32
|
}
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
33
|
+
if (Array.isArray(expression)) {
|
|
34
|
+
return expression.map((subExp) => replaceExpressionIndexes(subExp, indexes));
|
|
15
35
|
}
|
|
16
|
-
let workingExp = String(
|
|
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());
|
|
@@ -95,8 +115,16 @@ class DataChangeListenerPlugin {
|
|
|
95
115
|
});
|
|
96
116
|
});
|
|
97
117
|
};
|
|
98
|
-
player.hooks.dataController.tap(this.name, (dc) => dc.hooks.onUpdate.tap(this.name, (updates) => {
|
|
99
|
-
|
|
118
|
+
player.hooks.dataController.tap(this.name, (dc) => dc.hooks.onUpdate.tap(this.name, (updates, options) => {
|
|
119
|
+
const { silent = false } = options || {};
|
|
120
|
+
if (silent)
|
|
121
|
+
return;
|
|
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));
|
|
100
128
|
}));
|
|
101
129
|
const resolveViewInterceptor = {
|
|
102
130
|
call: (view) => {
|
|
@@ -109,6 +137,10 @@ class DataChangeListenerPlugin {
|
|
|
109
137
|
};
|
|
110
138
|
player.hooks.viewController.tap(this.name, (viewController) => {
|
|
111
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
|
+
});
|
|
112
144
|
});
|
|
113
145
|
player.hooks.flowController.tap(this.name, (flowController) => {
|
|
114
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;
|
|
25
|
+
}
|
|
26
|
+
if (isExpressionNode(expression)) {
|
|
27
|
+
return expression;
|
|
8
28
|
}
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
29
|
+
if (Array.isArray(expression)) {
|
|
30
|
+
return expression.map((subExp) => replaceExpressionIndexes(subExp, indexes));
|
|
11
31
|
}
|
|
12
|
-
let workingExp = String(
|
|
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());
|
|
@@ -91,8 +111,16 @@ class DataChangeListenerPlugin {
|
|
|
91
111
|
});
|
|
92
112
|
});
|
|
93
113
|
};
|
|
94
|
-
player.hooks.dataController.tap(this.name, (dc) => dc.hooks.onUpdate.tap(this.name, (updates) => {
|
|
95
|
-
|
|
114
|
+
player.hooks.dataController.tap(this.name, (dc) => dc.hooks.onUpdate.tap(this.name, (updates, options) => {
|
|
115
|
+
const { silent = false } = options || {};
|
|
116
|
+
if (silent)
|
|
117
|
+
return;
|
|
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));
|
|
96
124
|
}));
|
|
97
125
|
const resolveViewInterceptor = {
|
|
98
126
|
call: (view) => {
|
|
@@ -105,6 +133,10 @@ class DataChangeListenerPlugin {
|
|
|
105
133
|
};
|
|
106
134
|
player.hooks.viewController.tap(this.name, (viewController) => {
|
|
107
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
|
+
});
|
|
108
140
|
});
|
|
109
141
|
player.hooks.flowController.tap(this.name, (flowController) => {
|
|
110
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.3.1
|
|
3
|
+
"version": "0.3.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.3.1
|
|
9
|
+
"@player-ui/player": "0.3.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;
|
|
@@ -227,8 +232,14 @@ export class DataChangeListenerPlugin implements PlayerPlugin {
|
|
|
227
232
|
};
|
|
228
233
|
|
|
229
234
|
player.hooks.dataController.tap(this.name, (dc: DataController) =>
|
|
230
|
-
dc.hooks.onUpdate.tap(this.name, (updates) => {
|
|
231
|
-
|
|
235
|
+
dc.hooks.onUpdate.tap(this.name, (updates, options) => {
|
|
236
|
+
const { silent = false } = options || {};
|
|
237
|
+
if (silent) return;
|
|
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));
|
|
232
243
|
})
|
|
233
244
|
);
|
|
234
245
|
|
|
@@ -259,6 +270,12 @@ export class DataChangeListenerPlugin implements PlayerPlugin {
|
|
|
259
270
|
this.name,
|
|
260
271
|
(viewController: ViewController) => {
|
|
261
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
|
+
});
|
|
262
279
|
}
|
|
263
280
|
);
|
|
264
281
|
|