@merkur/core 0.32.0 → 0.34.0
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/lib/index.cjs +19 -6
- package/lib/index.es9.cjs +11 -0
- package/lib/index.es9.mjs +11 -1
- package/lib/index.js +19 -6
- package/lib/index.mjs +19 -7
- package/lib/index.umd.js +1 -1
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -45,7 +45,7 @@ function parsePath(widget, path = '') {
|
|
|
45
45
|
|
|
46
46
|
if (!isFunction(target[methodName])) {
|
|
47
47
|
throw new Error(
|
|
48
|
-
`Defined path '${path}' is incorrect. Check your widget structure
|
|
48
|
+
`Defined path '${path}' is incorrect. Check your widget structure.`,
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -56,6 +56,18 @@ function isFunction(value) {
|
|
|
56
56
|
return typeof value === 'function';
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
function assignMissingKeys(target, ...sources) {
|
|
60
|
+
sources.forEach((source) => {
|
|
61
|
+
Object.keys(source || {}).forEach((key) => {
|
|
62
|
+
if (!(key in target)) {
|
|
63
|
+
target[key] = source[key];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return target;
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
async function callPluginMethod(widget, method, args) {
|
|
60
72
|
for (const plugin of widget.$plugins) {
|
|
61
73
|
if (isFunction(plugin[method])) {
|
|
@@ -74,7 +86,7 @@ async function createMerkurWidget(widgetDefinition = {}) {
|
|
|
74
86
|
widgetDefinition = setDefaultValueForUndefined(
|
|
75
87
|
widgetDefinition,
|
|
76
88
|
['setup', 'create'],
|
|
77
|
-
(widget) => widget
|
|
89
|
+
(widget) => widget,
|
|
78
90
|
);
|
|
79
91
|
|
|
80
92
|
const { setup, create } = widgetDefinition;
|
|
@@ -91,7 +103,7 @@ async function createMerkurWidget(widgetDefinition = {}) {
|
|
|
91
103
|
return create(widget, ...rest);
|
|
92
104
|
},
|
|
93
105
|
$plugins: (widgetDefinition.$plugins || []).map((pluginFactory) =>
|
|
94
|
-
pluginFactory()
|
|
106
|
+
pluginFactory(),
|
|
95
107
|
),
|
|
96
108
|
};
|
|
97
109
|
|
|
@@ -135,7 +147,7 @@ function create(widgetProperties = {}) {
|
|
|
135
147
|
throw new Error(
|
|
136
148
|
`The widget with defined name and version "${
|
|
137
149
|
name + version
|
|
138
|
-
}" is not defined
|
|
150
|
+
}" is not defined.`,
|
|
139
151
|
);
|
|
140
152
|
}
|
|
141
153
|
|
|
@@ -185,8 +197,8 @@ function isRegistered(name) {
|
|
|
185
197
|
|
|
186
198
|
return Boolean(
|
|
187
199
|
Object.keys(merkur.$in.widgetFactory).find((key) =>
|
|
188
|
-
new RegExp(`^${name}`).test(key)
|
|
189
|
-
)
|
|
200
|
+
new RegExp(`^${name}`).test(key),
|
|
201
|
+
),
|
|
190
202
|
);
|
|
191
203
|
}
|
|
192
204
|
|
|
@@ -207,6 +219,7 @@ function getGlobalContext() {
|
|
|
207
219
|
return {};
|
|
208
220
|
}
|
|
209
221
|
|
|
222
|
+
exports.assignMissingKeys = assignMissingKeys;
|
|
210
223
|
exports.bindWidgetToFunctions = bindWidgetToFunctions;
|
|
211
224
|
exports.createMerkur = createMerkur;
|
|
212
225
|
exports.createMerkurWidget = createMerkurWidget;
|
package/lib/index.es9.cjs
CHANGED
|
@@ -49,6 +49,16 @@ function parsePath(widget, path = '') {
|
|
|
49
49
|
function isFunction(value) {
|
|
50
50
|
return typeof value === 'function';
|
|
51
51
|
}
|
|
52
|
+
function assignMissingKeys(target, ...sources) {
|
|
53
|
+
sources.forEach(source => {
|
|
54
|
+
Object.keys(source || {}).forEach(key => {
|
|
55
|
+
if (!(key in target)) {
|
|
56
|
+
target[key] = source[key];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
return target;
|
|
61
|
+
}
|
|
52
62
|
async function callPluginMethod(widget, method, args) {
|
|
53
63
|
for (const plugin of widget.$plugins) {
|
|
54
64
|
if (isFunction(plugin[method])) {
|
|
@@ -166,6 +176,7 @@ function getGlobalContext() {
|
|
|
166
176
|
}
|
|
167
177
|
return {};
|
|
168
178
|
}
|
|
179
|
+
exports.assignMissingKeys = assignMissingKeys;
|
|
169
180
|
exports.bindWidgetToFunctions = bindWidgetToFunctions;
|
|
170
181
|
exports.createMerkur = createMerkur;
|
|
171
182
|
exports.createMerkurWidget = createMerkurWidget;
|
package/lib/index.es9.mjs
CHANGED
|
@@ -47,6 +47,16 @@ function parsePath(widget, path = '') {
|
|
|
47
47
|
function isFunction(value) {
|
|
48
48
|
return typeof value === 'function';
|
|
49
49
|
}
|
|
50
|
+
function assignMissingKeys(target, ...sources) {
|
|
51
|
+
sources.forEach(source => {
|
|
52
|
+
Object.keys(source || {}).forEach(key => {
|
|
53
|
+
if (!(key in target)) {
|
|
54
|
+
target[key] = source[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
return target;
|
|
59
|
+
}
|
|
50
60
|
async function callPluginMethod(widget, method, args) {
|
|
51
61
|
for (const plugin of widget.$plugins) {
|
|
52
62
|
if (isFunction(plugin[method])) {
|
|
@@ -164,4 +174,4 @@ function getGlobalContext() {
|
|
|
164
174
|
}
|
|
165
175
|
return {};
|
|
166
176
|
}
|
|
167
|
-
export { bindWidgetToFunctions, createMerkur, createMerkurWidget, getMerkur, hookMethod, isFunction, removeMerkur, setDefaultValueForUndefined };
|
|
177
|
+
export { assignMissingKeys, bindWidgetToFunctions, createMerkur, createMerkurWidget, getMerkur, hookMethod, isFunction, removeMerkur, setDefaultValueForUndefined };
|
package/lib/index.js
CHANGED
|
@@ -45,7 +45,7 @@ function parsePath(widget, path = '') {
|
|
|
45
45
|
|
|
46
46
|
if (!isFunction(target[methodName])) {
|
|
47
47
|
throw new Error(
|
|
48
|
-
`Defined path '${path}' is incorrect. Check your widget structure
|
|
48
|
+
`Defined path '${path}' is incorrect. Check your widget structure.`,
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -56,6 +56,18 @@ function isFunction(value) {
|
|
|
56
56
|
return typeof value === 'function';
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
function assignMissingKeys(target, ...sources) {
|
|
60
|
+
sources.forEach((source) => {
|
|
61
|
+
Object.keys(source || {}).forEach((key) => {
|
|
62
|
+
if (!(key in target)) {
|
|
63
|
+
target[key] = source[key];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return target;
|
|
69
|
+
}
|
|
70
|
+
|
|
59
71
|
async function callPluginMethod(widget, method, args) {
|
|
60
72
|
for (const plugin of widget.$plugins) {
|
|
61
73
|
if (isFunction(plugin[method])) {
|
|
@@ -74,7 +86,7 @@ async function createMerkurWidget(widgetDefinition = {}) {
|
|
|
74
86
|
widgetDefinition = setDefaultValueForUndefined(
|
|
75
87
|
widgetDefinition,
|
|
76
88
|
['setup', 'create'],
|
|
77
|
-
(widget) => widget
|
|
89
|
+
(widget) => widget,
|
|
78
90
|
);
|
|
79
91
|
|
|
80
92
|
const { setup, create } = widgetDefinition;
|
|
@@ -91,7 +103,7 @@ async function createMerkurWidget(widgetDefinition = {}) {
|
|
|
91
103
|
return create(widget, ...rest);
|
|
92
104
|
},
|
|
93
105
|
$plugins: (widgetDefinition.$plugins || []).map((pluginFactory) =>
|
|
94
|
-
pluginFactory()
|
|
106
|
+
pluginFactory(),
|
|
95
107
|
),
|
|
96
108
|
};
|
|
97
109
|
|
|
@@ -135,7 +147,7 @@ function create(widgetProperties = {}) {
|
|
|
135
147
|
throw new Error(
|
|
136
148
|
`The widget with defined name and version "${
|
|
137
149
|
name + version
|
|
138
|
-
}" is not defined
|
|
150
|
+
}" is not defined.`,
|
|
139
151
|
);
|
|
140
152
|
}
|
|
141
153
|
|
|
@@ -185,8 +197,8 @@ function isRegistered(name) {
|
|
|
185
197
|
|
|
186
198
|
return Boolean(
|
|
187
199
|
Object.keys(merkur.$in.widgetFactory).find((key) =>
|
|
188
|
-
new RegExp(`^${name}`).test(key)
|
|
189
|
-
)
|
|
200
|
+
new RegExp(`^${name}`).test(key),
|
|
201
|
+
),
|
|
190
202
|
);
|
|
191
203
|
}
|
|
192
204
|
|
|
@@ -207,6 +219,7 @@ function getGlobalContext() {
|
|
|
207
219
|
return {};
|
|
208
220
|
}
|
|
209
221
|
|
|
222
|
+
exports.assignMissingKeys = assignMissingKeys;
|
|
210
223
|
exports.bindWidgetToFunctions = bindWidgetToFunctions;
|
|
211
224
|
exports.createMerkur = createMerkur;
|
|
212
225
|
exports.createMerkurWidget = createMerkurWidget;
|
package/lib/index.mjs
CHANGED
|
@@ -43,7 +43,7 @@ function parsePath(widget, path = '') {
|
|
|
43
43
|
|
|
44
44
|
if (!isFunction(target[methodName])) {
|
|
45
45
|
throw new Error(
|
|
46
|
-
`Defined path '${path}' is incorrect. Check your widget structure
|
|
46
|
+
`Defined path '${path}' is incorrect. Check your widget structure.`,
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -54,6 +54,18 @@ function isFunction(value) {
|
|
|
54
54
|
return typeof value === 'function';
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
function assignMissingKeys(target, ...sources) {
|
|
58
|
+
sources.forEach((source) => {
|
|
59
|
+
Object.keys(source || {}).forEach((key) => {
|
|
60
|
+
if (!(key in target)) {
|
|
61
|
+
target[key] = source[key];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return target;
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
async function callPluginMethod(widget, method, args) {
|
|
58
70
|
for (const plugin of widget.$plugins) {
|
|
59
71
|
if (isFunction(plugin[method])) {
|
|
@@ -72,7 +84,7 @@ async function createMerkurWidget(widgetDefinition = {}) {
|
|
|
72
84
|
widgetDefinition = setDefaultValueForUndefined(
|
|
73
85
|
widgetDefinition,
|
|
74
86
|
['setup', 'create'],
|
|
75
|
-
(widget) => widget
|
|
87
|
+
(widget) => widget,
|
|
76
88
|
);
|
|
77
89
|
|
|
78
90
|
const { setup, create } = widgetDefinition;
|
|
@@ -89,7 +101,7 @@ async function createMerkurWidget(widgetDefinition = {}) {
|
|
|
89
101
|
return create(widget, ...rest);
|
|
90
102
|
},
|
|
91
103
|
$plugins: (widgetDefinition.$plugins || []).map((pluginFactory) =>
|
|
92
|
-
pluginFactory()
|
|
104
|
+
pluginFactory(),
|
|
93
105
|
),
|
|
94
106
|
};
|
|
95
107
|
|
|
@@ -133,7 +145,7 @@ function create(widgetProperties = {}) {
|
|
|
133
145
|
throw new Error(
|
|
134
146
|
`The widget with defined name and version "${
|
|
135
147
|
name + version
|
|
136
|
-
}" is not defined
|
|
148
|
+
}" is not defined.`,
|
|
137
149
|
);
|
|
138
150
|
}
|
|
139
151
|
|
|
@@ -183,8 +195,8 @@ function isRegistered(name) {
|
|
|
183
195
|
|
|
184
196
|
return Boolean(
|
|
185
197
|
Object.keys(merkur.$in.widgetFactory).find((key) =>
|
|
186
|
-
new RegExp(`^${name}`).test(key)
|
|
187
|
-
)
|
|
198
|
+
new RegExp(`^${name}`).test(key),
|
|
199
|
+
),
|
|
188
200
|
);
|
|
189
201
|
}
|
|
190
202
|
|
|
@@ -205,4 +217,4 @@ function getGlobalContext() {
|
|
|
205
217
|
return {};
|
|
206
218
|
}
|
|
207
219
|
|
|
208
|
-
export { bindWidgetToFunctions, createMerkur, createMerkurWidget, getMerkur, hookMethod, isFunction, removeMerkur, setDefaultValueForUndefined };
|
|
220
|
+
export { assignMissingKeys, bindWidgetToFunctions, createMerkur, createMerkurWidget, getMerkur, hookMethod, isFunction, removeMerkur, setDefaultValueForUndefined };
|
package/lib/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,
|
|
1
|
+
!function(e,n){if("function"==typeof define&&define.amd)define("@merkur/core",["exports"],n);else if("undefined"!=typeof exports)n(exports);else{var t={exports:{}};n(t.exports),e.Merkur=e.Merkur||{},e.Merkur.Core=t.exports}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:this,(function(e){function n(e){return function(e){if(Array.isArray(e))return r(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||t(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,n){if(e){if("string"==typeof e)return r(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?r(e,n):void 0}}function r(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function i(e,n,t,r,o,i,u){try{var a=e[i](u),c=a.value}catch(e){return void t(e)}a.done?n(c):Promise.resolve(c).then(r,o)}function u(e){return function(){var n=this,t=arguments;return new Promise((function(r,o){var u=e.apply(n,t);function a(e){i(u,r,o,a,c,"next",e)}function c(e){i(u,r,o,a,c,"throw",e)}a(void 0)}))}}function a(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,r)}return t}function c(e,n,t){return(n=function(e){var n=function(e,n){if("object"!==o(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,n||"default");if("object"!==o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(e,"string");return"symbol"===o(n)?n:String(n)}(n))in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function f(e,n){return function(){for(var t=arguments.length,r=new Array(t),o=0;o<t;o++)r[o]=arguments[o];return n.apply(void 0,[e].concat(r))}}function l(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=function(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?a(Object(t),!0).forEach((function(n){c(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):a(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}({},e);return n.forEach((function(e){r[e]=r[e]||t})),r}function s(e,n){n=n||e,Object.keys(n).forEach((function(t){if(d(n[t])){var r=n[t];n[t]=f(e,r)}}))}function d(e){return"function"==typeof e}function p(e,n,t){return y.apply(this,arguments)}function y(){return(y=u((function*(e,r,o){var i,u=function(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=t(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var o=0,i=function(){};return{s:i,n:function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,u=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw u}}}}(e.$plugins);try{for(u.s();!(i=u.n()).done;){var a=i.value;d(a[r])&&(e=yield a[r].apply(a,[e].concat(n(o))))}}catch(e){u.e(e)}finally{u.f()}return e}))).apply(this,arguments)}function v(){return v=u((function*(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};e=l(e,["$dependencies","$external"]),e=l(e,["setup","create"],(function(e){return e}));var n=e,t=n.setup,r=n.create,o={setup:function(e){var n=arguments;return u((function*(){for(var r=n.length,o=new Array(r>1?r-1:0),i=1;i<r;i++)o[i-1]=n[i];return e=yield p(e,"setup",o),t.apply(void 0,[e].concat(o))}))()},create:function(e){var n=arguments;return u((function*(){for(var t=n.length,o=new Array(t>1?t-1:0),i=1;i<t;i++)o[i-1]=n[i];return e=yield p(e,"create",o),r.apply(void 0,[e].concat(o))}))()},$plugins:(e.$plugins||[]).map((function(e){return e()}))};return o.name=e.name,o.version=e.version,o.$dependencies=e.$dependencies,o.$external=e.$external,o.$in={},delete e.name,delete e.version,delete e.$dependencies,delete e.$external,delete e.$plugins,delete e.setup,delete e.create,o=yield o.setup(o,e),s(o=yield o.create(o,e)),Object.seal(o),o})),v.apply(this,arguments)}function b(e){var n=e.name,t=e.version,r=e.createWidget;h().$in.widgetFactory[n+t]=r}function g(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=h(),t=e.name,r=e.version,o=n.$in.widgetFactory[t+r];if(!d(o))throw new Error('The widget with defined name and version "'.concat(t+r,'" is not defined.'));return o(e)}function h(){var e=w();return e.__merkur__||(e.__merkur__={$in:{widgets:[],widgetFactory:{}},$external:{},$dependencies:{},isRegistered:m,register:b,create:g}),e.__merkur__}function m(e){var n=h();return Boolean(Object.keys(n.$in.widgetFactory).find((function(n){return new RegExp("^".concat(e)).test(n)})))}function w(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{}}Object.defineProperty(e,"__esModule",{value:!0}),e.assignMissingKeys=function(e){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];return t.forEach((function(n){Object.keys(n||{}).forEach((function(t){t in e||(e[t]=n[t])}))})),e},e.bindWidgetToFunctions=s,e.createMerkur=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.$plugins,t=void 0===n?[]:n,r=h();return t.forEach((function(e){e&&d(e.setup)&&e.setup(r)})),r},e.createMerkurWidget=function(){return v.apply(this,arguments)},e.getMerkur=h,e.hookMethod=function(e,n,t){var r=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",t=n.split("."),r=t.pop(),o=t.reduce((function(e,n){return e[n]||{}}),e);if(!d(o[r]))throw new Error("Defined path '".concat(n,"' is incorrect. Check your widget structure."));return{target:o,methodName:r}}(e,n),o=r.target,i=r.methodName,u=f(e,o[i]);return o[i]=function(e){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return t.apply(void 0,[e,u].concat(r))},u},e.isFunction=d,e.removeMerkur=function(){delete w().__merkur__},e.setDefaultValueForUndefined=l}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "Merkur is tiny and extensible library for creating front-end microservices.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://merkur.js.org/",
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "3bc4a1efb8f8d5cee6bcf5f1454809747904153c"
|
|
55
55
|
}
|