Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibiki v0.3.0 Release #4

Merged
merged 32 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
41eee78
minor updates to support new bulma component library. 'unwrap' attri…
sawka Feb 6, 2022
0f8c30f
add hibikiversion attribute to library -- allow them to require a cer…
sawka Feb 6, 2022
1da6aab
fix bug with false values on class attributes
sawka Feb 7, 2022
d4c213f
checkpoint, bulma control library
sawka Feb 7, 2022
93a56b4
ChildrenVar.filter, special invoke expression for filtering nodes by …
sawka Feb 7, 2022
3110ade
make if, if-break, condition attribute consistent in how they handle …
sawka Feb 7, 2022
9a1016f
After testing, change ChildrenVar.empty to ChildrenVar.size. empty d…
sawka Feb 7, 2022
dff82dd
remove unused InjectedAttrsObj.styleMap, and add merge function
sawka Feb 7, 2022
d482899
big behind the scenes change. children of custom components are now …
sawka Feb 8, 2022
5e0febd
fix mobx issue where defaults/define-vars was updating state during r…
sawka Feb 8, 2022
40c317d
move welcome message and source code link from nodes.tsx to main hibi…
sawka Feb 8, 2022
25644fc
only call event.preventDefault for clicks/submits when href/action at…
sawka Feb 8, 2022
d8e1b1d
Re-License Hibiki HTML under MPL 2.0 (OSI approved)
sawka Feb 8, 2022
15546ba
updates to hibikihtml homepage
sawka Feb 8, 2022
947498c
Next version will be 0.3.0 (because of license change)
sawka Feb 9, 2022
b84180f
Parse define-vars, datacontext, and componentdata blocks once in html…
sawka Feb 9, 2022
98aefe7
fix bug where component local event handlers did not see context vars…
sawka Feb 9, 2022
746d872
components now fire 'mount' event internally (can be caught with defi…
sawka Feb 9, 2022
dd64a33
grammar change to allow functions to receive named call params plus d…
sawka Feb 9, 2022
dd77adf
added new spaceship '<=>' operator for comparisons. added fn:upperca…
sawka Feb 10, 2022
118a514
new fn:compare, lots of options for comparing hibiki values, locale, …
sawka Feb 10, 2022
65debac
added fn:sort (with option to sort as references). also add a lot mo…
sawka Feb 10, 2022
686c5c1
fn:slice can now slice an array and return references to the original
sawka Feb 11, 2022
26f3758
really technical change that allows sub-references to be created from…
sawka Feb 11, 2022
6499d65
add slice and sortexpr parameters to fn:sort
sawka Feb 11, 2022
28aed35
fix 'if' attribute on h-children (foreach is not allowed). make noat…
sawka Feb 11, 2022
f649c26
bugfix, check fn:sort#sortexpr against noattr
sawka Feb 11, 2022
0b8fa70
remove dev build externals -- not worth the build complexity
sawka Feb 11, 2022
a34d7d9
small cleanups on playground/tutorial. no longer use children.all, j…
sawka Feb 11, 2022
12912e0
pass parentHtmlTag through all react nodes to eliminate rediculous re…
sawka Feb 11, 2022
a2159d4
clean up core library, removed redundant nodes
sawka Feb 12, 2022
6ccd7a9
update playground to link to versioned hibiki js (easier testing/depl…
sawka Feb 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix mobx issue where defaults/define-vars was updating state during r…
…ender. new createspecials datactx function which creates a new context map without using setPathInternal (so it is mobx safe). fixed issue with nested lvalues (bulma modalbutton)
  • Loading branch information
sawka committed Feb 8, 2022
commit 5e0febdbb731b0bd9d5cac2c1662ca09d3a34d02
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* added innerhtml and outerhtml to node var
* bugfix: class.[class] was not being properly set to false when set to the Hibiki value false
* bugfix: and/or operators were not correctly evaluating 'noattr' as false
* bugfix: fix component defaults, define-vars, and h-withcontext, to never update mobx state

## v0.2.0

Expand Down
22 changes: 8 additions & 14 deletions src/datactx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2789,25 +2789,19 @@ function ParseContextAssignListThrow(ctxStr : string) : {key : string, expr : HE
return actions;
}

function ParseAndCreateContextThrow(ctxStr : string, rootName : "context" | "c", dataenv : DataEnvironment, htmlContext : string) : DataEnvironment {
let ctxDataenv : DataEnvironment = null;
if (rootName === "context") {
ctxDataenv = dataenv.makeChildEnv({}, {htmlContext: htmlContext});
}
else {
ctxDataenv = dataenv;
}
function ParseAndCreateSpecialsThrow(ctxStr : string, dataenv : DataEnvironment, htmlContext : string) : HibikiValObj {
let caList = ParseContextAssignListThrow(ctxStr);
let rtctx = new RtContext();
rtctx.pushContext(htmlContext, null);
let specials : HibikiValObj = {};
for (let i=0; i<caList.length; i++) {
let caVal = caList[i];
let expr = evalExprAst(caVal.expr, ctxDataenv, "natural");
let setop = caVal.setop ?? "set";
let path : PathType = [{pathtype: "root", pathkey: rootName}, {pathtype: "map", pathkey: caVal.key}];
setPathWrapper(setop, path, ctxDataenv, expr, {allowContext: true});
let evalDataenv = dataenv.makeChildEnv(specials, {htmlContext: htmlContext});
let expr = evalExprAst(caVal.expr, evalDataenv, "natural");
let specialKey = caVal.key;
specials[specialKey] = expr;
}
return ctxDataenv;
return specials;
}

function EvalSimpleExpr(exprStr : string, dataenv : DataEnvironment, rtContext? : string) : any {
Expand Down Expand Up @@ -2995,7 +2989,7 @@ function setLValue(lv : LValue, setVal : HibikiVal) : void {
rlv.set(setVal);
}

export {ParsePath, ResolvePath, SetPath, ParsePathThrow, ResolvePathThrow, SetPathThrow, StringPath, JsonStringify, EvalSimpleExpr, ParseSetPathThrow, ParseSetPath, HibikiBlob, ObjectSetPath, DeepEqual, DeepCopy, CheckCycle, LValue, BoundLValue, ObjectLValue, ReadOnlyLValue, getShortEMsg, CreateReadOnlyLValue, demobx, BlobFromRRA, ExtBlobFromRRA, isObject, convertSimpleType, ParseStaticCallStatement, evalExprAst, ParseAndCreateContextThrow, BlobFromBlob, formatVal, ExecuteHandlerBlock, ExecuteHAction, makeIteratorFromExpr, rawAttrStr, getUnmergedAttributeStr, getUnmergedAttributeValPair, SYM_NOATTR, HActionBlock, valToString, valToBool, compileActionStr, FireEvent, makeErrorObj, OpaqueValue, ChildrenVar, Watcher, LambdaValue, blobPrintStr, asNumber, hibikiTypeOf, JsonReplacerFn, valToAttrStr, resolveLValue, resolveUnmergedCnArray, isUnmerged, resolveUnmergedStyleMap, asStyleMap, asStyleMapFromPair};
export {ParsePath, ResolvePath, SetPath, ParsePathThrow, ResolvePathThrow, SetPathThrow, StringPath, JsonStringify, EvalSimpleExpr, ParseSetPathThrow, ParseSetPath, HibikiBlob, ObjectSetPath, DeepEqual, DeepCopy, CheckCycle, LValue, BoundLValue, ObjectLValue, ReadOnlyLValue, getShortEMsg, CreateReadOnlyLValue, demobx, BlobFromRRA, ExtBlobFromRRA, isObject, convertSimpleType, ParseStaticCallStatement, evalExprAst, BlobFromBlob, formatVal, ExecuteHandlerBlock, ExecuteHAction, makeIteratorFromExpr, rawAttrStr, getUnmergedAttributeStr, getUnmergedAttributeValPair, SYM_NOATTR, HActionBlock, valToString, valToBool, compileActionStr, FireEvent, makeErrorObj, OpaqueValue, ChildrenVar, Watcher, LambdaValue, blobPrintStr, asNumber, hibikiTypeOf, JsonReplacerFn, valToAttrStr, resolveLValue, resolveUnmergedCnArray, isUnmerged, resolveUnmergedStyleMap, asStyleMap, asStyleMapFromPair, ParseAndCreateSpecialsThrow};

export type {PathType, HAction, HExpr, HIteratorExpr};

23 changes: 6 additions & 17 deletions src/dbctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,26 +675,17 @@ class DBCtx {
this.dataenv.dbstate.NodeDataMap.delete(this.uuid);
}

getNodeData(compName : string) : mobx.IObservableValue<HibikiVal> {
getNodeData(compName : string, defaultsObj? : HibikiValObj) : mobx.IObservableValue<HibikiValObj> {
let box = this.dataenv.dbstate.NodeDataMap.get(this.uuid);
if (box == null) {
let uuidName = "id_" + this.uuid.replace(/-/g, "_");
box = mobx.observable.box({_hibiki: {"customtag": compName, uuid: this.uuid}}, {name: uuidName});
let nodeData = Object.assign({}, defaultsObj, {_hibiki: {"customtag": compName, uuid: this.uuid}});
box = mobx.observable.box(nodeData, {name: uuidName});
this.dataenv.dbstate.NodeDataMap.set(this.uuid, box);
}
return box;
}

getNodeDataLV(compName : string) : DataCtx.ObjectLValue {
let box = this.dataenv.dbstate.NodeDataMap.get(this.uuid);
if (box == null) {
let uuidName = "id_" + this.uuid.replace(/-/g, "_");
box = mobx.observable.box({_hibiki: {"customtag": compName, uuid: this.uuid}}, {name: uuidName});
this.dataenv.dbstate.NodeDataMap.set(this.uuid, box);
}
return new DataCtx.ObjectLValue(null, box);
}

makeNodeVar(withAttrs : boolean) : HibikiValObj {
let node = this.node;
if (node == null) {
Expand Down Expand Up @@ -770,13 +761,12 @@ function bindSingleNode(node : HibikiNode, dataenv : DataEnvironment, injectedAt
return [makeErrorDBCtx("<define-vars> no context attribute", dataenv), false, null];
}
try {
let ctxDataenv = DataCtx.ParseAndCreateContextThrow(contextAttr, "context", dataenv, "<define-vars>");
return [null, false, ctxDataenv];
let specials = DataCtx.ParseAndCreateSpecialsThrow(contextAttr, dataenv, "<define-vars>");
return [null, false, dataenv.makeChildEnv(specials, {htmlContext: "<define-vars>"})];
}
catch (e) {
return [makeErrorDBCtx("<define-vars> Error parsing/executing context block: " + e, dataenv), false, null];
}
return [null, false, null];
}
if (node.tag === "define-handler") {
if (!isRoot) {
Expand Down Expand Up @@ -837,8 +827,7 @@ function expandChildrenNode(ctx : DBCtx) : DBCtx[] {
let contextattr = ctx.resolveAttrStr("datacontext");
if (contextattr != null) {
try {
let ctxEnv = DataCtx.ParseAndCreateContextThrow(contextattr, "context", ctx.dataenv, nodeStr(ctx.node));
ctxSpecials = ctxEnv.specials;
ctxSpecials = DataCtx.ParseAndCreateSpecialsThrow(contextattr, ctx.dataenv, nodeStr(ctx.node));
}
catch (e) {
let msg = nodeStr(ctx.node) + " Error parsing/executing context block: " + e;
Expand Down
19 changes: 13 additions & 6 deletions src/nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {parseHtml, HibikiNode, NodeAttrType} from "./html-parser";
import * as NodeUtils from "./nodeutils";
import {RtContext, HibikiError} from "./error";
import type {HAction} from "./datactx";
import type {EHandlerType} from "./state";
import type {EHandlerType, DataEnvironmentOpts} from "./state";

declare var window : any;

Expand Down Expand Up @@ -629,14 +629,13 @@ class CustomNode extends React.Component<HibikiReactProps & {component : Compone
let ctxHandlers = NodeUtils.makeHandlers(ctx.node, ctx.injectedAttrs, null, null);
let eventCtx = sprintf("%s", nodeStr(ctx.node));
let eventDE = ctx.dataenv.makeChildEnv(null, {eventBoundary: "hard", handlers: ctxHandlers, htmlContext: eventCtx});
let nodeDataLV = ctx.getNodeDataLV(componentName);
let specials : Record<string, any> = {};
specials.children = ctx.makeChildrenVar();
specials.node = nodeVar;
let argsRoot = resolveArgsRoot(ctx);
let handlers = NodeUtils.makeHandlers(implNode, null, component.libName, ["event"]);
let envOpts = {
componentRoot: unbox(ctx.getNodeData(componentName)),
let envOpts : DataEnvironmentOpts = {
componentRoot: {},
argsRoot: argsRoot,
handlers: handlers,
htmlContext: sprintf("<define-component %s>", componentName),
Expand All @@ -645,15 +644,22 @@ class CustomNode extends React.Component<HibikiReactProps & {component : Compone
};
let childEnv = eventDE.makeChildEnv(specials, envOpts);
if (initialize && rawImplAttrs.defaults != null) {
let htmlContext = sprintf("<define-component %s>:defaults", componentName);
let defaultsObj = {};
try {
DataCtx.ParseAndCreateContextThrow(DataCtx.rawAttrStr(rawImplAttrs.defaults), "c", childEnv, sprintf("<define-component %s>:defaults", componentName));
let defaultsStr = DataCtx.rawAttrStr(rawImplAttrs.defaults);
defaultsObj = DataCtx.ParseAndCreateSpecialsThrow(defaultsStr, childEnv, htmlContext);
}
catch (e) {
console.log(sprintf("ERROR parsing/executing 'defaults' in <define-component %s>", componentName), e);
}
childEnv.componentRoot = unbox(ctx.getNodeData(componentName, defaultsObj));
let implCtx = makeCustomDBCtx(implNode, childEnv, null);
implCtx.handleInitEvent();
}
else {
childEnv.componentRoot = unbox(ctx.getNodeData(componentName));
}
return childEnv;
}

Expand Down Expand Up @@ -755,7 +761,8 @@ class WithContextNode extends React.Component<HibikiReactProps, {}> {
return <ErrorMsg message={sprintf("%s no context attribute", nodeStr(ctx.node))}/>;
}
try {
let ctxDataenv = DataCtx.ParseAndCreateContextThrow(contextattr, "context", ctx.dataenv, nodeStr(ctx.node));
let specials = DataCtx.ParseAndCreateSpecialsThrow(contextattr, ctx.dataenv, nodeStr(ctx.node));
let ctxDataenv = ctx.dataenv.makeChildEnv(specials, {htmlContext: nodeStr(ctx.node)});
return ctxRenderHtmlChildren(ctx, ctxDataenv);
}
catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ class HibikiState {
DataNodeStates : Record<string, {query : string, dnstate : any}> = {};
ResourceCache : Record<string, boolean> = {};
HasRendered = false;
NodeDataMap : Map<string, mobx.IObservableValue<HibikiVal>> = new Map(); // TODO clear on unmount
NodeDataMap : Map<string, mobx.IObservableValue<HibikiValObj>> = new Map();
ExtHtmlObj : mobx.ObservableMap<string,any> = mobx.observable.map({}, {name: "ExtHtmlObj", deep: false});
Config : HibikiConfig = {};
PageName : mobx.IObservableValue<string> = mobx.observable.box("default", {name: "PageName"});
Expand Down Expand Up @@ -1337,4 +1337,4 @@ function hasHtmlRR(rra : any[]) : boolean {


export {HibikiState, DataEnvironment, HibikiExtState};
export type {EHandlerType};
export type {EHandlerType, DataEnvironmentOpts};
13 changes: 8 additions & 5 deletions static/libs/bulma.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="control" unwrap="!$args.control" automerge="control">
<button component="*$args.buttoncomponent" class="button" automerge click.handler="fire->click()">
<span if="$args.icon" class="icon" automerge="icon"><i class="*$args.icon"></i></span>
<h-fragment if="!!$args.icon && fn:len(@children.list) > 0">
<h-fragment if="!!$args.icon && @children.size">
<span><h-children bind="@children"></h-children></span>
</h-fragment>
<h-fragment if="!$args.icon">
Expand Down Expand Up @@ -132,10 +132,10 @@
<div class="dropdown" automerge class.is-active="* @active" active="*@active" hibiki-mark>
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu" click.handler="log('menu-click'); @active = !@active">
<h-if condition="fn:len(@activechildren.list) > 0">
<h-if condition="@activechildren.size">
<h-children bind="@activechildren.first" datacontext="@label=true"></h-children>
</h-if>
<h-if condition="fn:len(@activechildren.list) == 0">
<h-if condition="!@activechildren.size">
<span if="$args.label">{{ $args.label }}</span>
<h-children bind="@children.byslot['label']"></h-children>
</h-if>
Expand Down Expand Up @@ -196,10 +196,13 @@
</define-component>

<define-component name="modalbutton" defaults="show=false;">
<local-modal show="*ref($c.show)">
<define-vars>
@show = raw($args.show) ?? ref($c.show);
</define-vars>
<local-modal show="*@show">
<h-children bind="@children.noslot"></h-children>
</local-modal>
<button if="!$.show_modal" class="button" automerge="button" click.handler="$c.show = true;">
<button if="!$.show_modal" class="button" automerge="button" click.handler="@show = true;">
<h-children text="*$args.label" bind="@children.byslot['label']"></h-children>
</button>
</define-component>
Expand Down