Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
noogen committed Jan 17, 2022
1 parent 6f648dd commit 4f69436
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 18 deletions.
3 changes: 2 additions & 1 deletion includes/AdminLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public function plugin_page()
'nonce' => wp_create_nonce('wp_rest')
],
'settings' => $settingController->get_settings_raw(),
'settingStructure' => $settingController->get_settings_structure(true)
'settingStructure' => $settingController->get_settings_structure(true),
'prefix' => $this->prefix
] );

$content = '<div class="admin-app-wrapper"><div id="vue-admin-app"></div></div>';
Expand Down
4 changes: 2 additions & 2 deletions public/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@

<div id="vue-admin-app"></div>
<script src="js/manifest.js?id=77cdbc52e55e2aeb2a17"></script>
<script src="js/vendor.js?id=a6c831aec7be8e864900"></script>
<script src="js/admin.js?id=558fc38e688452e19108"></script>
<script src="js/vendor.js?id=3ab70a818cc8399588b3"></script>
<script src="js/admin.js?id=78f93e841dd3701c07e3"></script>
<style>
html, body, #vue-admin-app {
height: 100%;
Expand Down
2 changes: 1 addition & 1 deletion public/frontend.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<div id="vue-frontend-app"></div>
<script src="js/manifest.js?id=77cdbc52e55e2aeb2a17"></script>
<script src="js/vendor.js?id=a6c831aec7be8e864900"></script>
<script src="js/vendor.js?id=3ab70a818cc8399588b3"></script>
<script src="js/frontend.js?id=b5dbb8b0cbf2ff8653a3"></script>
<style>
html, body, #vue-frontend-app {
Expand Down
2 changes: 1 addition & 1 deletion public/frontview.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<div id="vue-frontview-app"></div>
<script src="js/manifest.js?id=77cdbc52e55e2aeb2a17"></script>
<script src="js/vendor.js?id=a6c831aec7be8e864900"></script>
<script src="js/vendor.js?id=3ab70a818cc8399588b3"></script>
<script src="js/frontview.js?id=b908769d9aaf69bad912"></script>
<style>
html, body, #vue-frontview-app {
Expand Down
37 changes: 30 additions & 7 deletions public/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ var admin_menu_fix_1 = __importDefault(__webpack_require__(/*! ./admin-menu-fix

exports["default"] = (0, vue_1.defineComponent)({
mounted: function mounted() {
// fix the admin menu for the slug "vue-app"
(0, admin_menu_fix_1.default)('vue-app');
var that = this; // @ts-ignore

setTimeout(function () {
// fix the admin menu for the prefix slug or 'vue-app' if none is defined
(0, admin_menu_fix_1.default)(that.$win.vue_wp_plugin_config_admin.prefix || 'vue-app');
}, 1000);
}
});

Expand Down Expand Up @@ -379,7 +383,7 @@ var _default = (0, _vue.defineComponent)({
var _this = this;

return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
var data, rst, settings;
var data, rst, config, oldSettings, settings;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
Expand All @@ -400,11 +404,15 @@ var _default = (0, _vue.defineComponent)({
title: 'Your settings has been saved.',
showConfirmButton: false,
timer: 1500
});
}); // @ts-ignore


config = _this.$win.vue_wp_plugin_config_admin;
oldSettings = config.settings || {};
settings = _objectSpread({}, _this.settings);
Object.keys(settings).forEach(function (key) {
_this.oldSettings[key] = settings[key];
oldSettings[key] = settings[key];
}); // force rerendered

_this.ui.actionKey = _this.ui.actionKey + 1;
Expand Down Expand Up @@ -817,7 +825,7 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
/*!*************************************!*\
!*** ./src/admin/admin-menu-fix.js ***!
\*************************************/
/***/ (function(__unused_webpack_module, exports) {
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {



Expand All @@ -826,12 +834,14 @@ Object.defineProperty(exports, "__esModule", ({
}));
exports["default"] = void 0;

__webpack_require__(/*! core-js/modules/es.string.ends-with.js */ "./node_modules/core-js/modules/es.string.ends-with.js");

// @ts-ignore
function menuFix(slug) {
var currentUrl = window.location.href;
var isLocal = currentUrl.indexOf('admin.html') > 0;
var currentPath = currentUrl.substr(currentUrl.indexOf(isLocal ? '#/' : 'admin.php'));
var menuRoot = document.querySelector(isLocal ? '.wp-menu-open' : "#toplevel_page_".concat(slug));
var currentPath = currentUrl.substr(currentUrl.indexOf(isLocal ? '#/' : 'admin.php'));

if (menuRoot) {
menuRoot.addEventListener('click', function (e) {
Expand All @@ -847,10 +857,23 @@ function menuFix(slug) {
target.parentElement.classList.add('current');
}
}
});
}); // remove all current

var items = menuRoot.querySelectorAll(".current");

for (var i = 0; i < items.length; i++) {
var node = items[i];
node.classList.remove('current');
}

var menu = menuRoot.querySelector(".wp-submenu a[href=\"".concat(currentPath, "\""));

if (!isLocal && currentPath.endsWith('#/')) {
menu = menuRoot.querySelector(".wp-submenu a.wp-first-item");
}

if (menu) {
console.log(menu);
menu.parentElement.classList.add('current');
}
}
Expand Down
116 changes: 116 additions & 0 deletions public/js/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -34430,6 +34430,31 @@ module.exports = function (target, source, exceptions) {
};


/***/ }),

/***/ "./node_modules/core-js/internals/correct-is-regexp-logic.js":
/*!*******************************************************************!*\
!*** ./node_modules/core-js/internals/correct-is-regexp-logic.js ***!
\*******************************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

var wellKnownSymbol = __webpack_require__(/*! ../internals/well-known-symbol */ "./node_modules/core-js/internals/well-known-symbol.js");

