mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-13 14:56:54 +08:00
feat(docs): Implement docs filter default value operator as plugin.
This commit is contained in:
parent
7a97261543
commit
fa46d22675
3
.pnp.cjs
generated
3
.pnp.cjs
generated
@ -3231,6 +3231,9 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) {
|
||||
"packageLocation": "./packages/docs/",
|
||||
"packageDependencies": [
|
||||
["@lowdefy/docs", "workspace:packages/docs"],
|
||||
["@jest/globals", "npm:27.5.1"],
|
||||
["@lowdefy/helpers", "workspace:packages/utils/helpers"],
|
||||
["@swc/cli", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.1.55"],
|
||||
["@swc/core", "npm:1.2.135"],
|
||||
["@swc/jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:0.2.17"],
|
||||
["jest", "virtual:babee6e81435a5d101529cd67f2c6b175f4db37a4ab0b58df15adf73dd11be8917ac14caf44ab4e6882a92c61661055072365b349016e85173e049f006fc2305#npm:27.5.1"]
|
||||
|
@ -1 +0,0 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2.6.3/dist/cdn/docsearch.min.js"></script>
|
@ -1,4 +1,3 @@
|
||||
<script type="module" src="/public/modules/index.js"></script>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/docsearch.js@2.6.3/dist/cdn/docsearch.min.css"
|
||||
|
@ -1,23 +1,13 @@
|
||||
export default {
|
||||
clearMocks: true,
|
||||
collectCoverage: true,
|
||||
collectCoverageFrom: ['**/*.js'],
|
||||
collectCoverageFrom: ['src/**/*.js'],
|
||||
coverageDirectory: 'coverage',
|
||||
coveragePathIgnorePatterns: [
|
||||
'<rootDir>/.lowdefy/',
|
||||
'<rootDir>/jest.config.js',
|
||||
'<rootDir>/coverage/',
|
||||
'<rootDir>/howto/',
|
||||
],
|
||||
coveragePathIgnorePatterns: ['<rootDir>/dist/', '<rootDir>/src/operatorsClient.js'],
|
||||
coverageReporters: [['lcov', { projectRoot: '../..' }], 'text', 'clover'],
|
||||
errorOnDeprecated: true,
|
||||
testEnvironment: 'node',
|
||||
testPathIgnorePatterns: [
|
||||
'<rootDir>/.lowdefy/',
|
||||
'<rootDir>/jest.config.js',
|
||||
'<rootDir>/coverage/',
|
||||
'<rootDir>/howto/',
|
||||
],
|
||||
testPathIgnorePatterns: ['<rootDir>/dist/'],
|
||||
transform: {
|
||||
'^.+\\.(t|j)sx?$': ['@swc/jest', { configFile: '../../.swcrc.test' }],
|
||||
},
|
||||
|
@ -19,6 +19,10 @@ licence: Apache-2.0
|
||||
cli:
|
||||
disableTelemetry: true
|
||||
|
||||
plugins:
|
||||
- name: '@lowdefy/docs'
|
||||
version: '4.0.0-alpha.7'
|
||||
|
||||
global:
|
||||
all_icons:
|
||||
_ref: blocks/all_icons.yaml
|
||||
@ -30,8 +34,6 @@ app:
|
||||
html:
|
||||
appendHead:
|
||||
_ref: head.html
|
||||
appendBody:
|
||||
_ref: body.html
|
||||
|
||||
connections:
|
||||
- id: discord_channel
|
||||
|
@ -27,11 +27,27 @@
|
||||
"url": "https://github.com/lowdefy/lowdefy.git"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./actions": "./dist/actions.js",
|
||||
"./operators/client": "./dist/operatorsClient.js",
|
||||
"./types": "./dist/types.js"
|
||||
},
|
||||
"files": [
|
||||
"dist/*"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "yarn swc",
|
||||
"clean": "rm -rf .lowdefy",
|
||||
"test": "jest --coverage"
|
||||
"prepare": "yarn build",
|
||||
"swc": "swc src --out-dir dist --config-file ../../.swcrc --delete-dir-on-start",
|
||||
"test": "yarn node --experimental-vm-modules $(yarn bin jest)"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lowdefy/helpers": "4.0.0-alpha.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/globals": "27.5.1",
|
||||
"@swc/cli": "0.1.55",
|
||||
"@swc/core": "1.2.135",
|
||||
"@swc/jest": "0.2.17",
|
||||
"jest": "27.5.1"
|
||||
|
@ -1,5 +0,0 @@
|
||||
import connectDocsearch from './connectDocsearch.js';
|
||||
import filterDefaultValue from './filterDefaultValue.js';
|
||||
|
||||
window.lowdefy.registerJsAction('connectDocsearch', connectDocsearch);
|
||||
window.lowdefy.registerJsOperator('filterDefaultValue', filterDefaultValue);
|
@ -14,22 +14,24 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
function filterDefaultValue(value, defaultValue) {
|
||||
const isObject = (obj) => typeof obj === 'object' && obj !== null && !Array.isArray(obj);
|
||||
const isEmptyObject = (obj) => isObject(obj) && Object.keys(obj).length === 0;
|
||||
import { type } from '@lowdefy/helpers';
|
||||
|
||||
function custom_filter_default_value({ params }) {
|
||||
const { value, defaultValue } = params;
|
||||
const isEmptyObject = (obj) => type.isObject(obj) && Object.keys(obj).length === 0;
|
||||
|
||||
const getNestedValue = (obj, path) => {
|
||||
const keys = [...path];
|
||||
const key = keys.shift();
|
||||
const value = obj[key];
|
||||
if (keys.length > 0 && isObject(value)) return getNestedValue(value, keys);
|
||||
if (keys.length > 0 && type.isObject(value)) return getNestedValue(value, keys);
|
||||
return value;
|
||||
};
|
||||
|
||||
const filterObject = ({ obj, path }) => {
|
||||
Object.keys(obj).forEach((key) => {
|
||||
const propPath = path.concat([key]);
|
||||
if (isObject(obj[key])) {
|
||||
if (type.isObject(obj[key])) {
|
||||
filterObject({ obj: obj[key], path: propPath });
|
||||
}
|
||||
const dv = getNestedValue(defaultValue, propPath);
|
||||
@ -45,4 +47,4 @@ function filterDefaultValue(value, defaultValue) {
|
||||
return filterObject({ obj: value, path: [] });
|
||||
}
|
||||
|
||||
export default filterDefaultValue;
|
||||
export default custom_filter_default_value;
|
@ -14,11 +14,11 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import filterDefaultValue from '../filterDefaultValue';
|
||||
import filter_default_value from './filter_default_value.js';
|
||||
|
||||
test('no default value', () => {
|
||||
const value = { a: 1 };
|
||||
expect(filterDefaultValue(value, {})).toEqual({ a: 1 });
|
||||
expect(filter_default_value({ params: { value, defaultValue: {} } })).toEqual({ a: 1 });
|
||||
});
|
||||
|
||||
test('remove null, empty objects and empty objects with all properties null or empty', () => {
|
||||
@ -30,7 +30,7 @@ test('remove null, empty objects and empty objects with all properties null or e
|
||||
g: { h: { i: { j: null, k: { l: null } } } },
|
||||
m: { n: null, o: null, p: null },
|
||||
};
|
||||
expect(filterDefaultValue(value, {})).toEqual({});
|
||||
expect(filter_default_value({ params: { value, defaultValue: {} } })).toEqual({});
|
||||
});
|
||||
|
||||
test('remove a default value', () => {
|
||||
@ -42,7 +42,7 @@ test('remove a default value', () => {
|
||||
a: 1,
|
||||
b: 1,
|
||||
};
|
||||
expect(filterDefaultValue(value, defaultValue)).toEqual({ b: 2 });
|
||||
expect(filter_default_value({ params: { value, defaultValue } })).toEqual({ b: 2 });
|
||||
});
|
||||
|
||||
test('remove a default value but keep arrays', () => {
|
||||
@ -64,7 +64,7 @@ test('remove a default value but keep arrays', () => {
|
||||
},
|
||||
e: ['1', '2'],
|
||||
};
|
||||
expect(filterDefaultValue(value, defaultValue)).toEqual({
|
||||
expect(filter_default_value({ params: { value, defaultValue } })).toEqual({
|
||||
a: {
|
||||
c: false,
|
||||
d: true,
|
||||
@ -87,5 +87,5 @@ test('only recurse getNestedValue on objects', () => {
|
||||
b: null,
|
||||
},
|
||||
};
|
||||
expect(filterDefaultValue(value, defaultValue)).toEqual({ a: { b: { c: 1 } } });
|
||||
expect(filter_default_value({ params: { value, defaultValue } })).toEqual({ a: { b: { c: 1 } } });
|
||||
});
|
17
packages/docs/src/operatorsClient.js
Normal file
17
packages/docs/src/operatorsClient.js
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
export { default as _custom_filter_default_value } from './operators/client/filter_default_value.js';
|
23
packages/docs/src/types.js
Normal file
23
packages/docs/src/types.js
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2020-2021 Lowdefy, Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import * as operatorsClient from './operatorsClient.js';
|
||||
|
||||
export default {
|
||||
operators: {
|
||||
client: Object.keys(operatorsClient),
|
||||
},
|
||||
};
|
16
packages/docs/templates/blocks/template.yaml.njk
vendored
16
packages/docs/templates/blocks/template.yaml.njk
vendored
@ -192,14 +192,16 @@ areas:
|
||||
required:
|
||||
_state: block.required
|
||||
properties:
|
||||
_js.filterDefaultValue:
|
||||
- _ref:
|
||||
_custom_filter_default_value:
|
||||
value:
|
||||
_ref:
|
||||
path:
|
||||
_var: schema
|
||||
vars:
|
||||
block_type: {{ block_type }}
|
||||
transformer: templates/blocks/propertiesGetterTransformer.js
|
||||
- _ref:
|
||||
defaultValue:
|
||||
_ref:
|
||||
path:
|
||||
_var: schema
|
||||
transformer: templates/blocks/defaultValueTransformer.js
|
||||
@ -309,8 +311,9 @@ areas:
|
||||
options:
|
||||
sortKeys: false
|
||||
on:
|
||||
_js.filterDefaultValue:
|
||||
- id: block_id
|
||||
_custom_filter_default_value:
|
||||
value:
|
||||
id: block_id
|
||||
type: {{ block_type }}
|
||||
required:
|
||||
_state: block.required
|
||||
@ -330,7 +333,8 @@ areas:
|
||||
vars:
|
||||
block_type: {{ block_type }}
|
||||
transformer: templates/blocks/propertiesGetterTransformer.js
|
||||
- required: false
|
||||
defaultValue:
|
||||
required: false
|
||||
visible: true
|
||||
layout:
|
||||
align: top
|
||||
|
@ -13,6 +13,7 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import * as actions from './actions.js';
|
||||
|
||||
export default {
|
||||
|
Loading…
x
Reference in New Issue
Block a user