lilact 0.0.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/Icon/r +0 -0
- package/LICENSE.TXT +26 -0
- package/README.md +116 -0
- package/bin/copy-demo.js +26 -0
- package/bin/transpile-dir.js +112 -0
- package/bin/transpile.js +137 -0
- package/dist/lilact.development.js +9344 -0
- package/dist/lilact.development.js.map +1 -0
- package/dist/lilact.production.min.js +63 -0
- package/dist/lilact.production.min.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +71 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1633 -0
- package/docs/classes/accessories.ErrorBoundary.html +37 -0
- package/docs/classes/accessories.Suspense.html +41 -0
- package/docs/classes/components.Component.html +45 -0
- package/docs/classes/components.HTMLComponent.html +32 -0
- package/docs/classes/components.RootComponent.html +32 -0
- package/docs/classes/transition.Transition.html +31 -0
- package/docs/functions/accessories.Spinner.html +9 -0
- package/docs/functions/components.createComponent.html +8 -0
- package/docs/functions/components.createRoot.html +5 -0
- package/docs/functions/components.render.html +5 -0
- package/docs/functions/hooks.createContext.html +3 -0
- package/docs/functions/hooks.useActionState.html +3 -0
- package/docs/functions/hooks.useCallback.html +5 -0
- package/docs/functions/hooks.useContext.html +3 -0
- package/docs/functions/hooks.useDeferredValue.html +4 -0
- package/docs/functions/hooks.useEffect.html +3 -0
- package/docs/functions/hooks.useHook.html +5 -0
- package/docs/functions/hooks.useId.html +4 -0
- package/docs/functions/hooks.useLayoutEffect.html +3 -0
- package/docs/functions/hooks.useLocalStorage.html +4 -0
- package/docs/functions/hooks.useMemo.html +4 -0
- package/docs/functions/hooks.useReducer.html +6 -0
- package/docs/functions/hooks.useRef.html +4 -0
- package/docs/functions/hooks.useState.html +3 -0
- package/docs/functions/hooks.useTransition.html +3 -0
- package/docs/functions/jsx.transpileJSX.html +6 -0
- package/docs/functions/misc.Fragment.html +3 -0
- package/docs/functions/misc.classNames.html +2 -0
- package/docs/functions/misc.deepEqual.html +3 -0
- package/docs/functions/misc.findDOMNode.html +3 -0
- package/docs/functions/misc.getComponentByPointer.html +3 -0
- package/docs/functions/misc.isAsync.html +3 -0
- package/docs/functions/misc.isClass.html +3 -0
- package/docs/functions/misc.isEmpty.html +3 -0
- package/docs/functions/misc.isError.html +3 -0
- package/docs/functions/misc.isThenable.html +3 -0
- package/docs/functions/misc.isValidElement.html +3 -0
- package/docs/functions/misc.shallowEqual.html +3 -0
- package/docs/functions/redux.Provider.html +5 -0
- package/docs/functions/redux.connect.html +5 -0
- package/docs/functions/redux.useDispatch.html +3 -0
- package/docs/functions/redux.useSelector.html +5 -0
- package/docs/functions/redux.useStore.html +3 -0
- package/docs/functions/router.HashRouter.html +5 -0
- package/docs/functions/router.Link.html +12 -0
- package/docs/functions/router.NavLink.html +10 -0
- package/docs/functions/router.Route.html +6 -0
- package/docs/functions/router.Routes.html +4 -0
- package/docs/functions/router.useLocation.html +3 -0
- package/docs/functions/router.useNavigate.html +3 -0
- package/docs/functions/run.require.html +14 -0
- package/docs/functions/run.run.html +13 -0
- package/docs/functions/run.runScripts.html +7 -0
- package/docs/functions/run.traceError.html +6 -0
- package/docs/functions/timers.animationFramePromise.html +3 -0
- package/docs/functions/timers.clearInterval.html +2 -0
- package/docs/functions/timers.clearTimeout.html +2 -0
- package/docs/functions/timers.grabTimers.html +3 -0
- package/docs/functions/timers.pauseTimers.html +2 -0
- package/docs/functions/timers.releaseTimers.html +2 -0
- package/docs/functions/timers.resetTimers.html +2 -0
- package/docs/functions/timers.resumeTimers.html +2 -0
- package/docs/functions/timers.setInterval.html +5 -0
- package/docs/functions/timers.setTimeout.html +4 -0
- package/docs/functions/timers.timeoutPromise.html +4 -0
- package/docs/functions/transition.CSSTransition.html +18 -0
- package/docs/functions/transition.TransitionGroup.html +5 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +88 -0
- package/docs/media/icon.png +0 -0
- package/docs/modules/accessories.html +1 -0
- package/docs/modules/components.html +1 -0
- package/docs/modules/hooks.html +1 -0
- package/docs/modules/jsx.html +1 -0
- package/docs/modules/misc.html +1 -0
- package/docs/modules/redux.html +1 -0
- package/docs/modules/router.html +1 -0
- package/docs/modules/run.html +1 -0
- package/docs/modules/timers.html +1 -0
- package/docs/modules/transition.html +1 -0
- package/docs/modules.html +1 -0
- package/docs/static/demos/actionstate.jsx +41 -0
- package/docs/static/demos/boundary.jsx +52 -0
- package/docs/static/demos/context.jsx +68 -0
- package/docs/static/demos/css-transition.jsx +65 -0
- package/docs/static/demos/modal.jsx +41 -0
- package/docs/static/demos/proptypes.jsx +37 -0
- package/docs/static/demos/reducer.jsx +71 -0
- package/docs/static/demos/redux.jsx +58 -0
- package/docs/static/demos/router.jsx +153 -0
- package/docs/static/demos/stopwatch.jsx +42 -0
- package/docs/static/demos/suspense.jsx +48 -0
- package/docs/static/demos/transition.jsx +40 -0
- package/docs/static/demos/use-differed.jsx +30 -0
- package/docs/static/demos/usetransition.jsx +37 -0
- package/docs/static/index.html +212 -0
- package/docs/static/lilact.development.js +9344 -0
- package/docs/static/lilact.production.min.js +63 -0
- package/docs/static/prismjs/LICENSE.md +21 -0
- package/docs/static/prismjs/prism-jsx.min.js +1 -0
- package/docs/static/prismjs/prism.min.css +1 -0
- package/docs/static/prismjs/prism.min.js +16 -0
- package/docs/variables/jsx.transpilerConfig.html +1 -0
- package/docs/variables/misc.Children.html +10 -0
- package/icon.png +0 -0
- package/package.json +39 -0
- package/root/demos/actionstate.jsx +41 -0
- package/root/demos/boundary.jsx +52 -0
- package/root/demos/context.jsx +68 -0
- package/root/demos/css-transition.jsx +65 -0
- package/root/demos/modal.jsx +41 -0
- package/root/demos/proptypes.jsx +37 -0
- package/root/demos/reducer.jsx +71 -0
- package/root/demos/redux.jsx +58 -0
- package/root/demos/router.jsx +153 -0
- package/root/demos/stopwatch.jsx +42 -0
- package/root/demos/suspense.jsx +48 -0
- package/root/demos/transition.jsx +40 -0
- package/root/demos/use-differed.jsx +30 -0
- package/root/demos/usetransition.jsx +37 -0
- package/root/index.html +212 -0
- package/root/lilact.development.js +9344 -0
- package/root/lilact.production.min.js +63 -0
- package/root/prismjs/LICENSE.md +21 -0
- package/root/prismjs/prism-jsx.min.js +1 -0
- package/root/prismjs/prism.min.css +1 -0
- package/root/prismjs/prism.min.js +16 -0
- package/src/accessories.jsx +287 -0
- package/src/components.jsx +1063 -0
- package/src/events.jsx +175 -0
- package/src/hooks.jsx +461 -0
- package/src/jsx.addons.js +70 -0
- package/src/jsx.js +1168 -0
- package/src/lilact.jsx +115 -0
- package/src/loader.cjs +59 -0
- package/src/misc.jsx +419 -0
- package/src/redux.jsx +198 -0
- package/src/router.jsx +282 -0
- package/src/run.jsx +275 -0
- package/src/timers.jsx +313 -0
- package/src/transition.jsx +244 -0
- package/src/vlq.js +94 -0
- package/tsconfig.json +15 -0
- package/typedoc.json +23 -0
- package/webpack.config.js +196 -0
package/src/lilact.jsx
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Lilact
|
|
4
|
+
Copyright (C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
BSD-2-Clause
|
|
8
|
+
|
|
9
|
+
Redistribution and use in source and binary forms, with or without
|
|
10
|
+
modification, are permitted provided that the following conditions are met:
|
|
11
|
+
|
|
12
|
+
* Redistributions of source code must retain the above copyright
|
|
13
|
+
notice, this list of conditions and the following disclaimer.
|
|
14
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer in the
|
|
16
|
+
documentation and/or other materials provided with the distribution.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
22
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
23
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
24
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
25
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
27
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
import * as redux from "redux";
|
|
34
|
+
import * as emotion from "@emotion/css";
|
|
35
|
+
|
|
36
|
+
import PropTypes from 'prop-types';
|
|
37
|
+
|
|
38
|
+
import * as components from './components.jsx';
|
|
39
|
+
import * as hooks from './hooks.jsx';
|
|
40
|
+
import * as run from './run.jsx';
|
|
41
|
+
import * as transition from './transition.jsx';
|
|
42
|
+
import EventWrapper from './events.jsx';
|
|
43
|
+
import * as redux_wrapper from './redux.jsx';
|
|
44
|
+
import * as timers from './timers.jsx';
|
|
45
|
+
import * as misc from './misc.jsx';
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
import * as router from './router.jsx';
|
|
49
|
+
import * as accessories from './accessories.jsx';
|
|
50
|
+
|
|
51
|
+
import {transpileJSX, transpilerConfig} from "./jsx";
|
|
52
|
+
|
|
53
|
+
//import '../node_modules/@dragdroptouch/drag-drop-touch/dist/drag-drop-touch.esm.min.js';
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @namespace Lilact
|
|
58
|
+
*
|
|
59
|
+
* @property PropTypes - Handle to the PropTypes runtime type-checking library (https://github.com/facebook/prop-types).
|
|
60
|
+
* @property Redux - Handle to Redux’s public API (https://github.com/reduxjs/redux).
|
|
61
|
+
* @property emotion - Handle to Emotion’s CSS-in-JS package for styling (https://github.com/emotion-js/emotion).
|
|
62
|
+
*/
|
|
63
|
+
export const Lilact =
|
|
64
|
+
{
|
|
65
|
+
|
|
66
|
+
VERSION: "beta.0",
|
|
67
|
+
|
|
68
|
+
// Configuration
|
|
69
|
+
|
|
70
|
+
defaultTransitionTimeout: 300,
|
|
71
|
+
defaultIsEqual: Object.is, // note: `Lilact.shallowEqual` and `Lilact.deepEqual` are also available,
|
|
72
|
+
// user can set it in your initializer code, and can be changed later too.
|
|
73
|
+
|
|
74
|
+
// Units
|
|
75
|
+
|
|
76
|
+
...components,
|
|
77
|
+
...hooks,
|
|
78
|
+
...run,
|
|
79
|
+
...transition,
|
|
80
|
+
...redux_wrapper,
|
|
81
|
+
...timers,
|
|
82
|
+
...misc,
|
|
83
|
+
...EventWrapper,
|
|
84
|
+
//...db,
|
|
85
|
+
|
|
86
|
+
...router,
|
|
87
|
+
...accessories,
|
|
88
|
+
|
|
89
|
+
transpileJSX,
|
|
90
|
+
transpilerConfig,
|
|
91
|
+
|
|
92
|
+
// Dependencies ()
|
|
93
|
+
|
|
94
|
+
PropTypes,
|
|
95
|
+
redux,
|
|
96
|
+
emotion,
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
// or, if you prefer DOMContentLoaded:
|
|
102
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
103
|
+
Lilact.runScripts();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
function yourFunctionHere() {
|
|
107
|
+
// ...
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
ʔ if(DEBUG) {
|
|
111
|
+
console.log(`Lilact (Version: ${Lilact.VERSION}) - Debug Mode`);
|
|
112
|
+
console.log(`Copyright(C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>`);
|
|
113
|
+
ʔ }
|
|
114
|
+
|
|
115
|
+
export default Lilact;
|
package/src/loader.cjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Lilact
|
|
4
|
+
Copyright (C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
BSD-2-Clause
|
|
8
|
+
|
|
9
|
+
Redistribution and use in source and binary forms, with or without
|
|
10
|
+
modification, are permitted provided that the following conditions are met:
|
|
11
|
+
|
|
12
|
+
* Redistributions of source code must retain the above copyright
|
|
13
|
+
notice, this list of conditions and the following disclaimer.
|
|
14
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer in the
|
|
16
|
+
documentation and/or other materials provided with the distribution.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
22
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
23
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
24
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
25
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
27
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
// Loader for JSX transpiler in webpack. Check webpack.config.js for the rules.
|
|
32
|
+
|
|
33
|
+
const {transpileJSX, transpilerConfig} = require ('./jsx.js');
|
|
34
|
+
|
|
35
|
+
module.exports = function loader(source) {
|
|
36
|
+
|
|
37
|
+
const opts = this.getOptions();
|
|
38
|
+
|
|
39
|
+
globalThis.DEBUG = opts.mode!=='production';
|
|
40
|
+
|
|
41
|
+
// globalThis.Lilact = Object.assign(globalThis.Lilact || {},
|
|
42
|
+
// {
|
|
43
|
+
// transpilerConfig
|
|
44
|
+
// });
|
|
45
|
+
|
|
46
|
+
console.log("Transpiling", DEBUG, this.resource);
|
|
47
|
+
source = transpileJSX(source,
|
|
48
|
+
{
|
|
49
|
+
path: this.resource,
|
|
50
|
+
appendSourcemap: DEBUG,
|
|
51
|
+
//factory: "Lialct.createComponent",
|
|
52
|
+
//mappings: [],
|
|
53
|
+
//injectTraceLabels: false,
|
|
54
|
+
//discardComments: false
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return source;
|
|
59
|
+
};
|
package/src/misc.jsx
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Lilact
|
|
4
|
+
Copyright (C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
BSD-2-Clause
|
|
8
|
+
|
|
9
|
+
Redistribution and use in source and binary forms, with or without
|
|
10
|
+
modification, are permitted provided that the following conditions are met:
|
|
11
|
+
|
|
12
|
+
* Redistributions of source code must retain the above copyright
|
|
13
|
+
notice, this list of conditions and the following disclaimer.
|
|
14
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer in the
|
|
16
|
+
documentation and/or other materials provided with the distribution.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
22
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
23
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
24
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
25
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
27
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import Lilact from './lilact.jsx';
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
ʔ defineSymbols ( "LILACT", [ "CORE", "COMPONENT", "MEMOIZED"] ) ʔ
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const typeOf = (input) => {
|
|
38
|
+
// used for object comparison functions
|
|
39
|
+
// https://monsterlessons-academy.com/posts/shallow-comparison-vs-deep-comparison-in-javascript
|
|
40
|
+
|
|
41
|
+
const rawObject = Object.prototype.toString.call(input).toLowerCase();
|
|
42
|
+
const typeOfRegex = /\[object (.*)]/g;
|
|
43
|
+
const type = typeOfRegex.exec(rawObject)[1];
|
|
44
|
+
return type;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// React API
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Checks whether a value is a Lilact component.
|
|
53
|
+
*
|
|
54
|
+
* @param value - Value to inspect.
|
|
55
|
+
* @returns True if the value is a class component; otherwise false.
|
|
56
|
+
*/
|
|
57
|
+
export const isValidElement = (o) => {
|
|
58
|
+
return o[CORE]!==undefined || o[TEXT]!==undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Utility to find the underlying DOM node for a mounted Lilact component.
|
|
63
|
+
*
|
|
64
|
+
* @param element - A Lilact component instance to locate its DOM node.
|
|
65
|
+
* @returns The corresponding DOM element (or null if unavailable).
|
|
66
|
+
*/
|
|
67
|
+
export const findDOMNode = (comp)=>{
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
When a component renders to null or false, findDOMNode returns null.
|
|
71
|
+
When a component renders to a string, findDOMNode returns a text DOM node containing that value.
|
|
72
|
+
|
|
73
|
+
Note:
|
|
74
|
+
|
|
75
|
+
findDOMNode only works on mounted components (that is, components that have been placed in the DOM).
|
|
76
|
+
If you try to call this on a component that has not been mounted yet (like calling findDOMNode() in
|
|
77
|
+
render() on a component that has yet to be created) an exception will be thrown.
|
|
78
|
+
|
|
79
|
+
Unlike React, in Lilact findDOMNode can also be used on function components.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
console.warn("NOT IMPLEMENTED YET")
|
|
83
|
+
|
|
84
|
+
if(!comp[CORE]?.element?.parentNode) throw "findDOMNode only works on mounted components.";
|
|
85
|
+
return comp[CORE].element;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Fragment helper/utility (same behavior as an array of children).
|
|
90
|
+
*
|
|
91
|
+
* @param children - The nodes to group without adding an extra DOM element.
|
|
92
|
+
*/
|
|
93
|
+
export const Fragment = ({children})=>children;
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Children namespace for utilities that operate on `props.children`. `Children` is deprecated
|
|
98
|
+
* and not recommended by React documentation itself. But `only` and `toArray` are used
|
|
99
|
+
* extensively everywhere, so I included them.
|
|
100
|
+
*
|
|
101
|
+
* @property only - Filters to the single child (or returns null/throws based on count).
|
|
102
|
+
* @property toArray - Converts children to a flat array.
|
|
103
|
+
*/
|
|
104
|
+
export const Children = {
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Returns the only child from a children collection.
|
|
108
|
+
*
|
|
109
|
+
* @param children - The children to read.
|
|
110
|
+
* @returns The single child (or null/exception based on the number of children).
|
|
111
|
+
*/
|
|
112
|
+
only(children) {
|
|
113
|
+
children = [...children];
|
|
114
|
+
let i=0;
|
|
115
|
+
while(i<children.length) {
|
|
116
|
+
if(children[i]?.constructor?.name==='Array') {
|
|
117
|
+
children.splice(i, 1, ...children[i]);
|
|
118
|
+
i--;
|
|
119
|
+
}
|
|
120
|
+
else if(children[i]===null || children[i]===undefined) {
|
|
121
|
+
children.splice(i, 1);
|
|
122
|
+
i--;
|
|
123
|
+
}
|
|
124
|
+
if(i>1) {
|
|
125
|
+
throw "no child or child is not the only one";
|
|
126
|
+
}
|
|
127
|
+
i++;
|
|
128
|
+
}
|
|
129
|
+
if(children.length===1) return children[0];
|
|
130
|
+
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Converts component children into a flat array.
|
|
135
|
+
*
|
|
136
|
+
* @param children - The children to convert.
|
|
137
|
+
* @returns An array representation of the children.
|
|
138
|
+
*/
|
|
139
|
+
toArray(children) {
|
|
140
|
+
if(children) {
|
|
141
|
+
if(children?.constructor?.name==='Array') return [...children];
|
|
142
|
+
return [children];
|
|
143
|
+
}
|
|
144
|
+
return [];
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
// Lilact API
|
|
150
|
+
/** @ignore */
|
|
151
|
+
export function getErrorLocation(err) // works for both error and error-event, and also in node env
|
|
152
|
+
{
|
|
153
|
+
if(err.lineno!==undefined || err.line!==undefined || err.lineNumber!==undefined) {
|
|
154
|
+
const l = err.lineno || err.line || err.lineNumber;
|
|
155
|
+
const c = err.colno || err.column || err.columnNumber;
|
|
156
|
+
|
|
157
|
+
return [l, c];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let match = /:(\d+):(\d+)[\n].*/m.exec(err.stack);
|
|
161
|
+
if(match===null) {
|
|
162
|
+
match = /:(\d+):(\d+)\)\s+at .*/m.exec(err.stack);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if(match) {
|
|
166
|
+
return [parseInt(match[1]), parseInt(match[2])]
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** @ignore */
|
|
173
|
+
export function mapLocation(mps, r,c)
|
|
174
|
+
{
|
|
175
|
+
let map = [0,0,0,0];
|
|
176
|
+
|
|
177
|
+
for(const i in mps) {
|
|
178
|
+
if(mps[i][0]<r) continue;
|
|
179
|
+
if(mps[i][0]>r || mps[i][1]>=c) {
|
|
180
|
+
map = mps[i-1];
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return [r-map[0]+map[2], ((r-map[0]===0)?map[3]:0)];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
/** @ignore */
|
|
190
|
+
export function scanFunctionLabels(code, path)
|
|
191
|
+
{
|
|
192
|
+
const ls = Array.from( code.matchAll(/LILACTBLOCK(\d+):(\d+),(\d+):([^*]+)\*\//mg) );
|
|
193
|
+
|
|
194
|
+
ls.forEach(
|
|
195
|
+
(x) => Lilact.transpilerConfig.func_labels[x[1]] = {
|
|
196
|
+
path,
|
|
197
|
+
row: parseInt(x[2])+1,
|
|
198
|
+
col: parseInt(x[3])+1,
|
|
199
|
+
label: x[4],
|
|
200
|
+
required: Lilact.transpilerConfig.required[path]
|
|
201
|
+
} );
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Debug tool to detect the component visible at a point on screen.
|
|
208
|
+
*
|
|
209
|
+
* @returns A promise that is resolved when the user clicks on screen and its value will be the component if any.
|
|
210
|
+
*/
|
|
211
|
+
export function getComponentByPointer()
|
|
212
|
+
{
|
|
213
|
+
let resolve_func;
|
|
214
|
+
|
|
215
|
+
const pr = new Promise( (res, rej)=> {
|
|
216
|
+
resolve_func = res;
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
function click_handler(event) {
|
|
220
|
+
|
|
221
|
+
event.stopImmediatePropagation();
|
|
222
|
+
window.removeEventListener('click', click_handler, true);
|
|
223
|
+
|
|
224
|
+
let t = event.target;
|
|
225
|
+
|
|
226
|
+
while( !t[COMPONENT] && t.parentNode ) {
|
|
227
|
+
t = t.parentNode;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
resolve_func( t[COMPONENT] );
|
|
231
|
+
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
window.addEventListener('click', click_handler, true);
|
|
236
|
+
|
|
237
|
+
return pr;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Utility for applying one or more class names to an element.
|
|
243
|
+
*
|
|
244
|
+
* @param classNames - One or more class name values to combine.
|
|
245
|
+
*/
|
|
246
|
+
export function classNames(classes) {
|
|
247
|
+
return Object.entries(classes)
|
|
248
|
+
.filter(([key, value]) => value)
|
|
249
|
+
.map(([key, value]) => key)
|
|
250
|
+
.join(' ');
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Checks whether a collection/set/array is empty.
|
|
256
|
+
*
|
|
257
|
+
* @param value - Value to check for emptiness.
|
|
258
|
+
* @returns True if empty; otherwise false.
|
|
259
|
+
*/
|
|
260
|
+
export function isEmpty(o) {
|
|
261
|
+
for(let i in o) return false;
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Determines whether two values are shallowly equal.
|
|
268
|
+
*
|
|
269
|
+
* @param objA - First object to compare.
|
|
270
|
+
* @param objB - Second object to compare.
|
|
271
|
+
* @returns True if shallowly equal; otherwise false.
|
|
272
|
+
*/
|
|
273
|
+
export const shallowEqual = (source, target) => {
|
|
274
|
+
if (typeOf(source) !== typeOf(target)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (typeOf(source) === "array") {
|
|
279
|
+
if (source.length !== target.length) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
return source.every((el, index) => el === target[index]);
|
|
283
|
+
} else if (typeOf(source) === "object") {
|
|
284
|
+
return Object.keys(source).every((key) => source[key] === target[key]);
|
|
285
|
+
} else if (typeOf(source) === "date") {
|
|
286
|
+
return source.getTime() === target.getTime();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return source === target;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Determines whether two values are deeply equal.
|
|
295
|
+
*
|
|
296
|
+
* @param objA - First object to compare.
|
|
297
|
+
* @param objB - Second object to compare.
|
|
298
|
+
* @returns True if deeply equal; otherwise false.
|
|
299
|
+
*/
|
|
300
|
+
export function deepEqual(source, target) {
|
|
301
|
+
if (typeOf(source) !== typeOf(target)) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (typeOf(source) === "array") {
|
|
306
|
+
if (source.length !== target.length) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return source.every((entry, index) => deepEqual(entry, target[index]));
|
|
311
|
+
} else if (typeOf(source) === "object") {
|
|
312
|
+
if (Object.keys(source).length !== Object.keys(target).length) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return Object.keys(source).every((key) =>
|
|
317
|
+
deepEqual(source[key], target[key])
|
|
318
|
+
);
|
|
319
|
+
} else if (typeOf(source) === "date") {
|
|
320
|
+
return source.getTime() === target.getTime();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return source === target;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Checks whether a value is a js class.
|
|
330
|
+
*
|
|
331
|
+
* @param value - Value to inspect.
|
|
332
|
+
* @returns True if the value is a js class; otherwise false.
|
|
333
|
+
*/
|
|
334
|
+
export function isClass(func) {
|
|
335
|
+
// from https://stackoverflow.com/a/66120819
|
|
336
|
+
if(!(func && func.constructor === Function) || func.prototype === undefined)
|
|
337
|
+
return false;
|
|
338
|
+
if(Function.prototype !== Object.getPrototypeOf(func))
|
|
339
|
+
return true;
|
|
340
|
+
return Object.getOwnPropertyNames(func.prototype).length > 1;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Checks whether a value is an async function.
|
|
345
|
+
*
|
|
346
|
+
* @param value - Value to inspect.
|
|
347
|
+
* @returns True if the value is an async function; otherwise false.
|
|
348
|
+
*/
|
|
349
|
+
export function isAsync(fn) {
|
|
350
|
+
return typeof fn === 'function' && fn.constructor && fn.constructor.name === 'AsyncFunction';
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Checks whether a value is thenable (supports `.then` like a Promise).
|
|
355
|
+
*
|
|
356
|
+
* @param value - Value to inspect.
|
|
357
|
+
* @returns True if thenable; otherwise false.
|
|
358
|
+
*/
|
|
359
|
+
export function isThenable(x) {
|
|
360
|
+
return x && (typeof x === "object" || typeof x === "function") && typeof x.then === "function";
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Checks whether a value is an error.
|
|
365
|
+
*
|
|
366
|
+
* @param value - Value to inspect.
|
|
367
|
+
* @returns True if thenable; otherwise false.
|
|
368
|
+
*/
|
|
369
|
+
export function isError(x) {
|
|
370
|
+
return x instanceof Error || Object.prototype.toString.call(x) === '[object Error]';
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
// Internals
|
|
377
|
+
|
|
378
|
+
/** @ignore */
|
|
379
|
+
export let update_timeout = undefined;
|
|
380
|
+
/** @ignore */
|
|
381
|
+
export let update_interval_margin = 0;
|
|
382
|
+
/** @ignore */
|
|
383
|
+
export let id_num = Math.floor(Math.random()*10000);
|
|
384
|
+
/** @ignore */
|
|
385
|
+
export let eval_num = Math.floor(Math.random()*10000);
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
// todo =improve these stacks
|
|
389
|
+
/** @ignore */
|
|
390
|
+
export let current_component = [];
|
|
391
|
+
/** @ignore */
|
|
392
|
+
export let update_set = new Set;
|
|
393
|
+
/** @ignore */
|
|
394
|
+
export let update_cbs = new Set;
|
|
395
|
+
/** @ignore */
|
|
396
|
+
export let roots = new Set;
|
|
397
|
+
/** @ignore */
|
|
398
|
+
export let special_attributes = new Set(["classname", "classname", "ref", "action", "lilact_jsx_loc", "children", "key"]);
|
|
399
|
+
/** @ignore */
|
|
400
|
+
export let err = null; // this is only to ease debuggin,
|
|
401
|
+
/** @ignore */
|
|
402
|
+
export let layout_effects = new Set;
|
|
403
|
+
/** @ignore */
|
|
404
|
+
export let events_set = new Set([
|
|
405
|
+
"onafterprint","onbeforeprint","onbeforeunload","onerror","onhashchange","onload","onmessage",
|
|
406
|
+
"onoffline","ononline","onpagehide","onpageshow","onpopstate","onresize","onstorage","onunload",
|
|
407
|
+
"onblur","onchange","oncontextmenu","onfocus","oninput","oninvalid","onreset","onsearch","onselect",
|
|
408
|
+
"onsubmit",
|
|
409
|
+
"onkeydown","onkeypress","onkeyup",
|
|
410
|
+
"onclick","ondblclick","onmousedown","onmousemove","onmouseout","onmouseover","onmouseup","onmousewheel",
|
|
411
|
+
"onwheel",
|
|
412
|
+
"ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart","ondrop","onscroll",
|
|
413
|
+
"oncopy","oncut","onpaste",
|
|
414
|
+
"onabort","oncanplay","oncanplaythrough","oncuechange","ondurationchange","onemptied","onended","onerror",
|
|
415
|
+
"onloadeddata","onloadedmetadata","onloadstart","onpause","onplay","onplaying","onprogress","onratechange",
|
|
416
|
+
"onseeked","onseeking","onstalled","onsuspend","ontimeupdate","onvolumechange","onwaiting",
|
|
417
|
+
"ontoggle"
|
|
418
|
+
])
|
|
419
|
+
|