var MATCH = wellKnownSymbol('match');

module.exports = function (METHOD_NAME) {
var regexp = /./;
try {
'/./'[METHOD_NAME](regexp);
} catch (error1) {
try {
regexp[MATCH] = false;
return '/./'[METHOD_NAME](regexp);
} catch (error2) { /* empty */ }
} return false;
};


/***/ }),

/***/ "./node_modules/core-js/internals/create-non-enumerable-property.js":
Expand Down Expand Up @@ -35447,6 +35472,28 @@ module.exports = function (it) {
module.exports = false;


/***/ }),

/***/ "./node_modules/core-js/internals/is-regexp.js":
/*!*****************************************************!*\
!*** ./node_modules/core-js/internals/is-regexp.js ***!
\*****************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

var isObject = __webpack_require__(/*! ../internals/is-object */ "./node_modules/core-js/internals/is-object.js");
var classof = __webpack_require__(/*! ../internals/classof-raw */ "./node_modules/core-js/internals/classof-raw.js");
var wellKnownSymbol = __webpack_require__(/*! ../internals/well-known-symbol */ "./node_modules/core-js/internals/well-known-symbol.js");

var MATCH = wellKnownSymbol('match');

// `IsRegExp` abstract operation
// https://tc39.es/ecma262/#sec-isregexp
module.exports = function (it) {
var isRegExp;
return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classof(it) == 'RegExp');
};


/***/ }),

/***/ "./node_modules/core-js/internals/is-symbol.js":
Expand Down Expand Up @@ -35786,6 +35833,26 @@ module.exports.f = function (C) {
};


/***/ }),

/***/ "./node_modules/core-js/internals/not-a-regexp.js":
/*!********************************************************!*\
!*** ./node_modules/core-js/internals/not-a-regexp.js ***!
\********************************************************/
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {

var global = __webpack_require__(/*! ../internals/global */ "./node_modules/core-js/internals/global.js");
var isRegExp = __webpack_require__(/*! ../internals/is-regexp */ "./node_modules/core-js/internals/is-regexp.js");

var TypeError = global.TypeError;

module.exports = function (it) {
if (isRegExp(it)) {
throw TypeError("The method doesn't accept regular expressions");
} return it;
};


/***/ }),

/***/ "./node_modules/core-js/internals/object-create.js":
Expand Down Expand Up @@ -37600,6 +37667,55 @@ $({ target: PROMISE, stat: true, forced: INCORRECT_ITERATION }, {
});


/***/ }),

