[Feature request] Resolve directives in conditions (visible, $cond)
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 68/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- frontend
調査の方向性
Start with resolveComparisonValue and resolveConditionValue in @json-render/core, then trace the visibility condition types and VisibilityConditionSchema and VisibilityConditionStrictSchema. Check the conditions section of catalog.prompt({ directives }) for the prompt update. Done means registered directives resolve on either side of comparisons, accepted types and schemas validate them, and runtime behavior is covered for visible and $cond.
索引モデルが issue の本文から書いたものです。
説明
Hi! Thanks for json-render, directives have been really useful for us. Here's a small feature request around conditions.
Context
Directives (defineDirective) are resolved in props and action params (via resolvePropValue), but not in conditions. In @json-render/core 0.20:
resolveComparisonValue(the right side ofeq,neq,gt,lt…) only resolves{ "$state" }; any other object is compared as is.resolveConditionValue(the left side) only accepts$state,$itemor$index.
Use case
Comparing against a value computed at render time, with the standard directives or a custom one:
{ "visible": { "$count": { "$state": "/cart/items" }, "gt": 0 } }
{
"visible": {
"$state": "/product/stock",
"lt": { "$math": "multiply", "a": { "$state": "/product/minStock" }, "b": 2 }
}
}
{ "visible": { "$item": "dueDate", "eq": { "$today": true } } }
($today would be a custom directive that returns today's date.)
Current behavior
- On the right side, the directive is compared as a literal object: the condition never matches, with no warning.
- On the left side, the condition has no
$state,$itemor$index: its value isundefined, andvalidateSpecrejects it (VisibilityConditionStrictSchema).
The workaround today is to save the value to state first (a setState on some event) and compare against { "$state" }. It's more verbose for whoever writes the spec (or the model generating it), and the value goes stale until that event runs again.
Proposal
Resolve a registered directive on both sides of a comparison. The ctx already carries directives both in an element's visible (the renderer builds the full context) and in $cond (resolvePropValue):
function resolveComparisonValue(value, ctx) {
if (typeof value === "object" && value !== null) {
if ("$state" in value && typeof value.$state === "string") {
return getByPath(ctx.stateModel, value.$state);
}
const directive = findDirective(value, ctx.directives);
if (directive) return directive.resolve(value, ctx);
}
return value;
}
function resolveConditionValue(cond, ctx) {
// … $index and $item as today
const directive = findDirective(cond, ctx.directives);
if (directive) return directive.resolve(cond, ctx);
return getByPath(ctx.stateModel, cond.$state);
}
On the left side, the directive gets the object with its operator included (gt, eq…), which its resolve ignores.
To be consistent, this would also need:
- Types:
gt/gte/lt/lteaccepting a directive, and aSingleConditionvariant whose value is a directive. - Schemas:
VisibilityConditionSchemaandVisibilityConditionStrictSchemaaccepting those forms, sovalidateSpecdoesn't flag them as invalid. - Prompt: a line in the conditions section of
catalog.prompt({ directives }), so the model knows it can use a directive on either side.
We tested it with a local patch of @json-render/core 0.20, covering runtime and types. Happy to open a PR if this sounds good, thanks!
- 主要言語
- TypeScript
- スター
- 20k
- フォーク
- 1.1k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 25
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
vercel-labs/json-render のほかの issue
-
React Quick Start examples fail at runtime: Renderer must be wrapped in JSONUIProvider対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 86/100
vercel-labs/json-render#443 ·
メンテナーはふだん 2 日以内に返信
-
shadcn Grid/Stack are not responsive (fixed grid-cols-N, no min-w-0)対応中かも @sushanshakya77 が 67 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
vercel-labs/json-render#355 ·
メンテナーはふだん 2 日以内に返信
-
Array path helpers accept malformed RFC 6902 indexes対応中かも @simonyang08 が 106 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
vercel-labs/json-render#326 ·
メンテナーはふだん 2 日以内に返信
-
Support zod 4.4+ — _zod.version.minor type check prevents upgrade再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
vercel-labs/json-render#297 · リアクション 2 件 ·
メンテナーはふだん 2 日以内に返信
-
feat: Generic `Spec` type support対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
vercel-labs/json-render#275 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
vercel-labs/json-render の issue をすべて見る
似ている issue
-
bug data-types
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
ClickHouse/clickhouse-js#1293 ·
メンテナーはふだん 1 日以内に返信
-
area: middleware enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
agent/quality testing
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
メンテナーはふだん 1 日以内に返信
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
juspay/agent-distro#203 ·
メンテナーはふだん 1 日以内に返信