@player-ui/player 0.11.0-next.3 → 0.11.0-next.4
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/Player.native.js +61 -1
- package/dist/Player.native.js.map +1 -1
- package/dist/cjs/index.cjs +61 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +61 -1
- package/dist/index.mjs +61 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/view/builder/index.test.ts +29 -1
- package/src/view/builder/index.ts +29 -1
- package/src/view/parser/types.ts +4 -1
- package/src/view/plugins/__tests__/__snapshots__/template.test.ts.snap +328 -48
- package/src/view/plugins/__tests__/template.test.ts +592 -128
- package/src/view/plugins/template.ts +67 -4
- package/types/view/builder/index.d.ts +8 -0
- package/types/view/parser/types.d.ts +3 -1
- package/types/view/plugins/template.d.ts +4 -1
package/dist/index.legacy-esm.js
CHANGED
|
@@ -3067,10 +3067,32 @@ var Builder = class _Builder {
|
|
|
3067
3067
|
node.children.push(newChild);
|
|
3068
3068
|
return node;
|
|
3069
3069
|
}
|
|
3070
|
+
/**
|
|
3071
|
+
* Updates children of a node of the same path and preserves order
|
|
3072
|
+
*
|
|
3073
|
+
* @param node - The node to update children for
|
|
3074
|
+
* @param pathToMatch - The path to match against child paths
|
|
3075
|
+
* @param mapFn - Function to transform matching children
|
|
3076
|
+
*/
|
|
3077
|
+
static updateChildrenByPath(node, pathToMatch, updateFn) {
|
|
3078
|
+
if (!node.children)
|
|
3079
|
+
return node;
|
|
3080
|
+
const updatedChildren = node.children.map(
|
|
3081
|
+
(child) => (
|
|
3082
|
+
// Check if paths match exactly
|
|
3083
|
+
child.path.join() === pathToMatch.join() ? { ...child, value: updateFn(child) } : child
|
|
3084
|
+
)
|
|
3085
|
+
);
|
|
3086
|
+
return {
|
|
3087
|
+
...node,
|
|
3088
|
+
children: updatedChildren
|
|
3089
|
+
};
|
|
3090
|
+
}
|
|
3070
3091
|
};
|
|
3071
3092
|
|
|
3072
3093
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/player/src/view/plugins/template.ts
|
|
3073
3094
|
import { SyncWaterfallHook as SyncWaterfallHook6 } from "tapable-ts";
|
|
3095
|
+
var templateSymbol = Symbol("template");
|
|
3074
3096
|
var TemplatePlugin = class {
|
|
3075
3097
|
constructor(options) {
|
|
3076
3098
|
this.hooks = {
|
|
@@ -3122,6 +3144,9 @@ var TemplatePlugin = class {
|
|
|
3122
3144
|
override: false,
|
|
3123
3145
|
values
|
|
3124
3146
|
};
|
|
3147
|
+
if (node.placement !== void 0) {
|
|
3148
|
+
result[templateSymbol] = node.placement;
|
|
3149
|
+
}
|
|
3125
3150
|
return result;
|
|
3126
3151
|
}
|
|
3127
3152
|
applyParser(parser) {
|
|
@@ -3135,6 +3160,40 @@ var TemplatePlugin = class {
|
|
|
3135
3160
|
}
|
|
3136
3161
|
return node;
|
|
3137
3162
|
});
|
|
3163
|
+
parser.hooks.onCreateASTNode.tap("template", (node) => {
|
|
3164
|
+
function getTemplateSymbolValue(node2) {
|
|
3165
|
+
if (node2.type === "multi-node" /* MultiNode */) {
|
|
3166
|
+
return node2[templateSymbol];
|
|
3167
|
+
} else if (node2.type === "template" /* Template */) {
|
|
3168
|
+
return node2.placement;
|
|
3169
|
+
}
|
|
3170
|
+
return void 0;
|
|
3171
|
+
}
|
|
3172
|
+
if (node && (node.type === "view" /* View */ || node.type === "asset" /* Asset */) && Array.isArray(node.children)) {
|
|
3173
|
+
node.children = node.children.sort((a, b) => {
|
|
3174
|
+
const aPath = a.path.join();
|
|
3175
|
+
const bPath = b.path.join();
|
|
3176
|
+
const pathsEqual = aPath === bPath;
|
|
3177
|
+
if (pathsEqual) {
|
|
3178
|
+
const aPlacement = getTemplateSymbolValue(a.value);
|
|
3179
|
+
const bPlacement = getTemplateSymbolValue(b.value);
|
|
3180
|
+
if (aPlacement !== void 0 && bPlacement === void 0) {
|
|
3181
|
+
return aPlacement === "prepend" ? -1 : 1;
|
|
3182
|
+
} else if (bPlacement !== void 0 && aPlacement === void 0) {
|
|
3183
|
+
return bPlacement === "prepend" ? 1 : -1;
|
|
3184
|
+
} else if (aPlacement !== void 0 && bPlacement !== void 0) {
|
|
3185
|
+
if (aPlacement === bPlacement) {
|
|
3186
|
+
return 0;
|
|
3187
|
+
}
|
|
3188
|
+
return aPlacement === "prepend" ? -1 : 1;
|
|
3189
|
+
}
|
|
3190
|
+
return 0;
|
|
3191
|
+
}
|
|
3192
|
+
return aPath > bPath ? 1 : -1;
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
return node;
|
|
3196
|
+
});
|
|
3138
3197
|
parser.hooks.parseNode.tap(
|
|
3139
3198
|
"template",
|
|
3140
3199
|
(obj, _nodeType, options, childOptions) => {
|
|
@@ -3146,7 +3205,8 @@ var TemplatePlugin = class {
|
|
|
3146
3205
|
depth: options.templateDepth ?? 0,
|
|
3147
3206
|
data: template.data,
|
|
3148
3207
|
template: template.value,
|
|
3149
|
-
dynamic: template.dynamic ?? false
|
|
3208
|
+
dynamic: template.dynamic ?? false,
|
|
3209
|
+
placement: template.placement
|
|
3150
3210
|
},
|
|
3151
3211
|
template
|
|
3152
3212
|
);
|
package/dist/index.mjs
CHANGED
|
@@ -3067,10 +3067,32 @@ var Builder = class _Builder {
|
|
|
3067
3067
|
node.children.push(newChild);
|
|
3068
3068
|
return node;
|
|
3069
3069
|
}
|
|
3070
|
+
/**
|
|
3071
|
+
* Updates children of a node of the same path and preserves order
|
|
3072
|
+
*
|
|
3073
|
+
* @param node - The node to update children for
|
|
3074
|
+
* @param pathToMatch - The path to match against child paths
|
|
3075
|
+
* @param mapFn - Function to transform matching children
|
|
3076
|
+
*/
|
|
3077
|
+
static updateChildrenByPath(node, pathToMatch, updateFn) {
|
|
3078
|
+
if (!node.children)
|
|
3079
|
+
return node;
|
|
3080
|
+
const updatedChildren = node.children.map(
|
|
3081
|
+
(child) => (
|
|
3082
|
+
// Check if paths match exactly
|
|
3083
|
+
child.path.join() === pathToMatch.join() ? { ...child, value: updateFn(child) } : child
|
|
3084
|
+
)
|
|
3085
|
+
);
|
|
3086
|
+
return {
|
|
3087
|
+
...node,
|
|
3088
|
+
children: updatedChildren
|
|
3089
|
+
};
|
|
3090
|
+
}
|
|
3070
3091
|
};
|
|
3071
3092
|
|
|
3072
3093
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/player/src/view/plugins/template.ts
|
|
3073
3094
|
import { SyncWaterfallHook as SyncWaterfallHook6 } from "tapable-ts";
|
|
3095
|
+
var templateSymbol = Symbol("template");
|
|
3074
3096
|
var TemplatePlugin = class {
|
|
3075
3097
|
constructor(options) {
|
|
3076
3098
|
this.hooks = {
|
|
@@ -3122,6 +3144,9 @@ var TemplatePlugin = class {
|
|
|
3122
3144
|
override: false,
|
|
3123
3145
|
values
|
|
3124
3146
|
};
|
|
3147
|
+
if (node.placement !== void 0) {
|
|
3148
|
+
result[templateSymbol] = node.placement;
|
|
3149
|
+
}
|
|
3125
3150
|
return result;
|
|
3126
3151
|
}
|
|
3127
3152
|
applyParser(parser) {
|
|
@@ -3135,6 +3160,40 @@ var TemplatePlugin = class {
|
|
|
3135
3160
|
}
|
|
3136
3161
|
return node;
|
|
3137
3162
|
});
|
|
3163
|
+
parser.hooks.onCreateASTNode.tap("template", (node) => {
|
|
3164
|
+
function getTemplateSymbolValue(node2) {
|
|
3165
|
+
if (node2.type === "multi-node" /* MultiNode */) {
|
|
3166
|
+
return node2[templateSymbol];
|
|
3167
|
+
} else if (node2.type === "template" /* Template */) {
|
|
3168
|
+
return node2.placement;
|
|
3169
|
+
}
|
|
3170
|
+
return void 0;
|
|
3171
|
+
}
|
|
3172
|
+
if (node && (node.type === "view" /* View */ || node.type === "asset" /* Asset */) && Array.isArray(node.children)) {
|
|
3173
|
+
node.children = node.children.sort((a, b) => {
|
|
3174
|
+
const aPath = a.path.join();
|
|
3175
|
+
const bPath = b.path.join();
|
|
3176
|
+
const pathsEqual = aPath === bPath;
|
|
3177
|
+
if (pathsEqual) {
|
|
3178
|
+
const aPlacement = getTemplateSymbolValue(a.value);
|
|
3179
|
+
const bPlacement = getTemplateSymbolValue(b.value);
|
|
3180
|
+
if (aPlacement !== void 0 && bPlacement === void 0) {
|
|
3181
|
+
return aPlacement === "prepend" ? -1 : 1;
|
|
3182
|
+
} else if (bPlacement !== void 0 && aPlacement === void 0) {
|
|
3183
|
+
return bPlacement === "prepend" ? 1 : -1;
|
|
3184
|
+
} else if (aPlacement !== void 0 && bPlacement !== void 0) {
|
|
3185
|
+
if (aPlacement === bPlacement) {
|
|
3186
|
+
return 0;
|
|
3187
|
+
}
|
|
3188
|
+
return aPlacement === "prepend" ? -1 : 1;
|
|
3189
|
+
}
|
|
3190
|
+
return 0;
|
|
3191
|
+
}
|
|
3192
|
+
return aPath > bPath ? 1 : -1;
|
|
3193
|
+
});
|
|
3194
|
+
}
|
|
3195
|
+
return node;
|
|
3196
|
+
});
|
|
3138
3197
|
parser.hooks.parseNode.tap(
|
|
3139
3198
|
"template",
|
|
3140
3199
|
(obj, _nodeType, options, childOptions) => {
|
|
@@ -3146,7 +3205,8 @@ var TemplatePlugin = class {
|
|
|
3146
3205
|
depth: options.templateDepth ?? 0,
|
|
3147
3206
|
data: template.data,
|
|
3148
3207
|
template: template.value,
|
|
3149
|
-
dynamic: template.dynamic ?? false
|
|
3208
|
+
dynamic: template.dynamic ?? false,
|
|
3209
|
+
placement: template.placement
|
|
3150
3210
|
},
|
|
3151
3211
|
template
|
|
3152
3212
|
);
|