/***/ "./node_modules/core-js/modules/es.string.ends-with.js":
/*!*************************************************************!*\
!*** ./node_modules/core-js/modules/es.string.ends-with.js ***!
\*************************************************************/
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {

"use strict";

var $ = __webpack_require__(/*! ../internals/export */ "./node_modules/core-js/internals/export.js");
var uncurryThis = __webpack_require__(/*! ../internals/function-uncurry-this */ "./node_modules/core-js/internals/function-uncurry-this.js");
var getOwnPropertyDescriptor = (__webpack_require__(/*! ../internals/object-get-own-property-descriptor */ "./node_modules/core-js/internals/object-get-own-property-descriptor.js").f);
var toLength = __webpack_require__(/*! ../internals/to-length */ "./node_modules/core-js/internals/to-length.js");
var toString = __webpack_require__(/*! ../internals/to-string */ "./node_modules/core-js/internals/to-string.js");
var notARegExp = __webpack_require__(/*! ../internals/not-a-regexp */ "./node_modules/core-js/internals/not-a-regexp.js");
var requireObjectCoercible = __webpack_require__(/*! ../internals/require-object-coercible */ "./node_modules/core-js/internals/require-object-coercible.js");
var correctIsRegExpLogic = __webpack_require__(/*! ../internals/correct-is-regexp-logic */ "./node_modules/core-js/internals/correct-is-regexp-logic.js");
var IS_PURE = __webpack_require__(/*! ../internals/is-pure */ "./node_modules/core-js/internals/is-pure.js");

// eslint-disable-next-line es/no-string-prototype-endswith -- safe
var un$EndsWith = uncurryThis(''.endsWith);
var slice = uncurryThis(''.slice);
var min = Math.min;

var CORRECT_IS_REGEXP_LOGIC = correctIsRegExpLogic('endsWith');
// https://github.com/zloirock/core-js/pull/702
var MDN_POLYFILL_BUG = !IS_PURE && !CORRECT_IS_REGEXP_LOGIC && !!function () {
var descriptor = getOwnPropertyDescriptor(String.prototype, 'endsWith');
return descriptor && !descriptor.writable;
}();

// `String.prototype.endsWith` method
// https://tc39.es/ecma262/#sec-string.prototype.endswith
$({ target: 'String', proto: true, forced: !MDN_POLYFILL_BUG && !CORRECT_IS_REGEXP_LOGIC }, {
endsWith: function endsWith(searchString /* , endPosition = @length */) {
var that = toString(requireObjectCoercible(this));
notARegExp(searchString);
var endPosition = arguments.length > 1 ? arguments[1] : undefined;
var len = that.length;
var end = endPosition === undefined ? len : min(toLength(endPosition), len);
var search = toString(searchString);
return un$EndsWith
? un$EndsWith(that, search, end)
: slice(that, end - search.length, end) === search;
}
});


/***/ }),

/***/ "./node_modules/core-js/modules/es.symbol.description.js":
Expand Down
4 changes: 2 additions & 2 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"/js/admin.js": "/js/admin.js?id=558fc38e688452e19108",
"/js/admin.js": "/js/admin.js?id=78f93e841dd3701c07e3",
"/js/frontend.js": "/js/frontend.js?id=b5dbb8b0cbf2ff8653a3",
"/js/frontview.js": "/js/frontview.js?id=b908769d9aaf69bad912",
"/js/manifest.js": "/js/manifest.js?id=77cdbc52e55e2aeb2a17",
"/css/frontview.css": "/css/frontview.css?id=7cf1befae2b37c53e819",
"/css/frontend.css": "/css/frontend.css?id=7cf1befae2b37c53e819",
"/css/admin.css": "/css/admin.css?id=4fd00009cd2f4b4fdb69",
"/js/vendor.js": "/js/vendor.js?id=a6c831aec7be8e864900"
"/js/vendor.js": "/js/vendor.js?id=3ab70a818cc8399588b3"
}
8 changes: 6 additions & 2 deletions src/admin/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import menuFix from './admin-menu-fix'
export default defineComponent({
mounted() {
// fix the admin menu for the slug "vue-app"
menuFix('vue-app')
const that = this
// @ts-ignore
setTimeout(() => {
// fix the admin menu for the prefix slug or 'vue-app' if none is defined
menuFix(that.$win.vue_wp_plugin_config_admin.prefix || 'vue-app')
}, 1000)
}
})
</script>
Expand Down
16 changes: 15 additions & 1 deletion src/admin/admin-menu-fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
function menuFix(slug) {
const currentUrl = window.location.href
const isLocal = currentUrl.indexOf('admin.html') > 0
const currentPath = currentUrl.substr(currentUrl.indexOf(isLocal ? '#/' : 'admin.php'))
const menuRoot = document.querySelector(isLocal ? '.wp-menu-open' : `#toplevel_page_${slug}`)

var currentPath = currentUrl.substr(currentUrl.indexOf(isLocal ? '#/' : 'admin.php'))

if (menuRoot) {
menuRoot.addEventListener('click', function (e) {
const target = e.target
Expand All @@ -19,8 +20,21 @@ function menuFix(slug) {
}
})

// remove all current
var items = menuRoot.querySelectorAll(`.current`)
for (let i = 0; i < items.length; i++) {
let node = items[i];
node.classList.remove('current')
}

var menu = menuRoot.querySelector(`.wp-submenu a[href="${currentPath}"`)

if (! isLocal && currentPath.endsWith('#/')) {
menu = menuRoot.querySelector(`.wp-submenu a.wp-first-item`)
}

if (menu) {
console.log(menu)
menu.parentElement.classList.add('current')
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/admin/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,14 @@ export default defineComponent({
timer: 1500
})
const settings = {...this.settings}
// @ts-ignore
const config = this.$win.vue_wp_plugin_config_admin
const oldSettings = config.settings || {}
const settings = {...this.settings}
Object.keys(settings).forEach((key) => {
this.oldSettings[key] = settings[key]
oldSettings[key] = settings[key]
})
// force rerendered
Expand Down

0 comments on commit 4f69436

Please sign in to comment.