@limetech/lime-crm-building-blocks 1.129.0 → 1.130.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/CHANGELOG.md +7 -0
- package/dist/cjs/lime-crm-building-blocks.cjs.js +1 -1
- package/dist/cjs/limebb-rule-editor.cjs.entry.js +101 -9
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/collection/components/rule-editor/chip-picker-view.js +2 -2
- package/dist/collection/components/rule-editor/rule-editor.js +102 -10
- package/dist/collection/components/rule-editor/view-helpers.js +9 -0
- package/dist/components/limebb-rule-editor.js +1 -1
- package/dist/esm/lime-crm-building-blocks.js +1 -1
- package/dist/esm/limebb-rule-editor.entry.js +102 -10
- package/dist/esm/loader.js +1 -1
- package/dist/lime-crm-building-blocks/lime-crm-building-blocks.esm.js +1 -1
- package/dist/lime-crm-building-blocks/p-f1d9e133.entry.js +1 -0
- package/dist/types/components/rule-editor/rule-editor-views.d.ts +2 -1
- package/dist/types/components/rule-editor/rule-editor.d.ts +54 -3
- package/dist/types/components/rule-editor/view-helpers.d.ts +8 -1
- package/dist/types/components.d.ts +30 -2
- package/package.json +2 -2
- package/dist/lime-crm-building-blocks/p-bd6e12e6.entry.js +0 -1
|
@@ -10,7 +10,8 @@ import { RulePath } from './rule-operations';
|
|
|
10
10
|
export interface RuleNodeRenderContext {
|
|
11
11
|
issues: RuleValidationIssue[];
|
|
12
12
|
metadataById: Map<string, PrimitiveMetadata>;
|
|
13
|
-
|
|
13
|
+
allPrimitiveOptions: Array<ListItem<string>>;
|
|
14
|
+
availablePrimitiveOptions: Array<ListItem<string>>;
|
|
14
15
|
isMutable: boolean;
|
|
15
16
|
readonly: boolean;
|
|
16
17
|
disabled: boolean;
|
|
@@ -17,12 +17,21 @@ import { ContextMap, LimeWebComponent, LimeWebComponentContext, LimeWebComponent
|
|
|
17
17
|
* forwards it to `RuleRegistry.validate` so `missing-slot` diagnostics
|
|
18
18
|
* surface inline on the offending nodes.
|
|
19
19
|
*
|
|
20
|
+
* The palette is surface-aware. When the editor is mounted in the DOM,
|
|
21
|
+
* it walks its host's ancestors through the context registry and unions
|
|
22
|
+
* the result with `availableContexts` to determine which context slots
|
|
23
|
+
* are reachable where the rule runs. Primitives whose `reads` slots
|
|
24
|
+
* aren't all reachable are hidden from the add palette, so an author
|
|
25
|
+
* can't pick a primitive that would silently fail closed at evaluation
|
|
26
|
+
* time.
|
|
27
|
+
*
|
|
20
28
|
* @exampleComponent limebb-example-rule-editor
|
|
21
29
|
*
|
|
22
30
|
* @alpha
|
|
23
31
|
* @private
|
|
24
32
|
*/
|
|
25
33
|
export declare class RuleEditor implements LimeWebComponent, FormComponent<Rule | undefined> {
|
|
34
|
+
host: HTMLElement;
|
|
26
35
|
platform: LimeWebComponentPlatform;
|
|
27
36
|
context: LimeWebComponentContext;
|
|
28
37
|
/**
|
|
@@ -33,8 +42,8 @@ export declare class RuleEditor implements LimeWebComponent, FormComponent<Rule
|
|
|
33
42
|
* Context keys the caller knows will be available where the rule
|
|
34
43
|
* runs. Forwarded to the rule registry's `validate` method so
|
|
35
44
|
* `missing-slot` issues surface inline. Leave unset when the
|
|
36
|
-
* evaluation context is not known
|
|
37
|
-
* the saved-rule library
|
|
45
|
+
* evaluation context is not known — typical for editors that target
|
|
46
|
+
* the saved-rule library.
|
|
38
47
|
*/
|
|
39
48
|
availableContexts?: (keyof ContextMap)[];
|
|
40
49
|
/**
|
|
@@ -74,9 +83,20 @@ export declare class RuleEditor implements LimeWebComponent, FormComponent<Rule
|
|
|
74
83
|
private issues;
|
|
75
84
|
private openChipPath;
|
|
76
85
|
private metadataById;
|
|
77
|
-
private
|
|
86
|
+
private allPrimitiveOptions;
|
|
87
|
+
private availablePrimitiveOptions;
|
|
88
|
+
private reachableSlots;
|
|
78
89
|
private normalizedCache;
|
|
90
|
+
private hasLoaded;
|
|
79
91
|
componentWillLoad(): void;
|
|
92
|
+
private rebuildFromRegistries;
|
|
93
|
+
/**
|
|
94
|
+
* Re-walk reachable slots when the editor is re-attached to the DOM,
|
|
95
|
+
* e.g. moved between surfaces. The reachable set depends on the host's
|
|
96
|
+
* ancestors, so a move can change which primitives the palette offers.
|
|
97
|
+
* Skipped on the first connect — `componentWillLoad` covers that.
|
|
98
|
+
*/
|
|
99
|
+
connectedCallback(): void;
|
|
80
100
|
componentDidLoad(): void;
|
|
81
101
|
protected onValueChange(): void;
|
|
82
102
|
protected onAvailableContextsChange(): void;
|
|
@@ -90,6 +110,35 @@ export declare class RuleEditor implements LimeWebComponent, FormComponent<Rule
|
|
|
90
110
|
private handleChipInteract;
|
|
91
111
|
private handlePopoverClose;
|
|
92
112
|
private indexMetadata;
|
|
113
|
+
/**
|
|
114
|
+
* Recompute the cached add-palette options. The inputs — indexed
|
|
115
|
+
* metadata, the reachable slot set, and the translator — only change
|
|
116
|
+
* in `rebuildFromRegistries` and `connectedCallback`, so caching here
|
|
117
|
+
* keeps `render` from rebuilding and sorting the list every pass.
|
|
118
|
+
*/
|
|
119
|
+
private rebuildAvailableOptions;
|
|
120
|
+
/**
|
|
121
|
+
* The subset of registered metadata offered for adding in the
|
|
122
|
+
* palette: primitives whose `reads` aren't fully covered by the
|
|
123
|
+
* reachable slots are dropped. Filtering only the palette — not the
|
|
124
|
+
* full `allPrimitiveOptions` — keeps already-placed chips resolving
|
|
125
|
+
* to their proper title even when their read slot isn't reachable.
|
|
126
|
+
*/
|
|
127
|
+
private availablePrimitiveMetadata;
|
|
128
|
+
/**
|
|
129
|
+
* Recompute the context slots reachable from the editor's mount
|
|
130
|
+
* point, unioning two sources:
|
|
131
|
+
*
|
|
132
|
+
* - the registered keys the resolver answers for — it walks the DOM
|
|
133
|
+
* from the host (and the session-wide fallbacks) the same way the
|
|
134
|
+
* runtime scope does, so a key resolves only when an ancestor
|
|
135
|
+
* actually provides it;
|
|
136
|
+
* - `availableContexts`, a hardcoded hint for keys (notably
|
|
137
|
+
* `limeobject`) that have no session-wide fallback and are provided
|
|
138
|
+
* by a different application than the one hosting the editor, so the
|
|
139
|
+
* DOM walk can't discover them.
|
|
140
|
+
*/
|
|
141
|
+
private computeReachableSlots;
|
|
93
142
|
private runValidation;
|
|
94
143
|
private emitIfChanged;
|
|
95
144
|
/**
|
|
@@ -114,5 +163,7 @@ export declare class RuleEditor implements LimeWebComponent, FormComponent<Rule
|
|
|
114
163
|
*/
|
|
115
164
|
private emitNormalization;
|
|
116
165
|
private get ruleRegistry();
|
|
166
|
+
private get translator();
|
|
167
|
+
private get contextRegistry();
|
|
117
168
|
}
|
|
118
169
|
//# sourceMappingURL=rule-editor.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LimelPickerCustomEvent, ListItem } from '@limetech/lime-elements';
|
|
2
|
-
import { PrimitiveMetadata, RuleValidationIssue, Translator } from '@limetech/lime-web-components';
|
|
2
|
+
import { ContextMap, PrimitiveMetadata, RuleValidationIssue, Translator } from '@limetech/lime-web-components';
|
|
3
3
|
/**
|
|
4
4
|
* Event emitted by `limel-picker` when its value changes. Single-select
|
|
5
5
|
* pickers receive a single item, multi-select pickers receive an array.
|
|
@@ -27,6 +27,13 @@ export declare function nodeClasses(type: 'all' | 'any', issues: RuleValidationI
|
|
|
27
27
|
* @param translator
|
|
28
28
|
*/
|
|
29
29
|
export declare function createPrimitiveOptions(metadataById: Map<string, PrimitiveMetadata>, translator: Translator): Array<ListItem<string>>;
|
|
30
|
+
/**
|
|
31
|
+
* Whether every context key a primitive reads is in the reachable set.
|
|
32
|
+
* A primitive that reads nothing is always covered.
|
|
33
|
+
* @param meta
|
|
34
|
+
* @param reachable
|
|
35
|
+
*/
|
|
36
|
+
export declare function primitiveReadsCovered(meta: PrimitiveMetadata, reachable: Set<keyof ContextMap>): boolean;
|
|
30
37
|
/**
|
|
31
38
|
* Find the picker item for `id`, falling back to a placeholder marked
|
|
32
39
|
* with the unknown-primitive icon when the id isn't in the registry.
|
|
@@ -2272,13 +2272,20 @@ export namespace Components {
|
|
|
2272
2272
|
* caller knows will be available where the rule runs. The component
|
|
2273
2273
|
* forwards it to `RuleRegistry.validate` so `missing-slot` diagnostics
|
|
2274
2274
|
* surface inline on the offending nodes.
|
|
2275
|
+
* The palette is surface-aware. When the editor is mounted in the DOM,
|
|
2276
|
+
* it walks its host's ancestors through the context registry and unions
|
|
2277
|
+
* the result with `availableContexts` to determine which context slots
|
|
2278
|
+
* are reachable where the rule runs. Primitives whose `reads` slots
|
|
2279
|
+
* aren't all reachable are hidden from the add palette, so an author
|
|
2280
|
+
* can't pick a primitive that would silently fail closed at evaluation
|
|
2281
|
+
* time.
|
|
2275
2282
|
* @exampleComponent limebb-example-rule-editor
|
|
2276
2283
|
* @alpha
|
|
2277
2284
|
* @private
|
|
2278
2285
|
*/
|
|
2279
2286
|
interface LimebbRuleEditor {
|
|
2280
2287
|
/**
|
|
2281
|
-
* Context keys the caller knows will be available where the rule runs. Forwarded to the rule registry's `validate` method so `missing-slot` issues surface inline. Leave unset when the evaluation context is not known
|
|
2288
|
+
* Context keys the caller knows will be available where the rule runs. Forwarded to the rule registry's `validate` method so `missing-slot` issues surface inline. Leave unset when the evaluation context is not known — typical for editors that target the saved-rule library.
|
|
2282
2289
|
*/
|
|
2283
2290
|
"availableContexts"?: (keyof ContextMap)[];
|
|
2284
2291
|
/**
|
|
@@ -4401,6 +4408,13 @@ declare global {
|
|
|
4401
4408
|
* caller knows will be available where the rule runs. The component
|
|
4402
4409
|
* forwards it to `RuleRegistry.validate` so `missing-slot` diagnostics
|
|
4403
4410
|
* surface inline on the offending nodes.
|
|
4411
|
+
* The palette is surface-aware. When the editor is mounted in the DOM,
|
|
4412
|
+
* it walks its host's ancestors through the context registry and unions
|
|
4413
|
+
* the result with `availableContexts` to determine which context slots
|
|
4414
|
+
* are reachable where the rule runs. Primitives whose `reads` slots
|
|
4415
|
+
* aren't all reachable are hidden from the add palette, so an author
|
|
4416
|
+
* can't pick a primitive that would silently fail closed at evaluation
|
|
4417
|
+
* time.
|
|
4404
4418
|
* @exampleComponent limebb-example-rule-editor
|
|
4405
4419
|
* @alpha
|
|
4406
4420
|
* @private
|
|
@@ -7084,13 +7098,20 @@ declare namespace LocalJSX {
|
|
|
7084
7098
|
* caller knows will be available where the rule runs. The component
|
|
7085
7099
|
* forwards it to `RuleRegistry.validate` so `missing-slot` diagnostics
|
|
7086
7100
|
* surface inline on the offending nodes.
|
|
7101
|
+
* The palette is surface-aware. When the editor is mounted in the DOM,
|
|
7102
|
+
* it walks its host's ancestors through the context registry and unions
|
|
7103
|
+
* the result with `availableContexts` to determine which context slots
|
|
7104
|
+
* are reachable where the rule runs. Primitives whose `reads` slots
|
|
7105
|
+
* aren't all reachable are hidden from the add palette, so an author
|
|
7106
|
+
* can't pick a primitive that would silently fail closed at evaluation
|
|
7107
|
+
* time.
|
|
7087
7108
|
* @exampleComponent limebb-example-rule-editor
|
|
7088
7109
|
* @alpha
|
|
7089
7110
|
* @private
|
|
7090
7111
|
*/
|
|
7091
7112
|
interface LimebbRuleEditor {
|
|
7092
7113
|
/**
|
|
7093
|
-
* Context keys the caller knows will be available where the rule runs. Forwarded to the rule registry's `validate` method so `missing-slot` issues surface inline. Leave unset when the evaluation context is not known
|
|
7114
|
+
* Context keys the caller knows will be available where the rule runs. Forwarded to the rule registry's `validate` method so `missing-slot` issues surface inline. Leave unset when the evaluation context is not known — typical for editors that target the saved-rule library.
|
|
7094
7115
|
*/
|
|
7095
7116
|
"availableContexts"?: (keyof ContextMap)[];
|
|
7096
7117
|
/**
|
|
@@ -8668,6 +8689,13 @@ declare module "@stencil/core" {
|
|
|
8668
8689
|
* caller knows will be available where the rule runs. The component
|
|
8669
8690
|
* forwards it to `RuleRegistry.validate` so `missing-slot` diagnostics
|
|
8670
8691
|
* surface inline on the offending nodes.
|
|
8692
|
+
* The palette is surface-aware. When the editor is mounted in the DOM,
|
|
8693
|
+
* it walks its host's ancestors through the context registry and unions
|
|
8694
|
+
* the result with `availableContexts` to determine which context slots
|
|
8695
|
+
* are reachable where the rule runs. Primitives whose `reads` slots
|
|
8696
|
+
* aren't all reachable are hidden from the add palette, so an author
|
|
8697
|
+
* can't pick a primitive that would silently fail closed at evaluation
|
|
8698
|
+
* time.
|
|
8671
8699
|
* @exampleComponent limebb-example-rule-editor
|
|
8672
8700
|
* @alpha
|
|
8673
8701
|
* @private
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@limetech/lime-crm-building-blocks",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.130.0",
|
|
4
4
|
"description": "A home for shared components meant for use with Lime CRM",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@limetech/eslint-config": "^4.0.1",
|
|
38
|
-
"@limetech/lime-elements": "^39.29.
|
|
38
|
+
"@limetech/lime-elements": "^39.29.3",
|
|
39
39
|
"@limetech/lime-web-components": "^6.24.0",
|
|
40
40
|
"@lundalogik/lime-icons8": "^2.41.0",
|
|
41
41
|
"@lundalogik/limeclient.js": "^1.105.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{h as e,r as t,c as r}from"./p-BIwHMk6j.js";import{b as n}from"./p-C84z8BwL.js";function l(e,t){return t?{type:"not",rule:e}:e}function o(e,t){return e.length===t.length&&e.every(((e,r)=>e===t[r]))}function i(e,t){return e.filter((e=>o(e.path,t)))}function s(e,t){let r=e;for(const e of t)r=a(r,e);return r}function u(e,t,r){if(0===t.length)return r;const[n,...l]=t;if("not"===e.type&&"rule"===n)return Object.assign(Object.assign({},e),{rule:u(e.rule,l,r)});if(("all"===e.type||"any"===e.type)&&"rules"===n){if(0===l.length)return r;const[t,...n]=l;if("number"!=typeof t)return e;const o=[...e.rules];return o[t]=u(o[t],n,r),Object.assign(Object.assign({},e),{rules:o})}return e}function a(e,t){return"not"===e.type&&"rule"===t?e.rule:"all"!==e.type&&"any"!==e.type||"rules"!==t?"all"!==e.type&&"any"!==e.type||"number"!=typeof t?e:e.rules[t]:e}const c={name:"question",color:"rgb(var(--color-glaucous-light))"};function d(e){return`__chip__:${e}`}function h(e){return"ref"===e.type?{ref:e,isNegated:!1}:"not"===e.type&&"ref"===e.rule.type?{ref:e.rule,isNegated:!0}:null}const p=({groupNode:t,groupPath:r,chipChildren:n,ctx:l})=>{const o=new Map,i=n.map((e=>{const t=d(e.index);o.set(t,e);const r=(n=e.ref.id,null!==(i=l.primitiveOptions.find((e=>e.value===n)))&&void 0!==i?i:{value:n,text:n,icon:c});var n,i;return Object.assign(Object.assign({},r),{text:e.isNegated?`¬ ${r.text}`:r.text,value:t})})),s=(u=l.primitiveOptions,e=>Promise.resolve(function(e,t){if(!t)return e;const r=t.toLocaleLowerCase().split(/\s+/);return e.filter((e=>r.every((t=>{var r,n;return e.text.toLocaleLowerCase().includes(t)||(null===(r=e.secondaryText)||void 0===r?void 0:r.toLocaleLowerCase().includes(t))||(null===(n=e.value)||void 0===n?void 0:n.toLocaleLowerCase().includes(t))}))))}(u,e)));var u;const a=function(e,t,r){var n;const l=_(t,r);return null===l?null:null!==(n=e.find((e=>e.index===l)))&&void 0!==n?n:null}(n,r,l.openChipPath),h="all"===t.type?"&":"|";return e("limel-popover",{class:"rule-node__chips-popover",open:null!==a,openDirection:"bottom-start",onClose:l.onPopoverClose},e("div",{slot:"trigger",class:"rule-node__chips"},e("limel-picker",{multiple:!0,label:l.translator.get("webclient.rule-editor.rules-label"),value:i,searcher:s,delimiter:h,readonly:l.readonly,disabled:l.disabled,onChange:f(t,r,o,l),onInteract:b(r,o,l)})),e("div",null,function(t,r,n){if(!t)return null;const l=function(e,t){return[...e,"rules",t]}(r,t.index);return e("limebb-rule-chip-popover",{platform:n.platform,context:n.context,refNode:t.ref,isNegated:t.isNegated,metadata:n.metadataById.get(t.ref.id),readonly:n.readonly,disabled:n.disabled,isMutable:n.isMutable,onNegate:v(t,l,n),onUpdateArgs:g(t,l,n),onDeleteChip:m(l,n)})}(a,r,l)))},f=(e,t,r,n)=>l=>{l.stopPropagation();const o=Array.isArray(l.detail)?l.detail:[],i=_(t,n.openChipPath);if(null!==i){const e=d(i);o.every((t=>t.value!==e))&&n.onPopoverClose()}const s=o.flatMap((e=>{if("string"!=typeof e.value)return[];const t=r.get(e.value);return t?[t.isNegated?{type:"not",rule:t.ref}:t.ref]:[{type:"ref",id:e.value}]})),u=e.rules.filter((e=>null===h(e)));n.onReplaceNode(t,Object.assign(Object.assign({},e),{rules:[...s,...u]}))},b=(e,t,r)=>n=>{n.stopPropagation();const l=function(e){if("string"==typeof e)return e;if(e&&"object"==typeof e&&"value"in e){const t=e.value;return"string"==typeof t?t:void 0}}(n.detail),o=l?t.get(l):void 0;o&&r.onChipInteract([...e,"rules",o.index])},v=(e,t,r)=>n=>{n.stopPropagation(),r.onReplaceNode(t,n.detail?{type:"not",rule:e.ref}:e.ref)},g=(e,t,r)=>n=>{n.stopPropagation();const l=e.isNegated?[...t,"rule"]:t;r.onUpdateArgs(l,n.detail)},m=(e,t)=>()=>{t.onDelete(e)};function _(e,t){if(!t||t.length<2)return null;if(!o((r=t,r.slice(0,-2)),e))return null;var r;const n=t.at(-1);return"number"==typeof n?n:null}const y=({node:t,path:r,isNegated:n,ctx:l})=>{const o=n?[...r,"rule"]:r,s=n?[...i(l.issues,r),...i(l.issues,o)]:i(l.issues,r),u=[],a=[];for(const[e,r]of t.rules.entries()){const t=h(r);t?u.push(Object.assign(Object.assign({},t),{index:e})):a.push({child:r,index:e})}const c=function(e){return[{value:"all",text:e.translator.get("webclient.rule-editor.combinator.all")},{value:"any",text:e.translator.get("webclient.rule-editor.combinator.any")}]}(l),d=c.find((e=>e.value===t.type));return e("div",{class:(f=t.type,b=s,{"rule-node":!0,[`rule-node--${f}`]:!0,"rule-node--invalid":b.length>0}),key:x(r)},e("div",{class:"rule-node__header"},e("limel-select",{class:"rule-node__combinator-select",value:d,options:c,disabled:!l.isMutable,onChange:C(t,r,n,l)}),function(t,r,n,l){return l.isMutable?e("div",{class:"rule-node__header-actions"},e("limel-switch",{class:"rule-node__negate-switch",label:l.translator.get("webclient.rule-editor.negate"),value:n,onChange:O(t,r,l)}),e("limel-icon-button",{icon:"trash",label:l.translator.get("webclient.rule-editor.delete"),onClick:()=>l.onDelete(r)})):null}(t,r,n,l)),e("div",{class:"rule-node__body"},e(M,{issues:s}),e(p,{groupNode:t,groupPath:o,chipChildren:u,ctx:l}),function(t,r,n){return 0===t.length?null:e("div",{class:"rule-node__children"},t.map((t=>e(N,{node:t.child,path:[...r,"rules",t.index],ctx:n}))))}(a,o,l),function(t,r,n,l){return l.isMutable?e("div",{class:"rule-node__footer"},e("limel-button",{icon:"add",label:l.translator.get("webclient.rule-editor.add-nested-group"),onClick:w(t,r,n,l)})):null}(t,r,n,l)));var f,b};function x(e){return 0===e.length?"root":e.join("/")}function j(e,t,r,n){n.onReplaceNode(t,l(e,r))}const C=(e,t,r,n)=>l=>{l.stopPropagation();const o=l.detail.value;o!==e.type&&j(Object.assign(Object.assign({},e),{type:o}),t,r,n)},w=(e,t,r,n)=>()=>{var l,o;j((l=e,o={type:"all",rules:[]},Object.assign(Object.assign({},l),{rules:[...l.rules,o]})),t,r,n)},O=(e,t,r)=>n=>{n.stopPropagation(),r.onReplaceNode(t,l(e,n.detail))},N=t=>{const{node:r,path:n,ctx:l}=t,o=z(r);return o?e(y,{node:o.node,path:n,isNegated:o.isNegated,ctx:l}):null},k=e=>"not"===e.type&&("all"===e.rule.type||"any"===e.rule.type);function z(e){if("all"===e.type||"any"===e.type)return{node:e,isNegated:!1};if(k(e))return{node:e.rule,isNegated:!0};if("not"===e.type){const t=z(e.rule);if(t)return{node:t.node,isNegated:!t.isNegated}}return null}const M=({issues:t})=>0===t.length?null:t.map((t=>e("div",{class:"rule-node__issue"},t.message))),A=class{constructor(e){t(this,e),this.change=r(this,"change"),this.issues=[],this.openChipPath=null,this.metadataById=new Map,this.primitiveOptions=[],this.normalizedCache=null,this.handleDelete=e=>{this.openChipPath=null,this.emitIfChanged(function(e,t){if(0===t.length)return{type:"all",rules:[]};const r=t.slice(0,-1),n=t.at(-1),l=s(e,r);if(("all"===l.type||"any"===l.type)&&"number"==typeof n){const t=[...l.rules];return t.splice(n,1),u(e,r,Object.assign(Object.assign({},l),{rules:t}))}return"not"===l.type&&"rule"===n?u(e,r,{type:"all",rules:[]}):e}(this.normalizedValue,e))},this.handleUpdateArgs=(e,t)=>{this.emitIfChanged(function(e,t,r){const n=s(e,t);return"ref"!==n.type?e:u(e,t,Object.assign(Object.assign({},n),{args:r}))}(this.normalizedValue,e,t))},this.handleReplaceNode=(e,t)=>{this.emitIfChanged(function(e,t,r){return u(e,t,r)}(this.normalizedValue,e,t))},this.handleChipInteract=e=>{this.openChipPath=e},this.handlePopoverClose=()=>{this.openChipPath=null}}componentWillLoad(){this.indexMetadata(),this.runValidation()}componentDidLoad(){this.emitNormalization()}onValueChange(){this.emitNormalization()||this.runValidation()}onAvailableContextsChange(){this.runValidation()}render(){return e("div",{key:"8e0da39f6544c86de0143e91a6c48c9f2654315f",class:{"rule-editor":!0,"rule-editor--disabled":this.disabled}},this.renderLabel(),e(N,{key:"cd093f5dc5a9b747036f581e6230f1205cf834e6",node:this.normalizedValue,path:[],ctx:this.createRenderContext()}),this.renderHelperText())}renderLabel(){return this.label?e("div",{class:"rule-editor__label"},this.label):null}renderHelperText(){return this.helperText?e("div",{class:"rule-editor__helper-text"},this.helperText):null}createRenderContext(){return{issues:this.issues,metadataById:this.metadataById,primitiveOptions:this.primitiveOptions,isMutable:!this.readonly&&!this.disabled,readonly:this.readonly,disabled:this.disabled,platform:this.platform,context:this.context,translator:this.platform.get(n.Translate),openChipPath:this.openChipPath,onDelete:this.handleDelete,onUpdateArgs:this.handleUpdateArgs,onReplaceNode:this.handleReplaceNode,onChipInteract:this.handleChipInteract,onPopoverClose:this.handlePopoverClose}}indexMetadata(){var e,t,r;const l=null!==(r=null===(t=(e=this.ruleRegistry).listMetadata)||void 0===t?void 0:t.call(e))&&void 0!==r?r:[];var o,i;this.metadataById=new Map(l.map((e=>[e.id,e]))),this.primitiveOptions=(o=this.metadataById,i=this.platform.get(n.Translate),[...o.values()].map((e=>({value:e.id,text:e.title?i.get(e.title):e.id,secondaryText:e.description?i.get(e.description):"",icon:e.icon}))).sort(((e,t)=>e.text.localeCompare(t.text))))}runValidation(){if(!this.value)return void(this.issues=[]);const e=this.ruleRegistry.validate(this.normalizedValue,this.availableContexts);this.issues=e.ok?[]:e.issues}emitIfChanged(e){var t;e!==this.normalizedValue&&this.change.emit("all"!==(t=e).type&&"any"!==t.type?t:0===t.rules.length?void 0:t)}get normalizedValue(){if(null!==this.normalizedCache&&this.normalizedCache.source===this.value)return this.normalizedCache.normalized;const e=(t=this.value)?z(t)?t:{type:"all",rules:[t]}:{type:"all",rules:[]};var t;return this.normalizedCache={source:this.value,normalized:e},e}emitNormalization(){if(!this.value)return!1;const e=this.normalizedValue;return e!==this.value&&(this.change.emit(e),!0)}get ruleRegistry(){return this.platform.get(n.RuleRegistry)}static get watchers(){return{value:[{onValueChange:0}],availableContexts:[{onAvailableContextsChange:0}]}}};A.style=":host{display:block}.rule-editor--disabled{opacity:0.6;pointer-events:none}.rule-editor__label{font-size:0.75rem;font-weight:600;color:rgb(var(--contrast-1500));margin-bottom:0.25rem}.rule-editor__helper-text{font-size:0.75rem;color:rgb(var(--contrast-1300));margin-top:0.25rem}.rule-node{border:1px solid rgb(var(--contrast-500));border-radius:0.5rem;margin:0.25rem 0;overflow:hidden;background-color:rgb(var(--contrast-100))}.rule-node--invalid{border-color:rgb(var(--color-red-default))}.rule-node--all>.rule-node__header,.rule-node--any>.rule-node__header{background-color:rgb(var(--contrast-300));padding:0.375rem 0.75rem;border-bottom:1px solid rgb(var(--contrast-500))}.rule-node__header{display:flex;align-items:center;gap:0.5rem}.rule-node__header-actions{margin-left:auto;display:grid;grid-auto-flow:column;grid-gap:0.5rem;padding:0.125rem;align-items:center}.rule-node__combinator-select{min-width:6rem}.rule-node__body{padding:0.75rem;display:flex;flex-direction:column;gap:0.75rem}limel-popover.rule-node__chips-popover{display:contents}.rule-node__chips{display:block;width:100%}.rule-node__chips limel-picker{display:block;width:100%}.rule-node__children{display:flex;flex-direction:column;gap:0.5rem}.rule-node__footer{display:flex;justify-content:center}.rule-node__issue{color:rgb(var(--color-red-default));font-size:0.875rem}";export{A as limebb_rule_editor}
|