@pod-os/elements 0.43.0-rc.4862e82.0 → 0.43.0-rc.9c5d5f9.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/dist/cjs/elements.cjs.js +1 -1
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/pos-case.cjs.entry.js +1 -1
- package/dist/cjs/pos-case.cjs.entry.js.map +1 -1
- package/dist/cjs/pos-switch.cjs.entry.js +3 -0
- package/dist/cjs/pos-switch.cjs.entry.js.map +1 -1
- package/dist/collection/components/pos-switch/pos-case/pos-case.js +1 -1
- package/dist/collection/components/pos-switch/pos-case/pos-case.js.map +1 -1
- package/dist/collection/components/pos-switch/pos-switch.css +3 -0
- package/dist/collection/components/pos-switch/pos-switch.js +10 -0
- package/dist/collection/components/pos-switch/pos-switch.js.map +1 -1
- package/dist/components/pos-case.js +1 -1
- package/dist/components/pos-case.js.map +1 -1
- package/dist/components/pos-switch.js +1 -1
- package/dist/components/pos-switch.js.map +1 -1
- package/dist/elements/elements.esm.js +1 -1
- package/dist/elements/p-7b27a836.entry.js +2 -0
- package/dist/elements/p-7b27a836.entry.js.map +1 -0
- package/dist/elements/{p-912e2f57.entry.js → p-a16ec07a.entry.js} +2 -2
- package/dist/elements/p-a16ec07a.entry.js.map +1 -0
- package/dist/esm/elements.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/pos-case.entry.js +1 -1
- package/dist/esm/pos-case.entry.js.map +1 -1
- package/dist/esm/pos-switch.entry.js +3 -0
- package/dist/esm/pos-switch.entry.js.map +1 -1
- package/package.json +2 -2
- package/dist/elements/p-912e2f57.entry.js.map +0 -1
- package/dist/elements/p-92e490db.entry.js +0 -2
- package/dist/elements/p-92e490db.entry.js.map +0 -1
package/dist/cjs/elements.cjs.js
CHANGED
|
@@ -45,7 +45,7 @@ var patchCloneNodeFix = (HTMLElementPrototype) => {
|
|
|
45
45
|
|
|
46
46
|
patchBrowser().then(async (options) => {
|
|
47
47
|
await index.globalScripts();
|
|
48
|
-
return index.bootstrapLazy([["pos-app-generic.cjs",[[1,"pos-app-generic"]]],["pos-app-ldp-container.cjs",[[1,"pos-app-ldp-container"]]],["pos-app-rdf-document.cjs",[[1,"pos-app-rdf-document"]]],["pos-app-image-viewer.cjs",[[1,"pos-app-image-viewer",{"resource":[32]}]]],["pos-tool-attachments.cjs",[[1,"pos-tool-attachments",{"os":[32],"resource":[32]}]]],["pos-app-document-viewer.cjs",[[1,"pos-app-document-viewer",{"resource":[32]}]]],["pos-list.cjs",[[0,"pos-list",{"rel":[1],"ifTypeof":[1,"if-typeof"],"fetch":[4],"error":[32],"os":[32],"resource":[32],"items":[32],"templateString":[32]}]]],["pos-case.cjs",[[0,"pos-case",{"ifTypeof":[1,"if-typeof"],"ifProperty":[1,"if-property"],"ifRev":[1,"if-rev"],"not":[4],"else":[4],"someValueEq":[1,"some-value-eq"],"everyValueEq":[1,"every-value-eq"],"someValueGt":[1,"some-value-gt"],"everyValueGt":[1,"every-value-gt"],"someValueGte":[1,"some-value-gte"],"everyValueGte":[1,"every-value-gte"],"someValueLt":[1,"some-value-lt"],"everyValueLt":[1,"every-value-lt"],"someValueLte":[1,"some-value-lte"],"everyValueLte":[1,"every-value-lte"],"active":[4],"error":[32],"getRule":[64]}]]],["pos-switch.cjs",[[257,"pos-switch",{"error":[32],"resource":[32],"cases":[32]}]]],["pos-value.cjs",[[1,"pos-value",{"predicate":[513],"resource":[32],"value":[32]},null,{"predicate":[{"observeAnyValue":0}]}]]],["pos-attachments.cjs",[[1,"pos-attachments",{"resource":[32],"attachments":[32],"addToList":[64]}]]],["pos-container-contents.cjs",[[1,"pos-container-contents",{"container":[32],"contents":[32],"loading":[32],"createNewItem":[32]},[[0,"keydown","handleKeyDown"]]]]],["pos-document.cjs",[[1,"pos-document",{"src":[1],"alt":[1],"os":[32],"file":[32],"brokenFile":[32],"error":[32],"saveStatus":[32],"loading":[32],"isEditable":[32]},[[0,"pod-os:document-modified","handleDocumentModified"]],{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}]]],["pos-add-new-thing_32.cjs",[[0,"pos-app-browser",{"restorePreviousSession":[4,"restore-previous-session"],"mode":[1],"uri":[32]}],[0,"pos-internal-router",{"uri":[1]}],[257,"pos-login",{"os":[32],"customLoggedInComponent":[32]},[[4,"pod-os:logout","logout"],[4,"pod-os:login","onLogin"]]],[1,"pos-navigation",{"uri":[1],"os":[32],"inputValue":[32],"searchIndex":[32],"suggestions":[32],"selectedIndex":[32],"resource":[32]},[[0,"pod-os:search:index-created","buildSearchIndex"],[0,"pod-os:search:index-updated","rebuildSearchIndex"],[0,"pod-os:navigate","openNavigationDialog"],[4,"click","closeDialog"],[0,"pod-os:link","clearSuggestions"],[0,"click","onClickSelf"],[0,"keydown","handleKeyDown"]],{"uri":[{"updateResource":0}],"os":[{"updateResource":0}]}],[1,"pos-user-menu",{"webId":[1,"web-id"]},[[0,"sl-select","onSelect"]]],[1,"pos-add-new-thing",{"referenceUri":[1,"reference-uri"]}],[1,"pos-type-router",{"initialTool":[32],"availableTools":[32],"oldTool":[32],"currentTool":[32],"transitioning":[32]},[[0,"pod-os:tool-selected","handleToolSelected"]]],[257,"pos-app",{"restorePreviousSession":[4,"restore-previous-session"],"os":[32],"unsubscribeSettings":[32],"loading":[32]},[[0,"pod-os:init","initializeOs"],[0,"pod-os:module","loadModule"]]],[257,"pos-error-toast",{"title":[32],"message":[32]},[[8,"unhandledrejection","unhandledRejection"],[0,"pod-os:error","catchError"]]],[260,"pos-router",{"mode":[1],"uri":[32]},[[0,"pod-os:link","linkClicked"],[8,"pod-os:session-restored","sessionRestored"]]],[1,"pos-app-dashboard"],[1,"pos-navigation-bar",{"current":[16],"searchIndexReady":[4,"search-index-ready"]},[[4,"keydown","activate"]]],[1,"pos-app-settings"],[17,"pos-new-thing-form",{"referenceUri":[1,"reference-uri"],"os":[32],"newUri":[32],"name":[32],"selectedTypeUri":[32],"canSubmit":[32]},null,{"name":[{"validate":0}],"selectedTypeUri":[{"validate":0}]}],[17,"pos-login-form",{"idpUrl":[32],"canSubmit":[32],"rememberMe":[32]},null,{"idpUrl":[{"validate":0}]}],[1,"pos-tool-select",{"selected":[16],"tools":[16]}],[1,"pos-type-index-entries",{"uri":[1],"entries":[32]}],[1,"pos-example-resources"],[1,"pos-make-findable",{"uri":[1],"os":[32],"thing":[32],"indexes":[32],"unsubscribeSessionChange":[32],"showOptions":[32],"isIndexed":[32]},[[0,"sl-select","onSelect"]],{"uri":[{"updateUri":0}]}],[260,"pos-dialog",{"showModal":[64],"close":[64]}],[1,"pos-getting-started"],[1,"pos-setting-offline-cache"],[1,"pos-share",{"uri":[1],"apps":[32],"os":[32]},[[4,"pod-os:resource-loaded","resourceLoaded"],[0,"sl-select","onSelect"]],{"uri":[{"updateApps":0}]}],[257,"pos-picture",{"blurredBackground":[4,"blurred-background"],"noUpload":[4,"no-upload"],"resource":[32],"os":[32],"isUploading":[32]}],[1,"pos-image",{"src":[1],"alt":[1],"blurredBackground":[4,"blurred-background"],"os":[32],"dataUri":[32],"brokenFile":[32],"networkError":[32],"imageError":[32],"loading":[32]},null,{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}],[1,"pos-upload",{"accept":[16],"uploader":[16]}],[1,"pos-predicate",{"uri":[1],"label":[1],"expanded":[32]}],[17,"pos-select-term",{"placeholder":[1],"value":[1],"os":[32],"terms":[32]},null,{"os":[{"setTerms":0}]}],[257,"pos-rich-link",{"uri":[1],"rel":[1],"rev":[1],"link":[32],"followPredicate":[32],"error":[32],"showCustomContent":[32]}],[1,"pos-description",{"description":[32]}],[1,"pos-label",{"label":[32]}],[257,"pos-resource",{"uri":[1],"lazy":[4],"os":[32],"resource":[32],"consumers":[32],"error":[32],"loading":[32],"fetch":[64]},[[0,"pod-os:resource","provideResource"]],{"os":[{"loadResource":0}],"uri":[{"loadResource":0}]}]]],["pos-
|
|
48
|
+
return index.bootstrapLazy([["pos-app-generic.cjs",[[1,"pos-app-generic"]]],["pos-app-ldp-container.cjs",[[1,"pos-app-ldp-container"]]],["pos-app-rdf-document.cjs",[[1,"pos-app-rdf-document"]]],["pos-app-image-viewer.cjs",[[1,"pos-app-image-viewer",{"resource":[32]}]]],["pos-tool-attachments.cjs",[[1,"pos-tool-attachments",{"os":[32],"resource":[32]}]]],["pos-app-document-viewer.cjs",[[1,"pos-app-document-viewer",{"resource":[32]}]]],["pos-list.cjs",[[0,"pos-list",{"rel":[1],"ifTypeof":[1,"if-typeof"],"fetch":[4],"error":[32],"os":[32],"resource":[32],"items":[32],"templateString":[32]}]]],["pos-case.cjs",[[0,"pos-case",{"ifTypeof":[1,"if-typeof"],"ifProperty":[1,"if-property"],"ifRev":[1,"if-rev"],"not":[4],"else":[4],"someValueEq":[1,"some-value-eq"],"everyValueEq":[1,"every-value-eq"],"someValueGt":[1,"some-value-gt"],"everyValueGt":[1,"every-value-gt"],"someValueGte":[1,"some-value-gte"],"everyValueGte":[1,"every-value-gte"],"someValueLt":[1,"some-value-lt"],"everyValueLt":[1,"every-value-lt"],"someValueLte":[1,"some-value-lte"],"everyValueLte":[1,"every-value-lte"],"active":[4],"error":[32],"getRule":[64]}]]],["pos-switch.cjs",[[257,"pos-switch",{"error":[32],"resource":[32],"cases":[32]}]]],["pos-value.cjs",[[1,"pos-value",{"predicate":[513],"resource":[32],"value":[32]},null,{"predicate":[{"observeAnyValue":0}]}]]],["pos-attachments.cjs",[[1,"pos-attachments",{"resource":[32],"attachments":[32],"addToList":[64]}]]],["pos-container-contents.cjs",[[1,"pos-container-contents",{"container":[32],"contents":[32],"loading":[32],"createNewItem":[32]},[[0,"keydown","handleKeyDown"]]]]],["pos-document.cjs",[[1,"pos-document",{"src":[1],"alt":[1],"os":[32],"file":[32],"brokenFile":[32],"error":[32],"saveStatus":[32],"loading":[32],"isEditable":[32]},[[0,"pod-os:document-modified","handleDocumentModified"]],{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}]]],["pos-add-new-thing_32.cjs",[[0,"pos-app-browser",{"restorePreviousSession":[4,"restore-previous-session"],"mode":[1],"uri":[32]}],[0,"pos-internal-router",{"uri":[1]}],[257,"pos-login",{"os":[32],"customLoggedInComponent":[32]},[[4,"pod-os:logout","logout"],[4,"pod-os:login","onLogin"]]],[1,"pos-navigation",{"uri":[1],"os":[32],"inputValue":[32],"searchIndex":[32],"suggestions":[32],"selectedIndex":[32],"resource":[32]},[[0,"pod-os:search:index-created","buildSearchIndex"],[0,"pod-os:search:index-updated","rebuildSearchIndex"],[0,"pod-os:navigate","openNavigationDialog"],[4,"click","closeDialog"],[0,"pod-os:link","clearSuggestions"],[0,"click","onClickSelf"],[0,"keydown","handleKeyDown"]],{"uri":[{"updateResource":0}],"os":[{"updateResource":0}]}],[1,"pos-user-menu",{"webId":[1,"web-id"]},[[0,"sl-select","onSelect"]]],[1,"pos-add-new-thing",{"referenceUri":[1,"reference-uri"]}],[1,"pos-type-router",{"initialTool":[32],"availableTools":[32],"oldTool":[32],"currentTool":[32],"transitioning":[32]},[[0,"pod-os:tool-selected","handleToolSelected"]]],[257,"pos-app",{"restorePreviousSession":[4,"restore-previous-session"],"os":[32],"unsubscribeSettings":[32],"loading":[32]},[[0,"pod-os:init","initializeOs"],[0,"pod-os:module","loadModule"]]],[257,"pos-error-toast",{"title":[32],"message":[32]},[[8,"unhandledrejection","unhandledRejection"],[0,"pod-os:error","catchError"]]],[260,"pos-router",{"mode":[1],"uri":[32]},[[0,"pod-os:link","linkClicked"],[8,"pod-os:session-restored","sessionRestored"]]],[1,"pos-app-dashboard"],[1,"pos-navigation-bar",{"current":[16],"searchIndexReady":[4,"search-index-ready"]},[[4,"keydown","activate"]]],[1,"pos-app-settings"],[17,"pos-new-thing-form",{"referenceUri":[1,"reference-uri"],"os":[32],"newUri":[32],"name":[32],"selectedTypeUri":[32],"canSubmit":[32]},null,{"name":[{"validate":0}],"selectedTypeUri":[{"validate":0}]}],[17,"pos-login-form",{"idpUrl":[32],"canSubmit":[32],"rememberMe":[32]},null,{"idpUrl":[{"validate":0}]}],[1,"pos-tool-select",{"selected":[16],"tools":[16]}],[1,"pos-type-index-entries",{"uri":[1],"entries":[32]}],[1,"pos-example-resources"],[1,"pos-make-findable",{"uri":[1],"os":[32],"thing":[32],"indexes":[32],"unsubscribeSessionChange":[32],"showOptions":[32],"isIndexed":[32]},[[0,"sl-select","onSelect"]],{"uri":[{"updateUri":0}]}],[260,"pos-dialog",{"showModal":[64],"close":[64]}],[1,"pos-getting-started"],[1,"pos-setting-offline-cache"],[1,"pos-share",{"uri":[1],"apps":[32],"os":[32]},[[4,"pod-os:resource-loaded","resourceLoaded"],[0,"sl-select","onSelect"]],{"uri":[{"updateApps":0}]}],[257,"pos-picture",{"blurredBackground":[4,"blurred-background"],"noUpload":[4,"no-upload"],"resource":[32],"os":[32],"isUploading":[32]}],[1,"pos-image",{"src":[1],"alt":[1],"blurredBackground":[4,"blurred-background"],"os":[32],"dataUri":[32],"brokenFile":[32],"networkError":[32],"imageError":[32],"loading":[32]},null,{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}],[1,"pos-upload",{"accept":[16],"uploader":[16]}],[1,"pos-predicate",{"uri":[1],"label":[1],"expanded":[32]}],[17,"pos-select-term",{"placeholder":[1],"value":[1],"os":[32],"terms":[32]},null,{"os":[{"setTerms":0}]}],[257,"pos-rich-link",{"uri":[1],"rel":[1],"rev":[1],"link":[32],"followPredicate":[32],"error":[32],"showCustomContent":[32]}],[1,"pos-description",{"description":[32]}],[1,"pos-label",{"label":[32]}],[257,"pos-resource",{"uri":[1],"lazy":[4],"os":[32],"resource":[32],"consumers":[32],"error":[32],"loading":[32],"fetch":[64]},[[0,"pod-os:resource","provideResource"]],{"os":[{"loadResource":0}],"uri":[{"loadResource":0}]}]]],["pos-subjects.cjs",[[1,"pos-subjects",{"data":[32]}]]],["pos-add-relation.cjs",[[1,"pos-add-relation",{"os":[32],"resource":[32],"selectedTermUri":[32],"currentValue":[32]}]]],["pos-relations_2.cjs",[[1,"pos-relations",{"data":[32]}],[1,"pos-reverse-relations",{"data":[32]}]]],["pos-markdown-document.cjs",[[1,"pos-markdown-document",{"file":[16],"saveStatus":[1,"save-status"],"editable":[4],"markdown":[32],"isModified":[32],"isEditing":[32],"startEditing":[64],"stopEditing":[64]}]]],["pos-container-item_3.cjs",[[257,"pos-container-item",{"resource":[32]}],[1,"pos-container-toolbar"],[1,"pos-create-new-container-item",{"type":[1],"container":[16],"os":[32],"name":[32]}]]],["pos-add-literal-value_3.cjs",[[1,"pos-literals",{"data":[32]}],[1,"pos-type-badges",{"data":[32],"typeLabels":[32],"isExpanded":[32]}],[1,"pos-add-literal-value",{"os":[32],"resource":[32],"currentValue":[32],"selectedTermUri":[32]},null,{"os":[{"setName":0}]}]]]], options);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
exports.setNonce = index.setNonce;
|
package/dist/cjs/loader.cjs.js
CHANGED
|
@@ -5,7 +5,7 @@ var index = require('./index-CjKppELa.js');
|
|
|
5
5
|
const defineCustomElements = async (win, options) => {
|
|
6
6
|
if (typeof window === 'undefined') return undefined;
|
|
7
7
|
await index.globalScripts();
|
|
8
|
-
return index.bootstrapLazy([["pos-app-generic.cjs",[[1,"pos-app-generic"]]],["pos-app-ldp-container.cjs",[[1,"pos-app-ldp-container"]]],["pos-app-rdf-document.cjs",[[1,"pos-app-rdf-document"]]],["pos-app-image-viewer.cjs",[[1,"pos-app-image-viewer",{"resource":[32]}]]],["pos-tool-attachments.cjs",[[1,"pos-tool-attachments",{"os":[32],"resource":[32]}]]],["pos-app-document-viewer.cjs",[[1,"pos-app-document-viewer",{"resource":[32]}]]],["pos-list.cjs",[[0,"pos-list",{"rel":[1],"ifTypeof":[1,"if-typeof"],"fetch":[4],"error":[32],"os":[32],"resource":[32],"items":[32],"templateString":[32]}]]],["pos-case.cjs",[[0,"pos-case",{"ifTypeof":[1,"if-typeof"],"ifProperty":[1,"if-property"],"ifRev":[1,"if-rev"],"not":[4],"else":[4],"someValueEq":[1,"some-value-eq"],"everyValueEq":[1,"every-value-eq"],"someValueGt":[1,"some-value-gt"],"everyValueGt":[1,"every-value-gt"],"someValueGte":[1,"some-value-gte"],"everyValueGte":[1,"every-value-gte"],"someValueLt":[1,"some-value-lt"],"everyValueLt":[1,"every-value-lt"],"someValueLte":[1,"some-value-lte"],"everyValueLte":[1,"every-value-lte"],"active":[4],"error":[32],"getRule":[64]}]]],["pos-switch.cjs",[[257,"pos-switch",{"error":[32],"resource":[32],"cases":[32]}]]],["pos-value.cjs",[[1,"pos-value",{"predicate":[513],"resource":[32],"value":[32]},null,{"predicate":[{"observeAnyValue":0}]}]]],["pos-attachments.cjs",[[1,"pos-attachments",{"resource":[32],"attachments":[32],"addToList":[64]}]]],["pos-container-contents.cjs",[[1,"pos-container-contents",{"container":[32],"contents":[32],"loading":[32],"createNewItem":[32]},[[0,"keydown","handleKeyDown"]]]]],["pos-document.cjs",[[1,"pos-document",{"src":[1],"alt":[1],"os":[32],"file":[32],"brokenFile":[32],"error":[32],"saveStatus":[32],"loading":[32],"isEditable":[32]},[[0,"pod-os:document-modified","handleDocumentModified"]],{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}]]],["pos-add-new-thing_32.cjs",[[0,"pos-app-browser",{"restorePreviousSession":[4,"restore-previous-session"],"mode":[1],"uri":[32]}],[0,"pos-internal-router",{"uri":[1]}],[257,"pos-login",{"os":[32],"customLoggedInComponent":[32]},[[4,"pod-os:logout","logout"],[4,"pod-os:login","onLogin"]]],[1,"pos-navigation",{"uri":[1],"os":[32],"inputValue":[32],"searchIndex":[32],"suggestions":[32],"selectedIndex":[32],"resource":[32]},[[0,"pod-os:search:index-created","buildSearchIndex"],[0,"pod-os:search:index-updated","rebuildSearchIndex"],[0,"pod-os:navigate","openNavigationDialog"],[4,"click","closeDialog"],[0,"pod-os:link","clearSuggestions"],[0,"click","onClickSelf"],[0,"keydown","handleKeyDown"]],{"uri":[{"updateResource":0}],"os":[{"updateResource":0}]}],[1,"pos-user-menu",{"webId":[1,"web-id"]},[[0,"sl-select","onSelect"]]],[1,"pos-add-new-thing",{"referenceUri":[1,"reference-uri"]}],[1,"pos-type-router",{"initialTool":[32],"availableTools":[32],"oldTool":[32],"currentTool":[32],"transitioning":[32]},[[0,"pod-os:tool-selected","handleToolSelected"]]],[257,"pos-app",{"restorePreviousSession":[4,"restore-previous-session"],"os":[32],"unsubscribeSettings":[32],"loading":[32]},[[0,"pod-os:init","initializeOs"],[0,"pod-os:module","loadModule"]]],[257,"pos-error-toast",{"title":[32],"message":[32]},[[8,"unhandledrejection","unhandledRejection"],[0,"pod-os:error","catchError"]]],[260,"pos-router",{"mode":[1],"uri":[32]},[[0,"pod-os:link","linkClicked"],[8,"pod-os:session-restored","sessionRestored"]]],[1,"pos-app-dashboard"],[1,"pos-navigation-bar",{"current":[16],"searchIndexReady":[4,"search-index-ready"]},[[4,"keydown","activate"]]],[1,"pos-app-settings"],[17,"pos-new-thing-form",{"referenceUri":[1,"reference-uri"],"os":[32],"newUri":[32],"name":[32],"selectedTypeUri":[32],"canSubmit":[32]},null,{"name":[{"validate":0}],"selectedTypeUri":[{"validate":0}]}],[17,"pos-login-form",{"idpUrl":[32],"canSubmit":[32],"rememberMe":[32]},null,{"idpUrl":[{"validate":0}]}],[1,"pos-tool-select",{"selected":[16],"tools":[16]}],[1,"pos-type-index-entries",{"uri":[1],"entries":[32]}],[1,"pos-example-resources"],[1,"pos-make-findable",{"uri":[1],"os":[32],"thing":[32],"indexes":[32],"unsubscribeSessionChange":[32],"showOptions":[32],"isIndexed":[32]},[[0,"sl-select","onSelect"]],{"uri":[{"updateUri":0}]}],[260,"pos-dialog",{"showModal":[64],"close":[64]}],[1,"pos-getting-started"],[1,"pos-setting-offline-cache"],[1,"pos-share",{"uri":[1],"apps":[32],"os":[32]},[[4,"pod-os:resource-loaded","resourceLoaded"],[0,"sl-select","onSelect"]],{"uri":[{"updateApps":0}]}],[257,"pos-picture",{"blurredBackground":[4,"blurred-background"],"noUpload":[4,"no-upload"],"resource":[32],"os":[32],"isUploading":[32]}],[1,"pos-image",{"src":[1],"alt":[1],"blurredBackground":[4,"blurred-background"],"os":[32],"dataUri":[32],"brokenFile":[32],"networkError":[32],"imageError":[32],"loading":[32]},null,{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}],[1,"pos-upload",{"accept":[16],"uploader":[16]}],[1,"pos-predicate",{"uri":[1],"label":[1],"expanded":[32]}],[17,"pos-select-term",{"placeholder":[1],"value":[1],"os":[32],"terms":[32]},null,{"os":[{"setTerms":0}]}],[257,"pos-rich-link",{"uri":[1],"rel":[1],"rev":[1],"link":[32],"followPredicate":[32],"error":[32],"showCustomContent":[32]}],[1,"pos-description",{"description":[32]}],[1,"pos-label",{"label":[32]}],[257,"pos-resource",{"uri":[1],"lazy":[4],"os":[32],"resource":[32],"consumers":[32],"error":[32],"loading":[32],"fetch":[64]},[[0,"pod-os:resource","provideResource"]],{"os":[{"loadResource":0}],"uri":[{"loadResource":0}]}]]],["pos-
|
|
8
|
+
return index.bootstrapLazy([["pos-app-generic.cjs",[[1,"pos-app-generic"]]],["pos-app-ldp-container.cjs",[[1,"pos-app-ldp-container"]]],["pos-app-rdf-document.cjs",[[1,"pos-app-rdf-document"]]],["pos-app-image-viewer.cjs",[[1,"pos-app-image-viewer",{"resource":[32]}]]],["pos-tool-attachments.cjs",[[1,"pos-tool-attachments",{"os":[32],"resource":[32]}]]],["pos-app-document-viewer.cjs",[[1,"pos-app-document-viewer",{"resource":[32]}]]],["pos-list.cjs",[[0,"pos-list",{"rel":[1],"ifTypeof":[1,"if-typeof"],"fetch":[4],"error":[32],"os":[32],"resource":[32],"items":[32],"templateString":[32]}]]],["pos-case.cjs",[[0,"pos-case",{"ifTypeof":[1,"if-typeof"],"ifProperty":[1,"if-property"],"ifRev":[1,"if-rev"],"not":[4],"else":[4],"someValueEq":[1,"some-value-eq"],"everyValueEq":[1,"every-value-eq"],"someValueGt":[1,"some-value-gt"],"everyValueGt":[1,"every-value-gt"],"someValueGte":[1,"some-value-gte"],"everyValueGte":[1,"every-value-gte"],"someValueLt":[1,"some-value-lt"],"everyValueLt":[1,"every-value-lt"],"someValueLte":[1,"some-value-lte"],"everyValueLte":[1,"every-value-lte"],"active":[4],"error":[32],"getRule":[64]}]]],["pos-switch.cjs",[[257,"pos-switch",{"error":[32],"resource":[32],"cases":[32]}]]],["pos-value.cjs",[[1,"pos-value",{"predicate":[513],"resource":[32],"value":[32]},null,{"predicate":[{"observeAnyValue":0}]}]]],["pos-attachments.cjs",[[1,"pos-attachments",{"resource":[32],"attachments":[32],"addToList":[64]}]]],["pos-container-contents.cjs",[[1,"pos-container-contents",{"container":[32],"contents":[32],"loading":[32],"createNewItem":[32]},[[0,"keydown","handleKeyDown"]]]]],["pos-document.cjs",[[1,"pos-document",{"src":[1],"alt":[1],"os":[32],"file":[32],"brokenFile":[32],"error":[32],"saveStatus":[32],"loading":[32],"isEditable":[32]},[[0,"pod-os:document-modified","handleDocumentModified"]],{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}]]],["pos-add-new-thing_32.cjs",[[0,"pos-app-browser",{"restorePreviousSession":[4,"restore-previous-session"],"mode":[1],"uri":[32]}],[0,"pos-internal-router",{"uri":[1]}],[257,"pos-login",{"os":[32],"customLoggedInComponent":[32]},[[4,"pod-os:logout","logout"],[4,"pod-os:login","onLogin"]]],[1,"pos-navigation",{"uri":[1],"os":[32],"inputValue":[32],"searchIndex":[32],"suggestions":[32],"selectedIndex":[32],"resource":[32]},[[0,"pod-os:search:index-created","buildSearchIndex"],[0,"pod-os:search:index-updated","rebuildSearchIndex"],[0,"pod-os:navigate","openNavigationDialog"],[4,"click","closeDialog"],[0,"pod-os:link","clearSuggestions"],[0,"click","onClickSelf"],[0,"keydown","handleKeyDown"]],{"uri":[{"updateResource":0}],"os":[{"updateResource":0}]}],[1,"pos-user-menu",{"webId":[1,"web-id"]},[[0,"sl-select","onSelect"]]],[1,"pos-add-new-thing",{"referenceUri":[1,"reference-uri"]}],[1,"pos-type-router",{"initialTool":[32],"availableTools":[32],"oldTool":[32],"currentTool":[32],"transitioning":[32]},[[0,"pod-os:tool-selected","handleToolSelected"]]],[257,"pos-app",{"restorePreviousSession":[4,"restore-previous-session"],"os":[32],"unsubscribeSettings":[32],"loading":[32]},[[0,"pod-os:init","initializeOs"],[0,"pod-os:module","loadModule"]]],[257,"pos-error-toast",{"title":[32],"message":[32]},[[8,"unhandledrejection","unhandledRejection"],[0,"pod-os:error","catchError"]]],[260,"pos-router",{"mode":[1],"uri":[32]},[[0,"pod-os:link","linkClicked"],[8,"pod-os:session-restored","sessionRestored"]]],[1,"pos-app-dashboard"],[1,"pos-navigation-bar",{"current":[16],"searchIndexReady":[4,"search-index-ready"]},[[4,"keydown","activate"]]],[1,"pos-app-settings"],[17,"pos-new-thing-form",{"referenceUri":[1,"reference-uri"],"os":[32],"newUri":[32],"name":[32],"selectedTypeUri":[32],"canSubmit":[32]},null,{"name":[{"validate":0}],"selectedTypeUri":[{"validate":0}]}],[17,"pos-login-form",{"idpUrl":[32],"canSubmit":[32],"rememberMe":[32]},null,{"idpUrl":[{"validate":0}]}],[1,"pos-tool-select",{"selected":[16],"tools":[16]}],[1,"pos-type-index-entries",{"uri":[1],"entries":[32]}],[1,"pos-example-resources"],[1,"pos-make-findable",{"uri":[1],"os":[32],"thing":[32],"indexes":[32],"unsubscribeSessionChange":[32],"showOptions":[32],"isIndexed":[32]},[[0,"sl-select","onSelect"]],{"uri":[{"updateUri":0}]}],[260,"pos-dialog",{"showModal":[64],"close":[64]}],[1,"pos-getting-started"],[1,"pos-setting-offline-cache"],[1,"pos-share",{"uri":[1],"apps":[32],"os":[32]},[[4,"pod-os:resource-loaded","resourceLoaded"],[0,"sl-select","onSelect"]],{"uri":[{"updateApps":0}]}],[257,"pos-picture",{"blurredBackground":[4,"blurred-background"],"noUpload":[4,"no-upload"],"resource":[32],"os":[32],"isUploading":[32]}],[1,"pos-image",{"src":[1],"alt":[1],"blurredBackground":[4,"blurred-background"],"os":[32],"dataUri":[32],"brokenFile":[32],"networkError":[32],"imageError":[32],"loading":[32]},null,{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}],[1,"pos-upload",{"accept":[16],"uploader":[16]}],[1,"pos-predicate",{"uri":[1],"label":[1],"expanded":[32]}],[17,"pos-select-term",{"placeholder":[1],"value":[1],"os":[32],"terms":[32]},null,{"os":[{"setTerms":0}]}],[257,"pos-rich-link",{"uri":[1],"rel":[1],"rev":[1],"link":[32],"followPredicate":[32],"error":[32],"showCustomContent":[32]}],[1,"pos-description",{"description":[32]}],[1,"pos-label",{"label":[32]}],[257,"pos-resource",{"uri":[1],"lazy":[4],"os":[32],"resource":[32],"consumers":[32],"error":[32],"loading":[32],"fetch":[64]},[[0,"pod-os:resource","provideResource"]],{"os":[{"loadResource":0}],"uri":[{"loadResource":0}]}]]],["pos-subjects.cjs",[[1,"pos-subjects",{"data":[32]}]]],["pos-add-relation.cjs",[[1,"pos-add-relation",{"os":[32],"resource":[32],"selectedTermUri":[32],"currentValue":[32]}]]],["pos-relations_2.cjs",[[1,"pos-relations",{"data":[32]}],[1,"pos-reverse-relations",{"data":[32]}]]],["pos-markdown-document.cjs",[[1,"pos-markdown-document",{"file":[16],"saveStatus":[1,"save-status"],"editable":[4],"markdown":[32],"isModified":[32],"isEditing":[32],"startEditing":[64],"stopEditing":[64]}]]],["pos-container-item_3.cjs",[[257,"pos-container-item",{"resource":[32]}],[1,"pos-container-toolbar"],[1,"pos-create-new-container-item",{"type":[1],"container":[16],"os":[32],"name":[32]}]]],["pos-add-literal-value_3.cjs",[[1,"pos-literals",{"data":[32]}],[1,"pos-type-badges",{"data":[32],"typeLabels":[32],"isExpanded":[32]}],[1,"pos-add-literal-value",{"os":[32],"resource":[32],"currentValue":[32],"selectedTermUri":[32]},null,{"os":[{"setName":0}]}]]]], options);
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
exports.setNonce = index.setNonce;
|
|
@@ -92,7 +92,7 @@ const PosCase = class {
|
|
|
92
92
|
// unset it here to not leave state in the dom
|
|
93
93
|
return index.h(index.Host, { innerHTML: "" });
|
|
94
94
|
}
|
|
95
|
-
return index.h(index.Host, { innerHTML: this.templateHTML });
|
|
95
|
+
return index.h(index.Host, { style: { display: 'contents' }, innerHTML: this.templateHTML });
|
|
96
96
|
}
|
|
97
97
|
get host() { return index.getElement(this); }
|
|
98
98
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"pos-case.cjs.entry.js","mappings":";;;;AA4FO,MAAM,UAAU,GAAc;AACnC,IAAA,IAAI,EAAE,OAAO;AACb,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,IAAI,EAAE,KAAK;CACZ;AAEM,MAAM,SAAS,GAAa;AACjC,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,IAAI,EAAE,IAAI;CACX;;ACtGD,MAAM,UAAU,GAAG,MAAM,CAAC,8JAA8J,CAAC;;MCY5K,OAAO,GAAA,MAAA;AALpB,IAAA,WAAA,CAAA,OAAA,EAAA;;AAOW,QAAA,IAAA,CAAA,KAAK,GAAkB,IAAI;AAC5B,QAAA,IAAA,CAAA,YAAY,GAAkB,IAAI;AAqF1C;;AAEG;AACK,QAAA,IAAA,CAAA,MAAM,GAAG,KAAK;AA8EvB;IAvGC,mBAAmB,GAAA;AACjB,QAAA,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,SAAS,CAAC,CAAC,MAAM;AACrG,QAAA,IAAI,UAAU,GAAG,CAAC,EAAE;AAClB,YAAA,IAAI,CAAC,KAAK,GAAG,iCAAiC;;AAEhD,QAAA,MAAM,gBAAgB,GAAG;AACvB,YAAA,IAAI,CAAC,WAAW;AAChB,YAAA,IAAI,CAAC,YAAY;AACjB,YAAA,IAAI,CAAC,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,CAAC,MAAA,IAAA,IAAA,EAAA,KAAA,MAAA,GAAA,EAAA,GACpD,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC;;AAIlD,IAAA,aAAa,CAAC,MAA0B,EAAE,QAAkB,EAAE,QAAkB,EAAA;QACtF,IAAI,MAAM,EAAE;AACV,YAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE;;;IAIzC,iBAAiB,GAAA;QACf,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC;AAC3D,QAAA,IAAI,eAAe,IAAI,IAAI,EAAE;AAC3B,YAAA,IAAI,CAAC,KAAK,GAAG,2BAA2B;;aACnC;AACL,YAAA,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC,SAAS;;;IAIjD,MAAM,GAAA;QACJ,IAAI,IAAI,CAAC,KAAK;AAAE,YAAA,OAAOA,OAAA,CAAA,KAAA,EAAA,EAAK,KAAK,EAAC,OAAO,IAAE,IAAI,CAAC,KAAK,CAAO;AAE5D,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;;;YAGhB,OAAOA,QAACC,UAAI,EAAA,EAAC,SAAS,EAAC,EAAE,GAAQ;;AAEnC,QAAA,OAAOD,OAAA,CAACC,UAAI,EAAA,EAAC,SAAS,EAAE,IAAI,CAAC,YAAY,EAAA,CAAS;;;;;;;;","names":["h","Host"],"sources":["src/components/pos-switch/rules/index.ts","src/components/pos-switch/pos-case/pos-case.css?tag=pos-case","src/components/pos-switch/pos-case/pos-case.tsx"],"sourcesContent":["import { Literal, RdfType, Relation } from '@pod-os/core';\n\nexport { findMatchingRules } from './findMatchingRules';\n\n/**\n * A rule that matches if the resource is of a specific type\n */\nexport interface IfTypeofRule {\n type: 'if-typeof';\n /**\n * The URI of the type to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource is not of the specified type)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n}\n\n/**\n * A rule that matches if the resource has a specific property (literal or relation)\n */\nexport interface IfPropertyRule {\n type: 'if-property';\n /**\n * The value of the property to match against (either literal value or the URI of a relation)\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified property)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the value of the property matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that matches if the resource has a specific reverse relation\n */\nexport interface IfRevRule {\n type: 'if-rev';\n /**\n * The URI of the reverse relation to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified reverse relation)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the URI of the reverse relation matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that only matches if all others did not\n */\nexport interface ElseRule {\n type: 'else';\n not: false;\n else: true;\n}\n\n/**\n * A rule that never matches\n */\nexport interface NeverRule {\n type: 'never';\n not: false;\n else: false;\n}\n\n/**\n * A rule defined by a pos-case\n */\nexport type SwitchCaseRule = IfTypeofRule | IfPropertyRule | IfRevRule | ElseRule | NeverRule;\n\nexport const NEVER_RULE: NeverRule = {\n type: 'never',\n not: false,\n else: false,\n};\n\nexport const ELSE_RULE: ElseRule = {\n type: 'else',\n not: false,\n else: true,\n};\n\n/**\n * Contains the actual data a rule is matched against\n */\nexport interface RuleContext {\n types: RdfType[];\n literals: Literal[];\n relations: Relation[];\n reverseRelations: Relation[];\n}\n\n/**\n * Defines how to compare values to a specific target value\n */\nexport interface Comparison {\n /**\n * Does every value need to match, or only some?\n */\n semantic: Semantic;\n /**\n * The comparison operator to apply (e.g. value must be equal, greater than, etc.)\n */\n operator: Operator;\n /**\n * The target value to compare against.\n */\n target: string;\n}\n\nexport type equals = 'eq';\nexport type greaterThan = 'gt';\nexport type greaterThanOrEqual = 'gte';\nexport type lessThan = 'lt';\nexport type lessThanOrEqual = 'lte';\nexport type some = 'some';\nexport type every = 'every';\nexport type Operator = equals | greaterThan | greaterThanOrEqual | lessThan | lessThanOrEqual;\nexport type Semantic = some | every;\n",".error {\n background-color: var(--pos-error-background-color);\n border: 1px solid var(--pos-error-border-color);\n padding: var(--size-3);\n border-radius: var(--radius-md);\n}\n","import { Component, Element, h, Host, Method, Prop, State } from '@stencil/core';\nimport { Comparison, ELSE_RULE, NEVER_RULE, Operator, Semantic, SwitchCaseRule } from '../rules';\n\n/**\n * Defines a template to use if the specified condition is met - to be used with [pos-switch](https://pod-os.org/reference/elements/components/pos-switch/).\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n */\n@Component({\n tag: 'pos-case',\n shadow: false,\n styleUrl: 'pos-case.css',\n})\nexport class PosCase {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n private templateHTML: string | null = null;\n\n /**\n * Test if the resource is of the specified type\n */\n @Prop() ifTypeof?: string;\n /**\n * Test if the resource has the specified property (forward link)\n */\n @Prop() ifProperty?: string;\n /**\n * Test if the resource is the subject of the specified property (backward link)\n */\n @Prop() ifRev?: string;\n /**\n * Negates the result of the test\n */\n @Prop() not?: boolean;\n /**\n * The test only evaluates to true if tests for preceding cases have failed\n */\n @Prop() else?: boolean;\n /**\n * Test if some value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() someValueEq?: string;\n /**\n * Test if every value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() everyValueEq?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGt?: string;\n /**\n * Test if some value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGte?: string;\n /**\n * Test if every value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGte?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLt?: string;\n /**\n * Test if some value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLte?: string;\n /**\n * Test if every value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLte?: string;\n\n componentWillRender() {\n const countRules = [this.ifTypeof, this.ifProperty, this.ifRev].filter(it => it !== undefined).length;\n if (countRules > 1) {\n this.error = 'At most 1 \"if-\" must be present';\n }\n const countComparisons = [\n this.someValueLt,\n this.everyValueLt,\n this.someValueLte,\n this.everyValueLte,\n this.someValueEq,\n this.everyValueEq,\n this.someValueGte,\n this.everyValueGte,\n this.someValueGt,\n this.everyValueGt,\n ].filter(it => it !== undefined).length;\n if (countComparisons > 1) {\n this.error = 'At most 1 comparison (\"every-\" / \"some-\") must be present';\n }\n }\n\n /**\n * Whether this case is active, i.e. shown. Usually this is controlled by the surrounding pos-switch, and there is no need to set this manually.\n */\n @Prop() active = false;\n\n /**\n * Returns the rule definition for this case. The rule determines if the element's content gets rendered.\n */\n @Method()\n async getRule(): Promise<SwitchCaseRule> {\n const modifiers = {\n not: this.not,\n else: this.else,\n };\n const comparison = this.getComparison();\n if (this.ifTypeof) {\n return {\n type: 'if-typeof',\n value: this.ifTypeof,\n ...modifiers,\n };\n }\n if (this.ifProperty) {\n return {\n type: 'if-property',\n value: this.ifProperty,\n ...modifiers,\n comparison,\n };\n }\n if (this.ifRev) {\n return {\n type: 'if-rev',\n value: this.ifRev,\n ...modifiers,\n comparison,\n };\n }\n return this.else ? ELSE_RULE : NEVER_RULE;\n }\n\n private getComparison(): Comparison | undefined {\n return (\n this.comparisonFor(this.someValueEq, 'some', 'eq') ??\n this.comparisonFor(this.everyValueEq, 'every', 'eq') ??\n this.comparisonFor(this.someValueGt, 'some', 'gt') ??\n this.comparisonFor(this.everyValueGt, 'every', 'gt') ??\n this.comparisonFor(this.someValueGte, 'some', 'gte') ??\n this.comparisonFor(this.everyValueGte, 'every', 'gte') ??\n this.comparisonFor(this.someValueLt, 'some', 'lt') ??\n this.comparisonFor(this.everyValueLt, 'every', 'lt') ??\n this.comparisonFor(this.someValueLte, 'some', 'lte') ??\n this.comparisonFor(this.everyValueLte, 'every', 'lte')\n );\n }\n\n private comparisonFor(target: string | undefined, semantic: Semantic, operator: Operator): Comparison | undefined {\n if (target) {\n return { semantic, operator, target };\n }\n }\n\n componentWillLoad() {\n const templateElement = this.host.querySelector('template');\n if (templateElement == null) {\n this.error = 'No template element found';\n } else {\n this.templateHTML = templateElement.innerHTML;\n }\n }\n\n render() {\n if (this.error) return <div class=\"error\">{this.error}</div>;\n\n if (!this.active) {\n // because we set innerHTML for active case elements, we need to\n // unset it here to not leave state in the dom\n return <Host innerHTML=\"\"></Host>;\n }\n return <Host innerHTML={this.templateHTML}></Host>;\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"pos-case.cjs.entry.js","mappings":";;;;AA4FO,MAAM,UAAU,GAAc;AACnC,IAAA,IAAI,EAAE,OAAO;AACb,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,IAAI,EAAE,KAAK;CACZ;AAEM,MAAM,SAAS,GAAa;AACjC,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,IAAI,EAAE,IAAI;CACX;;ACtGD,MAAM,UAAU,GAAG,MAAM,CAAC,8JAA8J,CAAC;;MCY5K,OAAO,GAAA,MAAA;AALpB,IAAA,WAAA,CAAA,OAAA,EAAA;;AAOW,QAAA,IAAA,CAAA,KAAK,GAAkB,IAAI;AAC5B,QAAA,IAAA,CAAA,YAAY,GAAkB,IAAI;AAqF1C;;AAEG;AACK,QAAA,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Q;;QAEnC,OAAOD,QAACC,UAAI,EAAA,EAAC,KAAK,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,YAAY,GAAS;;;;;;;;","names":["h","Host"],"sources":["src/components/pos-switch/rules/index.ts","src/components/pos-switch/pos-case/pos-case.css?tag=pos-case","src/components/pos-switch/pos-case/pos-case.tsx"],"sourcesContent":["import { Literal, RdfType, Relation } from '@pod-os/core';\n\nexport { findMatchingRules } from './findMatchingRules';\n\n/**\n * A rule that matches if the resource is of a specific type\n */\nexport interface IfTypeofRule {\n type: 'if-typeof';\n /**\n * The URI of the type to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource is not of the specified type)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n}\n\n/**\n * A rule that matches if the resource has a specific property (literal or relation)\n */\nexport interface IfPropertyRule {\n type: 'if-property';\n /**\n * The value of the property to match against (either literal value or the URI of a relation)\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified property)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the value of the property matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that matches if the resource has a specific reverse relation\n */\nexport interface IfRevRule {\n type: 'if-rev';\n /**\n * The URI of the reverse relation to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified reverse relation)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the URI of the reverse relation matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that only matches if all others did not\n */\nexport interface ElseRule {\n type: 'else';\n not: false;\n else: true;\n}\n\n/**\n * A rule that never matches\n */\nexport interface NeverRule {\n type: 'never';\n not: false;\n else: false;\n}\n\n/**\n * A rule defined by a pos-case\n */\nexport type SwitchCaseRule = IfTypeofRule | IfPropertyRule | IfRevRule | ElseRule | NeverRule;\n\nexport const NEVER_RULE: NeverRule = {\n type: 'never',\n not: false,\n else: false,\n};\n\nexport const ELSE_RULE: ElseRule = {\n type: 'else',\n not: false,\n else: true,\n};\n\n/**\n * Contains the actual data a rule is matched against\n */\nexport interface RuleContext {\n types: RdfType[];\n literals: Literal[];\n relations: Relation[];\n reverseRelations: Relation[];\n}\n\n/**\n * Defines how to compare values to a specific target value\n */\nexport interface Comparison {\n /**\n * Does every value need to match, or only some?\n */\n semantic: Semantic;\n /**\n * The comparison operator to apply (e.g. value must be equal, greater than, etc.)\n */\n operator: Operator;\n /**\n * The target value to compare against.\n */\n target: string;\n}\n\nexport type equals = 'eq';\nexport type greaterThan = 'gt';\nexport type greaterThanOrEqual = 'gte';\nexport type lessThan = 'lt';\nexport type lessThanOrEqual = 'lte';\nexport type some = 'some';\nexport type every = 'every';\nexport type Operator = equals | greaterThan | greaterThanOrEqual | lessThan | lessThanOrEqual;\nexport type Semantic = some | every;\n",".error {\n background-color: var(--pos-error-background-color);\n border: 1px solid var(--pos-error-border-color);\n padding: var(--size-3);\n border-radius: var(--radius-md);\n}\n","import { Component, Element, h, Host, Method, Prop, State } from '@stencil/core';\nimport { Comparison, ELSE_RULE, NEVER_RULE, Operator, Semantic, SwitchCaseRule } from '../rules';\n\n/**\n * Defines a template to use if the specified condition is met - to be used with [pos-switch](https://pod-os.org/reference/elements/components/pos-switch/).\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n */\n@Component({\n tag: 'pos-case',\n shadow: false,\n styleUrl: 'pos-case.css',\n})\nexport class PosCase {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n private templateHTML: string | null = null;\n\n /**\n * Test if the resource is of the specified type\n */\n @Prop() ifTypeof?: string;\n /**\n * Test if the resource has the specified property (forward link)\n */\n @Prop() ifProperty?: string;\n /**\n * Test if the resource is the subject of the specified property (backward link)\n */\n @Prop() ifRev?: string;\n /**\n * Negates the result of the test\n */\n @Prop() not?: boolean;\n /**\n * The test only evaluates to true if tests for preceding cases have failed\n */\n @Prop() else?: boolean;\n /**\n * Test if some value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() someValueEq?: string;\n /**\n * Test if every value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() everyValueEq?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGt?: string;\n /**\n * Test if some value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGte?: string;\n /**\n * Test if every value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGte?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLt?: string;\n /**\n * Test if some value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLte?: string;\n /**\n * Test if every value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLte?: string;\n\n componentWillRender() {\n const countRules = [this.ifTypeof, this.ifProperty, this.ifRev].filter(it => it !== undefined).length;\n if (countRules > 1) {\n this.error = 'At most 1 \"if-\" must be present';\n }\n const countComparisons = [\n this.someValueLt,\n this.everyValueLt,\n this.someValueLte,\n this.everyValueLte,\n this.someValueEq,\n this.everyValueEq,\n this.someValueGte,\n this.everyValueGte,\n this.someValueGt,\n this.everyValueGt,\n ].filter(it => it !== undefined).length;\n if (countComparisons > 1) {\n this.error = 'At most 1 comparison (\"every-\" / \"some-\") must be present';\n }\n }\n\n /**\n * Whether this case is active, i.e. shown. Usually this is controlled by the surrounding pos-switch, and there is no need to set this manually.\n */\n @Prop() active = false;\n\n /**\n * Returns the rule definition for this case. The rule determines if the element's content gets rendered.\n */\n @Method()\n async getRule(): Promise<SwitchCaseRule> {\n const modifiers = {\n not: this.not,\n else: this.else,\n };\n const comparison = this.getComparison();\n if (this.ifTypeof) {\n return {\n type: 'if-typeof',\n value: this.ifTypeof,\n ...modifiers,\n };\n }\n if (this.ifProperty) {\n return {\n type: 'if-property',\n value: this.ifProperty,\n ...modifiers,\n comparison,\n };\n }\n if (this.ifRev) {\n return {\n type: 'if-rev',\n value: this.ifRev,\n ...modifiers,\n comparison,\n };\n }\n return this.else ? ELSE_RULE : NEVER_RULE;\n }\n\n private getComparison(): Comparison | undefined {\n return (\n this.comparisonFor(this.someValueEq, 'some', 'eq') ??\n this.comparisonFor(this.everyValueEq, 'every', 'eq') ??\n this.comparisonFor(this.someValueGt, 'some', 'gt') ??\n this.comparisonFor(this.everyValueGt, 'every', 'gt') ??\n this.comparisonFor(this.someValueGte, 'some', 'gte') ??\n this.comparisonFor(this.everyValueGte, 'every', 'gte') ??\n this.comparisonFor(this.someValueLt, 'some', 'lt') ??\n this.comparisonFor(this.everyValueLt, 'every', 'lt') ??\n this.comparisonFor(this.someValueLte, 'some', 'lte') ??\n this.comparisonFor(this.everyValueLte, 'every', 'lte')\n );\n }\n\n private comparisonFor(target: string | undefined, semantic: Semantic, operator: Operator): Comparison | undefined {\n if (target) {\n return { semantic, operator, target };\n }\n }\n\n componentWillLoad() {\n const templateElement = this.host.querySelector('template');\n if (templateElement == null) {\n this.error = 'No template element found';\n } else {\n this.templateHTML = templateElement.innerHTML;\n }\n }\n\n render() {\n if (this.error) return <div class=\"error\">{this.error}</div>;\n\n if (!this.active) {\n // because we set innerHTML for active case elements, we need to\n // unset it here to not leave state in the dom\n return <Host innerHTML=\"\"></Host>;\n }\n return <Host style={{ display: 'contents' }} innerHTML={this.templateHTML}></Host>;\n }\n}\n"],"version":3}
|
|
@@ -109,6 +109,8 @@ function findMatchingRules(cases, context) {
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
const posSwitchCss = () => `:host{display:contents}`;
|
|
113
|
+
|
|
112
114
|
const PosSwitch = class {
|
|
113
115
|
constructor(hostRef) {
|
|
114
116
|
index.registerInstance(this, hostRef);
|
|
@@ -180,6 +182,7 @@ const PosSwitch = class {
|
|
|
180
182
|
}
|
|
181
183
|
get host() { return index.getElement(this); }
|
|
182
184
|
};
|
|
185
|
+
PosSwitch.style = posSwitchCss();
|
|
183
186
|
|
|
184
187
|
exports.pos_switch = PosSwitch;
|
|
185
188
|
//# sourceMappingURL=pos-switch.entry.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"pos-switch.cjs.entry.js","mappings":";;;;;;AAEA;;;;AAIG;AACG,SAAU,aAAa,CAAC,MAAgB,EAAE,UAAsB,EAAA;IACpE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAU;IACjD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,IAAG;AAC/B,QAAA,IAAI,GAAG;AACP,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC;AAC1B,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;AAChC,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;AACrD,YAAA,GAAG,GAAG,MAAM,GAAG,SAAS;;aACnB;AACL,YAAA,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;;QAEjD,QAAQ,QAAQ;AACd,YAAA,KAAK,IAAI;gBACP,OAAO,GAAG,KAAK,CAAC;AAClB,YAAA,KAAK,IAAI;gBACP,OAAO,GAAG,GAAG,CAAC;AAChB,YAAA,KAAK,KAAK;gBACR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M,EAAE,CAAC,OAAO,EAAE;AACxB,YAAA,WAAW,EAAE,EAAE;AAChB,SAAA,CAAC,CAAC,CACJ,CAAC,IAAI,CAAC,KAAK,IAAG;AACb,YAAA,IAAI,CAAC,KAAK,GAAG,KAAK;YAClBC,+BAAiB,CAAC,IAAI,CAAC;AACzB,SAAC,CAAC;;AAmCI,IAAA,YAAY,CAAC,IAA4B,EAAA;AAC/C,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;;IAGrD,MAAM,GAAA;AACJ,QAAA,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,OAAO,IAAI,CAAC,KAAK;;AAEnB,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AAClB,YAAA,OAAO,IAAI;;AAGb,QAAA,OAAOC,qBAAa;;IAGtB,oBAAoB,GAAA;AAClB,QAAA,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE;AACzB,QAAA,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;;;;;;;","names":["Subject","combineLatest","of","map","takeUntil","subscribeResource","h"],"sources":["src/components/pos-switch/rules/doValuesMatch.ts","src/components/pos-switch/rules/doesRuleMatch.ts","src/components/pos-switch/rules/findMatchingRules.ts","src/components/pos-switch/pos-switch.tsx"],"sourcesContent":["import { Comparison } from './index';\n\n/**\n * Checks whether the given values match the given target according to the given comparison\n * @param values\n * @param comparison\n */\nexport function doValuesMatch(values: string[], comparison: Comparison): boolean {\n const { operator, semantic, target } = comparison;\n const matches = values.map(val => {\n let cmp;\n const numVal = Number(val);\n const numTarget = Number(target);\n if (!Number.isNaN(numVal) && !Number.isNaN(numTarget)) {\n cmp = numVal - numTarget;\n } else {\n cmp = String(val).localeCompare(String(target));\n }\n switch (operator) {\n case 'eq':\n return cmp === 0;\n case 'gt':\n return cmp > 0;\n case 'gte':\n return cmp >= 0;\n case 'lt':\n return cmp < 0;\n case 'lte':\n return cmp <= 0;\n }\n });\n if (semantic == 'some') {\n return matches.some(Boolean);\n } else if (semantic == 'every') {\n return matches.every(Boolean);\n } else {\n throw new Error(`Unknown semantic: ${semantic}`);\n }\n}\n","import { IfPropertyRule, IfRevRule, IfTypeofRule, RuleContext, SwitchCaseRule } from './index';\n\nimport { doValuesMatch } from './doValuesMatch';\n\nexport function doesRuleMatch(rule: SwitchCaseRule, context: RuleContext) {\n const ruleResult = evaluateRule(rule, context);\n return rule.not ? !ruleResult : ruleResult;\n}\n\nfunction evaluateRule(rule: SwitchCaseRule, context: RuleContext) {\n switch (rule.type) {\n case 'if-typeof':\n return doesTypeMatch(rule, context);\n case 'if-property':\n return doesPropertyMatch(rule, context);\n case 'if-rev':\n return doesReverseRelationMatch(rule, context);\n case 'else':\n return true;\n default:\n return false;\n }\n}\n\nfunction doesTypeMatch(rule: IfTypeofRule, context: RuleContext) {\n return context.types.map(x => x.uri).includes(rule.value);\n}\n\nfunction doesPropertyMatch(rule: IfPropertyRule, context: RuleContext) {\n const matchingLiteral = context.literals.find(it => it.predicate == rule.value);\n const matchingRelation = context.relations.find(it => it.predicate == rule.value);\n if (rule.comparison && (matchingLiteral || matchingRelation)) {\n return doValuesMatch([...(matchingLiteral?.values ?? []), ...(matchingRelation?.uris ?? [])], rule.comparison);\n }\n return matchingLiteral !== undefined || matchingRelation !== undefined;\n}\n\nfunction doesReverseRelationMatch(rule: IfRevRule, context: RuleContext) {\n const matchingRev = context.reverseRelations.find(x => x.predicate == rule.value);\n if (rule.comparison && matchingRev) {\n return doValuesMatch(matchingRev.uris, rule.comparison);\n }\n return matchingRev !== undefined;\n}\n","import { RuleContext, SwitchCaseRule } from './index';\nimport { doesRuleMatch } from './doesRuleMatch';\n\nexport function findMatchingRules<T extends { rule: SwitchCaseRule }>(cases: T[], context: RuleContext) {\n /**\n * scope of if-else statements\n * each plain if (without else) increases the scope by 1\n * else branches are ignored if we already found a match in the current scope\n */\n let scope = 0;\n /**\n * scope of the previous rule that matched\n */\n let previousRuleMatched = -1;\n return cases.filter(it => {\n if (it.rule.else && previousRuleMatched == scope) {\n return false; // else branches are ignored if we already found a match in the current scope\n }\n if (!it.rule.else) {\n scope++; // plain if rule -> new scope\n }\n const match = doesRuleMatch(it.rule, context);\n if (match) {\n previousRuleMatched = scope; // found a match in the current if-else scope\n }\n return match;\n });\n}\n","import { Thing } from '@pod-os/core';\nimport { Component, Element, Event, h, State } from '@stencil/core';\nimport { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware';\nimport { combineLatest, map, of, Subject, takeUntil } from 'rxjs';\nimport { findMatchingRules, RuleContext, SwitchCaseRule } from './rules';\n\ninterface CaseWithRule {\n caseElement: HTMLPosCaseElement;\n rule: SwitchCaseRule;\n}\n\n/**\n * Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n * See [pos-case](https://pod-os.org/reference/elements/components/pos-switch/pos-case/) for available filter conditions.\n */\n@Component({\n tag: 'pos-switch',\n shadow: true,\n})\nexport class PosSwitch implements ResourceAware {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n @State() resource?: Thing;\n @State() cases: CaseWithRule[] = [];\n\n private readonly disconnected$ = new Subject<void>();\n\n @Event({ eventName: 'pod-os:resource' })\n subscribeResource!: ResourceEventEmitter;\n\n componentWillLoad() {\n const caseElements = Array.from(this.host.querySelectorAll('pos-case'));\n if (caseElements.length == 0) {\n this.error = 'No pos-case elements found';\n return;\n }\n // Do NOT await: awaiting a child @Method in componentWillLoad deadlocks the\n // lazy load graph (the child can't render until this component renders).\n // Build the rules once the children have upgraded, then subscribe to the resource\n Promise.all(\n caseElements.map(async it => ({\n rule: await it.getRule(),\n caseElement: it,\n })),\n ).then(cases => {\n this.cases = cases;\n subscribeResource(this);\n });\n }\n\n receiveResource = (resource: Thing) => {\n // reset any existing resource\n this.disconnected$.next();\n this.resource = resource;\n\n combineLatest([\n this.containsRule('if-typeof') ? resource.observeTypes() : of([]),\n this.containsRule('if-property') ? resource.observeLiterals() : of([]),\n this.containsRule('if-property') ? resource.observeRelations() : of([]),\n this.containsRule('if-rev') ? resource.observeReverseRelations() : of([]),\n ])\n .pipe(\n map(([types, literals, relations, reverseRelations]) => ({\n types,\n literals,\n relations,\n reverseRelations,\n })),\n takeUntil(this.disconnected$),\n )\n .subscribe((context: RuleContext) => {\n const activeElements = new Set(findMatchingRules(this.cases, context).map(it => it.caseElement));\n this.cases.forEach(it => {\n if (activeElements.has(it.caseElement)) {\n it.caseElement.setAttribute('active', '');\n } else {\n it.caseElement.removeAttribute('active');\n }\n });\n });\n };\n\n private containsRule(type: SwitchCaseRule['type']) {\n return this.cases.some(it => it.rule.type === type);\n }\n\n render() {\n if (this.error) {\n return this.error;\n }\n if (!this.resource) {\n return null;\n }\n\n return <slot></slot>;\n }\n\n disconnectedCallback() {\n this.disconnected$.next();\n this.disconnected$.complete();\n }\n}\n"],"version":3}
|
|
1
|
+
{"file":"pos-switch.cjs.entry.js","mappings":";;;;;;AAEA;;;;AAIG;AACG,SAAU,aAAa,CAAC,MAAgB,EAAE,UAAsB,EAAA;IACpE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAU;IACjD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,IAAG;AAC/B,QAAA,IAAI,GAAG;AACP,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC;AAC1B,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;AAChC,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;AACrD,YAAA,GAAG,GAAG,MAAM,GAAG,SAAS;;aACnB;AACL,YAAA,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,M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,CAAC,UAAU,CAAC,CAAC;AACvE,QAAA,IAAI,YAAY,CAAC,MAAM,IAAI,CAAC,EAAE;AAC5B,YAAA,IAAI,CAAC,KAAK,GAAG,4BAA4B;YACzC;;;;;AAKF,QAAA,OAAO,CAAC,GAAG,CACT,YAAY,CAAC,GAAG,CAAC,OAAM,EAAE,MAAK;AAC5B,YAAA,IAAI,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE;AACxB,YAAA,WAAW,EAAE,EAAE;AAChB,SAAA,CAAC,CAAC,CACJ,CAAC,IAAI,CAAC,KAAK,IAAG;AACb,YAAA,IAAI,CAAC,KAAK,GAAG,KAAK;YAClBC,+BAAiB,CAAC,IAAI,CAAC;AACzB,SAAC,CAAC;;AAmCI,IAAA,YAAY,CAAC,IAA4B,EAAA;AAC/C,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;;IAGrD,MAAM,GAAA;AACJ,QAAA,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,OAAO,IAAI,CAAC,KAAK;;AAEnB,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AAClB,YAAA,OAAO,IAAI;;AAGb,QAAA,OAAOC,qBAAa;;IAGtB,oBAAoB,GAAA;AAClB,QAAA,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE;AACzB,QAAA,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;;;;;;;;","names":["Subject","combineLatest","of","map","takeUntil","subscribeResource","h"],"sources":["src/components/pos-switch/rules/doValuesMatch.ts","src/components/pos-switch/rules/doesRuleMatch.ts","src/components/pos-switch/rules/findMatchingRules.ts","src/components/pos-switch/pos-switch.css?tag=pos-switch&encapsulation=shadow","src/components/pos-switch/pos-switch.tsx"],"sourcesContent":["import { Comparison } from './index';\n\n/**\n * Checks whether the given values match the given target according to the given comparison\n * @param values\n * @param comparison\n */\nexport function doValuesMatch(values: string[], comparison: Comparison): boolean {\n const { operator, semantic, target } = comparison;\n const matches = values.map(val => {\n let cmp;\n const numVal = Number(val);\n const numTarget = Number(target);\n if (!Number.isNaN(numVal) && !Number.isNaN(numTarget)) {\n cmp = numVal - numTarget;\n } else {\n cmp = String(val).localeCompare(String(target));\n }\n switch (operator) {\n case 'eq':\n return cmp === 0;\n case 'gt':\n return cmp > 0;\n case 'gte':\n return cmp >= 0;\n case 'lt':\n return cmp < 0;\n case 'lte':\n return cmp <= 0;\n }\n });\n if (semantic == 'some') {\n return matches.some(Boolean);\n } else if (semantic == 'every') {\n return matches.every(Boolean);\n } else {\n throw new Error(`Unknown semantic: ${semantic}`);\n }\n}\n","import { IfPropertyRule, IfRevRule, IfTypeofRule, RuleContext, SwitchCaseRule } from './index';\n\nimport { doValuesMatch } from './doValuesMatch';\n\nexport function doesRuleMatch(rule: SwitchCaseRule, context: RuleContext) {\n const ruleResult = evaluateRule(rule, context);\n return rule.not ? !ruleResult : ruleResult;\n}\n\nfunction evaluateRule(rule: SwitchCaseRule, context: RuleContext) {\n switch (rule.type) {\n case 'if-typeof':\n return doesTypeMatch(rule, context);\n case 'if-property':\n return doesPropertyMatch(rule, context);\n case 'if-rev':\n return doesReverseRelationMatch(rule, context);\n case 'else':\n return true;\n default:\n return false;\n }\n}\n\nfunction doesTypeMatch(rule: IfTypeofRule, context: RuleContext) {\n return context.types.map(x => x.uri).includes(rule.value);\n}\n\nfunction doesPropertyMatch(rule: IfPropertyRule, context: RuleContext) {\n const matchingLiteral = context.literals.find(it => it.predicate == rule.value);\n const matchingRelation = context.relations.find(it => it.predicate == rule.value);\n if (rule.comparison && (matchingLiteral || matchingRelation)) {\n return doValuesMatch([...(matchingLiteral?.values ?? []), ...(matchingRelation?.uris ?? [])], rule.comparison);\n }\n return matchingLiteral !== undefined || matchingRelation !== undefined;\n}\n\nfunction doesReverseRelationMatch(rule: IfRevRule, context: RuleContext) {\n const matchingRev = context.reverseRelations.find(x => x.predicate == rule.value);\n if (rule.comparison && matchingRev) {\n return doValuesMatch(matchingRev.uris, rule.comparison);\n }\n return matchingRev !== undefined;\n}\n","import { RuleContext, SwitchCaseRule } from './index';\nimport { doesRuleMatch } from './doesRuleMatch';\n\nexport function findMatchingRules<T extends { rule: SwitchCaseRule }>(cases: T[], context: RuleContext) {\n /**\n * scope of if-else statements\n * each plain if (without else) increases the scope by 1\n * else branches are ignored if we already found a match in the current scope\n */\n let scope = 0;\n /**\n * scope of the previous rule that matched\n */\n let previousRuleMatched = -1;\n return cases.filter(it => {\n if (it.rule.else && previousRuleMatched == scope) {\n return false; // else branches are ignored if we already found a match in the current scope\n }\n if (!it.rule.else) {\n scope++; // plain if rule -> new scope\n }\n const match = doesRuleMatch(it.rule, context);\n if (match) {\n previousRuleMatched = scope; // found a match in the current if-else scope\n }\n return match;\n });\n}\n",":host {\n display: contents;\n}\n","import { Thing } from '@pod-os/core';\nimport { Component, Element, Event, h, State } from '@stencil/core';\nimport { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware';\nimport { combineLatest, map, of, Subject, takeUntil } from 'rxjs';\nimport { findMatchingRules, RuleContext, SwitchCaseRule } from './rules';\n\ninterface CaseWithRule {\n caseElement: HTMLPosCaseElement;\n rule: SwitchCaseRule;\n}\n\n/**\n * Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n * See [pos-case](https://pod-os.org/reference/elements/components/pos-switch/pos-case/) for available filter conditions.\n */\n@Component({\n tag: 'pos-switch',\n shadow: true,\n styleUrl: 'pos-switch.css',\n})\nexport class PosSwitch implements ResourceAware {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n @State() resource?: Thing;\n @State() cases: CaseWithRule[] = [];\n\n private readonly disconnected$ = new Subject<void>();\n\n @Event({ eventName: 'pod-os:resource' })\n subscribeResource!: ResourceEventEmitter;\n\n componentWillLoad() {\n const caseElements = Array.from(this.host.querySelectorAll('pos-case'));\n if (caseElements.length == 0) {\n this.error = 'No pos-case elements found';\n return;\n }\n // Do NOT await: awaiting a child @Method in componentWillLoad deadlocks the\n // lazy load graph (the child can't render until this component renders).\n // Build the rules once the children have upgraded, then subscribe to the resource\n Promise.all(\n caseElements.map(async it => ({\n rule: await it.getRule(),\n caseElement: it,\n })),\n ).then(cases => {\n this.cases = cases;\n subscribeResource(this);\n });\n }\n\n receiveResource = (resource: Thing) => {\n // reset any existing resource\n this.disconnected$.next();\n this.resource = resource;\n\n combineLatest([\n this.containsRule('if-typeof') ? resource.observeTypes() : of([]),\n this.containsRule('if-property') ? resource.observeLiterals() : of([]),\n this.containsRule('if-property') ? resource.observeRelations() : of([]),\n this.containsRule('if-rev') ? resource.observeReverseRelations() : of([]),\n ])\n .pipe(\n map(([types, literals, relations, reverseRelations]) => ({\n types,\n literals,\n relations,\n reverseRelations,\n })),\n takeUntil(this.disconnected$),\n )\n .subscribe((context: RuleContext) => {\n const activeElements = new Set(findMatchingRules(this.cases, context).map(it => it.caseElement));\n this.cases.forEach(it => {\n if (activeElements.has(it.caseElement)) {\n it.caseElement.setAttribute('active', '');\n } else {\n it.caseElement.removeAttribute('active');\n }\n });\n });\n };\n\n private containsRule(type: SwitchCaseRule['type']) {\n return this.cases.some(it => it.rule.type === type);\n }\n\n render() {\n if (this.error) {\n return this.error;\n }\n if (!this.resource) {\n return null;\n }\n\n return <slot></slot>;\n }\n\n disconnectedCallback() {\n this.disconnected$.next();\n this.disconnected$.complete();\n }\n}\n"],"version":3}
|
|
@@ -80,7 +80,7 @@ export class PosCase {
|
|
|
80
80
|
// unset it here to not leave state in the dom
|
|
81
81
|
return h(Host, { innerHTML: "" });
|
|
82
82
|
}
|
|
83
|
-
return h(Host, { innerHTML: this.templateHTML });
|
|
83
|
+
return h(Host, { style: { display: 'contents' }, innerHTML: this.templateHTML });
|
|
84
84
|
}
|
|
85
85
|
static get is() { return "pos-case"; }
|
|
86
86
|
static get originalStyleUrls() {
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, h, Host, Method, Prop, State } from '@stencil/core';\nimport { Comparison, ELSE_RULE, NEVER_RULE, Operator, Semantic, SwitchCaseRule } from '../rules';\n\n/**\n * Defines a template to use if the specified condition is met - to be used with [pos-switch](https://pod-os.org/reference/elements/components/pos-switch/).\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n */\n@Component({\n tag: 'pos-case',\n shadow: false,\n styleUrl: 'pos-case.css',\n})\nexport class PosCase {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n private templateHTML: string | null = null;\n\n /**\n * Test if the resource is of the specified type\n */\n @Prop() ifTypeof?: string;\n /**\n * Test if the resource has the specified property (forward link)\n */\n @Prop() ifProperty?: string;\n /**\n * Test if the resource is the subject of the specified property (backward link)\n */\n @Prop() ifRev?: string;\n /**\n * Negates the result of the test\n */\n @Prop() not?: boolean;\n /**\n * The test only evaluates to true if tests for preceding cases have failed\n */\n @Prop() else?: boolean;\n /**\n * Test if some value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() someValueEq?: string;\n /**\n * Test if every value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() everyValueEq?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGt?: string;\n /**\n * Test if some value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGte?: string;\n /**\n * Test if every value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGte?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLt?: string;\n /**\n * Test if some value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLte?: string;\n /**\n * Test if every value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLte?: string;\n\n componentWillRender() {\n const countRules = [this.ifTypeof, this.ifProperty, this.ifRev].filter(it => it !== undefined).length;\n if (countRules > 1) {\n this.error = 'At most 1 \"if-\" must be present';\n }\n const countComparisons = [\n this.someValueLt,\n this.everyValueLt,\n this.someValueLte,\n this.everyValueLte,\n this.someValueEq,\n this.everyValueEq,\n this.someValueGte,\n this.everyValueGte,\n this.someValueGt,\n this.everyValueGt,\n ].filter(it => it !== undefined).length;\n if (countComparisons > 1) {\n this.error = 'At most 1 comparison (\"every-\" / \"some-\") must be present';\n }\n }\n\n /**\n * Whether this case is active, i.e. shown. Usually this is controlled by the surrounding pos-switch, and there is no need to set this manually.\n */\n @Prop() active = false;\n\n /**\n * Returns the rule definition for this case. The rule determines if the element's content gets rendered.\n */\n @Method()\n async getRule(): Promise<SwitchCaseRule> {\n const modifiers = {\n not: this.not,\n else: this.else,\n };\n const comparison = this.getComparison();\n if (this.ifTypeof) {\n return {\n type: 'if-typeof',\n value: this.ifTypeof,\n ...modifiers,\n };\n }\n if (this.ifProperty) {\n return {\n type: 'if-property',\n value: this.ifProperty,\n ...modifiers,\n comparison,\n };\n }\n if (this.ifRev) {\n return {\n type: 'if-rev',\n value: this.ifRev,\n ...modifiers,\n comparison,\n };\n }\n return this.else ? ELSE_RULE : NEVER_RULE;\n }\n\n private getComparison(): Comparison | undefined {\n return (\n this.comparisonFor(this.someValueEq, 'some', 'eq') ??\n this.comparisonFor(this.everyValueEq, 'every', 'eq') ??\n this.comparisonFor(this.someValueGt, 'some', 'gt') ??\n this.comparisonFor(this.everyValueGt, 'every', 'gt') ??\n this.comparisonFor(this.someValueGte, 'some', 'gte') ??\n this.comparisonFor(this.everyValueGte, 'every', 'gte') ??\n this.comparisonFor(this.someValueLt, 'some', 'lt') ??\n this.comparisonFor(this.everyValueLt, 'every', 'lt') ??\n this.comparisonFor(this.someValueLte, 'some', 'lte') ??\n this.comparisonFor(this.everyValueLte, 'every', 'lte')\n );\n }\n\n private comparisonFor(target: string | undefined, semantic: Semantic, operator: Operator): Comparison | undefined {\n if (target) {\n return { semantic, operator, target };\n }\n }\n\n componentWillLoad() {\n const templateElement = this.host.querySelector('template');\n if (templateElement == null) {\n this.error = 'No template element found';\n } else {\n this.templateHTML = templateElement.innerHTML;\n }\n }\n\n render() {\n if (this.error) return <div class=\"error\">{this.error}</div>;\n\n if (!this.active) {\n // because we set innerHTML for active case elements, we need to\n // unset it here to not leave state in the dom\n return <Host innerHTML=\"\"></Host>;\n }\n return <Host style={{ display: 'contents' }} innerHTML={this.templateHTML}></Host>;\n }\n}\n"]}
|
|
@@ -76,6 +76,16 @@ export class PosSwitch {
|
|
|
76
76
|
}
|
|
77
77
|
static get is() { return "pos-switch"; }
|
|
78
78
|
static get encapsulation() { return "shadow"; }
|
|
79
|
+
static get originalStyleUrls() {
|
|
80
|
+
return {
|
|
81
|
+
"$": ["pos-switch.css"]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
static get styleUrls() {
|
|
85
|
+
return {
|
|
86
|
+
"$": ["pos-switch.css"]
|
|
87
|
+
};
|
|
88
|
+
}
|
|
79
89
|
static get states() {
|
|
80
90
|
return {
|
|
81
91
|
"error": {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pos-switch.js","sourceRoot":"","sources":["../../../../src/components/pos-switch/pos-switch.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAuC,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAA+B,MAAM,SAAS,CAAC;AAOzE;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"pos-switch.js","sourceRoot":"","sources":["../../../../src/components/pos-switch/pos-switch.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAuC,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAA+B,MAAM,SAAS,CAAC;AAOzE;;;;GAIG;AAMH,MAAM,OAAO,SAAS;IALtB;QAOW,UAAK,GAAkB,IAAI,CAAC;QAE5B,UAAK,GAAmB,EAAE,CAAC;QAEnB,kBAAa,GAAG,IAAI,OAAO,EAAQ,CAAC;QAyBrD,oBAAe,GAAG,CAAC,QAAe,EAAE,EAAE;YACpC,8BAA8B;YAC9B,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAEzB,aAAa,CAAC;gBACZ,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,YAAY,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;;;;CACF","sourcesContent":["import { Thing } from '@pod-os/core';\nimport { Component, Element, Event, h, State } from '@stencil/core';\nimport { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware';\nimport { combineLatest, map, of, Subject, takeUntil } from 'rxjs';\nimport { findMatchingRules, RuleContext, SwitchCaseRule } from './rules';\n\ninterface CaseWithRule {\n caseElement: HTMLPosCaseElement;\n rule: SwitchCaseRule;\n}\n\n/**\n * Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n * See [pos-case](https://pod-os.org/reference/elements/components/pos-switch/pos-case/) for available filter conditions.\n */\n@Component({\n tag: 'pos-switch',\n shadow: true,\n styleUrl: 'pos-switch.css',\n})\nexport class PosSwitch implements ResourceAware {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n @State() resource?: Thing;\n @State() cases: CaseWithRule[] = [];\n\n private readonly disconnected$ = new Subject<void>();\n\n @Event({ eventName: 'pod-os:resource' })\n subscribeResource!: ResourceEventEmitter;\n\n componentWillLoad() {\n const caseElements = Array.from(this.host.querySelectorAll('pos-case'));\n if (caseElements.length == 0) {\n this.error = 'No pos-case elements found';\n return;\n }\n // Do NOT await: awaiting a child @Method in componentWillLoad deadlocks the\n // lazy load graph (the child can't render until this component renders).\n // Build the rules once the children have upgraded, then subscribe to the resource\n Promise.all(\n caseElements.map(async it => ({\n rule: await it.getRule(),\n caseElement: it,\n })),\n ).then(cases => {\n this.cases = cases;\n subscribeResource(this);\n });\n }\n\n receiveResource = (resource: Thing) => {\n // reset any existing resource\n this.disconnected$.next();\n this.resource = resource;\n\n combineLatest([\n this.containsRule('if-typeof') ? resource.observeTypes() : of([]),\n this.containsRule('if-property') ? resource.observeLiterals() : of([]),\n this.containsRule('if-property') ? resource.observeRelations() : of([]),\n this.containsRule('if-rev') ? resource.observeReverseRelations() : of([]),\n ])\n .pipe(\n map(([types, literals, relations, reverseRelations]) => ({\n types,\n literals,\n relations,\n reverseRelations,\n })),\n takeUntil(this.disconnected$),\n )\n .subscribe((context: RuleContext) => {\n const activeElements = new Set(findMatchingRules(this.cases, context).map(it => it.caseElement));\n this.cases.forEach(it => {\n if (activeElements.has(it.caseElement)) {\n it.caseElement.setAttribute('active', '');\n } else {\n it.caseElement.removeAttribute('active');\n }\n });\n });\n };\n\n private containsRule(type: SwitchCaseRule['type']) {\n return this.cases.some(it => it.rule.type === type);\n }\n\n render() {\n if (this.error) {\n return this.error;\n }\n if (!this.resource) {\n return null;\n }\n\n return <slot></slot>;\n }\n\n disconnectedCallback() {\n this.disconnected$.next();\n this.disconnected$.complete();\n }\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{proxyCustomElement as e,HTMLElement as t,h as s,Host as i,transformTag as r}from"@stencil/core/internal/client";const o={type:"never",not:false,else:false};const l={type:"else",not:false,else:true};const n=()=>`.error{background-color:var(--pos-error-background-color);border:1px solid var(--pos-error-border-color);padding:var(--size-3);border-radius:var(--radius-md)}`;const u=e(class e extends t{constructor(e){super();if(e!==false){this.__registerHost()}this.error=null;this.templateHTML=null;this.active=false}componentWillRender(){const e=[this.ifTypeof,this.ifProperty,this.ifRev].filter((e=>e!==undefined)).length;if(e>1){this.error='At most 1 "if-" must be present'}const t=[this.someValueLt,this.everyValueLt,this.someValueLte,this.everyValueLte,this.someValueEq,this.everyValueEq,this.someValueGte,this.everyValueGte,this.someValueGt,this.everyValueGt].filter((e=>e!==undefined)).length;if(t>1){this.error='At most 1 comparison ("every-" / "some-") must be present'}}async getRule(){const e={not:this.not,else:this.else};const t=this.getComparison();if(this.ifTypeof){return Object.assign({type:"if-typeof",value:this.ifTypeof},e)}if(this.ifProperty){return Object.assign(Object.assign({type:"if-property",value:this.ifProperty},e),{comparison:t})}if(this.ifRev){return Object.assign(Object.assign({type:"if-rev",value:this.ifRev},e),{comparison:t})}return this.else?l:o}getComparison(){var e,t,s,i,r,o,l,n,u;return(u=(n=(l=(o=(r=(i=(s=(t=(e=this.comparisonFor(this.someValueEq,"some","eq"))!==null&&e!==void 0?e:this.comparisonFor(this.everyValueEq,"every","eq"))!==null&&t!==void 0?t:this.comparisonFor(this.someValueGt,"some","gt"))!==null&&s!==void 0?s:this.comparisonFor(this.everyValueGt,"every","gt"))!==null&&i!==void 0?i:this.comparisonFor(this.someValueGte,"some","gte"))!==null&&r!==void 0?r:this.comparisonFor(this.everyValueGte,"every","gte"))!==null&&o!==void 0?o:this.comparisonFor(this.someValueLt,"some","lt"))!==null&&l!==void 0?l:this.comparisonFor(this.everyValueLt,"every","lt"))!==null&&n!==void 0?n:this.comparisonFor(this.someValueLte,"some","lte"))!==null&&u!==void 0?u:this.comparisonFor(this.everyValueLte,"every","lte")}comparisonFor(e,t,s){if(e){return{semantic:t,operator:s,target:e}}}componentWillLoad(){const e=this.host.querySelector("template");if(e==null){this.error="No template element found"}else{this.templateHTML=e.innerHTML}}render(){if(this.error)return s("div",{class:"error"},this.error);if(!this.active){return s(i,{innerHTML:""})}return s(i,{innerHTML:this.templateHTML})}get host(){return this}static get style(){return n()}},[0,"pos-case",{ifTypeof:[1,"if-typeof"],ifProperty:[1,"if-property"],ifRev:[1,"if-rev"],not:[4],else:[4],someValueEq:[1,"some-value-eq"],everyValueEq:[1,"every-value-eq"],someValueGt:[1,"some-value-gt"],everyValueGt:[1,"every-value-gt"],someValueGte:[1,"some-value-gte"],everyValueGte:[1,"every-value-gte"],someValueLt:[1,"some-value-lt"],everyValueLt:[1,"every-value-lt"],someValueLte:[1,"some-value-lte"],everyValueLte:[1,"every-value-lte"],active:[4],error:[32],getRule:[64]}]);function a(){if(typeof customElements==="undefined"){return}const e=["pos-case"];e.forEach((e=>{switch(e){case"pos-case":if(!customElements.get(r(e))){customElements.define(r(e),u)}break}}))}const h=u;const
|
|
1
|
+
import{proxyCustomElement as e,HTMLElement as t,h as s,Host as i,transformTag as r}from"@stencil/core/internal/client";const o={type:"never",not:false,else:false};const l={type:"else",not:false,else:true};const n=()=>`.error{background-color:var(--pos-error-background-color);border:1px solid var(--pos-error-border-color);padding:var(--size-3);border-radius:var(--radius-md)}`;const u=e(class e extends t{constructor(e){super();if(e!==false){this.__registerHost()}this.error=null;this.templateHTML=null;this.active=false}componentWillRender(){const e=[this.ifTypeof,this.ifProperty,this.ifRev].filter((e=>e!==undefined)).length;if(e>1){this.error='At most 1 "if-" must be present'}const t=[this.someValueLt,this.everyValueLt,this.someValueLte,this.everyValueLte,this.someValueEq,this.everyValueEq,this.someValueGte,this.everyValueGte,this.someValueGt,this.everyValueGt].filter((e=>e!==undefined)).length;if(t>1){this.error='At most 1 comparison ("every-" / "some-") must be present'}}async getRule(){const e={not:this.not,else:this.else};const t=this.getComparison();if(this.ifTypeof){return Object.assign({type:"if-typeof",value:this.ifTypeof},e)}if(this.ifProperty){return Object.assign(Object.assign({type:"if-property",value:this.ifProperty},e),{comparison:t})}if(this.ifRev){return Object.assign(Object.assign({type:"if-rev",value:this.ifRev},e),{comparison:t})}return this.else?l:o}getComparison(){var e,t,s,i,r,o,l,n,u;return(u=(n=(l=(o=(r=(i=(s=(t=(e=this.comparisonFor(this.someValueEq,"some","eq"))!==null&&e!==void 0?e:this.comparisonFor(this.everyValueEq,"every","eq"))!==null&&t!==void 0?t:this.comparisonFor(this.someValueGt,"some","gt"))!==null&&s!==void 0?s:this.comparisonFor(this.everyValueGt,"every","gt"))!==null&&i!==void 0?i:this.comparisonFor(this.someValueGte,"some","gte"))!==null&&r!==void 0?r:this.comparisonFor(this.everyValueGte,"every","gte"))!==null&&o!==void 0?o:this.comparisonFor(this.someValueLt,"some","lt"))!==null&&l!==void 0?l:this.comparisonFor(this.everyValueLt,"every","lt"))!==null&&n!==void 0?n:this.comparisonFor(this.someValueLte,"some","lte"))!==null&&u!==void 0?u:this.comparisonFor(this.everyValueLte,"every","lte")}comparisonFor(e,t,s){if(e){return{semantic:t,operator:s,target:e}}}componentWillLoad(){const e=this.host.querySelector("template");if(e==null){this.error="No template element found"}else{this.templateHTML=e.innerHTML}}render(){if(this.error)return s("div",{class:"error"},this.error);if(!this.active){return s(i,{innerHTML:""})}return s(i,{style:{display:"contents"},innerHTML:this.templateHTML})}get host(){return this}static get style(){return n()}},[0,"pos-case",{ifTypeof:[1,"if-typeof"],ifProperty:[1,"if-property"],ifRev:[1,"if-rev"],not:[4],else:[4],someValueEq:[1,"some-value-eq"],everyValueEq:[1,"every-value-eq"],someValueGt:[1,"some-value-gt"],everyValueGt:[1,"every-value-gt"],someValueGte:[1,"some-value-gte"],everyValueGte:[1,"every-value-gte"],someValueLt:[1,"some-value-lt"],everyValueLt:[1,"every-value-lt"],someValueLte:[1,"some-value-lte"],everyValueLte:[1,"every-value-lte"],active:[4],error:[32],getRule:[64]}]);function a(){if(typeof customElements==="undefined"){return}const e=["pos-case"];e.forEach((e=>{switch(e){case"pos-case":if(!customElements.get(r(e))){customElements.define(r(e),u)}break}}))}const h=u;const c=a;export{h as PosCase,c as defineCustomElement};
|
|
2
2
|
//# sourceMappingURL=pos-case.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NEVER_RULE","type","not","else","ELSE_RULE","posCaseCss","PosCase","__stencil_proxyCustomElement","HTMLElement","constructor","registerHost","this","error","templateHTML","active","componentWillRender","countRules","ifTypeof","ifProperty","ifRev","filter","it","undefined","length","countComparisons","someValueLt","everyValueLt","someValueLte","everyValueLte","someValueEq","everyValueEq","someValueGte","everyValueGte","someValueGt","everyValueGt","getRule","modifiers","comparison","getComparison","Object","assign","value","_j","_h","_g","_f","_e","_d","_c","_b","_a","comparisonFor","target","semantic","operator","componentWillLoad","templateElement","host","querySelector","innerHTML","render","h","class","Host"],"sources":["src/components/pos-switch/rules/index.ts","src/components/pos-switch/pos-case/pos-case.css?tag=pos-case","src/components/pos-switch/pos-case/pos-case.tsx"],"sourcesContent":["import { Literal, RdfType, Relation } from '@pod-os/core';\n\nexport { findMatchingRules } from './findMatchingRules';\n\n/**\n * A rule that matches if the resource is of a specific type\n */\nexport interface IfTypeofRule {\n type: 'if-typeof';\n /**\n * The URI of the type to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource is not of the specified type)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n}\n\n/**\n * A rule that matches if the resource has a specific property (literal or relation)\n */\nexport interface IfPropertyRule {\n type: 'if-property';\n /**\n * The value of the property to match against (either literal value or the URI of a relation)\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified property)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the value of the property matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that matches if the resource has a specific reverse relation\n */\nexport interface IfRevRule {\n type: 'if-rev';\n /**\n * The URI of the reverse relation to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified reverse relation)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the URI of the reverse relation matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that only matches if all others did not\n */\nexport interface ElseRule {\n type: 'else';\n not: false;\n else: true;\n}\n\n/**\n * A rule that never matches\n */\nexport interface NeverRule {\n type: 'never';\n not: false;\n else: false;\n}\n\n/**\n * A rule defined by a pos-case\n */\nexport type SwitchCaseRule = IfTypeofRule | IfPropertyRule | IfRevRule | ElseRule | NeverRule;\n\nexport const NEVER_RULE: NeverRule = {\n type: 'never',\n not: false,\n else: false,\n};\n\nexport const ELSE_RULE: ElseRule = {\n type: 'else',\n not: false,\n else: true,\n};\n\n/**\n * Contains the actual data a rule is matched against\n */\nexport interface RuleContext {\n types: RdfType[];\n literals: Literal[];\n relations: Relation[];\n reverseRelations: Relation[];\n}\n\n/**\n * Defines how to compare values to a specific target value\n */\nexport interface Comparison {\n /**\n * Does every value need to match, or only some?\n */\n semantic: Semantic;\n /**\n * The comparison operator to apply (e.g. value must be equal, greater than, etc.)\n */\n operator: Operator;\n /**\n * The target value to compare against.\n */\n target: string;\n}\n\nexport type equals = 'eq';\nexport type greaterThan = 'gt';\nexport type greaterThanOrEqual = 'gte';\nexport type lessThan = 'lt';\nexport type lessThanOrEqual = 'lte';\nexport type some = 'some';\nexport type every = 'every';\nexport type Operator = equals | greaterThan | greaterThanOrEqual | lessThan | lessThanOrEqual;\nexport type Semantic = some | every;\n",".error {\n background-color: var(--pos-error-background-color);\n border: 1px solid var(--pos-error-border-color);\n padding: var(--size-3);\n border-radius: var(--radius-md);\n}\n","import { Component, Element, h, Host, Method, Prop, State } from '@stencil/core';\nimport { Comparison, ELSE_RULE, NEVER_RULE, Operator, Semantic, SwitchCaseRule } from '../rules';\n\n/**\n * Defines a template to use if the specified condition is met - to be used with [pos-switch](https://pod-os.org/reference/elements/components/pos-switch/).\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n */\n@Component({\n tag: 'pos-case',\n shadow: false,\n styleUrl: 'pos-case.css',\n})\nexport class PosCase {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n private templateHTML: string | null = null;\n\n /**\n * Test if the resource is of the specified type\n */\n @Prop() ifTypeof?: string;\n /**\n * Test if the resource has the specified property (forward link)\n */\n @Prop() ifProperty?: string;\n /**\n * Test if the resource is the subject of the specified property (backward link)\n */\n @Prop() ifRev?: string;\n /**\n * Negates the result of the test\n */\n @Prop() not?: boolean;\n /**\n * The test only evaluates to true if tests for preceding cases have failed\n */\n @Prop() else?: boolean;\n /**\n * Test if some value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() someValueEq?: string;\n /**\n * Test if every value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() everyValueEq?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGt?: string;\n /**\n * Test if some value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGte?: string;\n /**\n * Test if every value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGte?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLt?: string;\n /**\n * Test if some value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLte?: string;\n /**\n * Test if every value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLte?: string;\n\n componentWillRender() {\n const countRules = [this.ifTypeof, this.ifProperty, this.ifRev].filter(it => it !== undefined).length;\n if (countRules > 1) {\n this.error = 'At most 1 \"if-\" must be present';\n }\n const countComparisons = [\n this.someValueLt,\n this.everyValueLt,\n this.someValueLte,\n this.everyValueLte,\n this.someValueEq,\n this.everyValueEq,\n this.someValueGte,\n this.everyValueGte,\n this.someValueGt,\n this.everyValueGt,\n ].filter(it => it !== undefined).length;\n if (countComparisons > 1) {\n this.error = 'At most 1 comparison (\"every-\" / \"some-\") must be present';\n }\n }\n\n /**\n * Whether this case is active, i.e. shown. Usually this is controlled by the surrounding pos-switch, and there is no need to set this manually.\n */\n @Prop() active = false;\n\n /**\n * Returns the rule definition for this case. The rule determines if the element's content gets rendered.\n */\n @Method()\n async getRule(): Promise<SwitchCaseRule> {\n const modifiers = {\n not: this.not,\n else: this.else,\n };\n const comparison = this.getComparison();\n if (this.ifTypeof) {\n return {\n type: 'if-typeof',\n value: this.ifTypeof,\n ...modifiers,\n };\n }\n if (this.ifProperty) {\n return {\n type: 'if-property',\n value: this.ifProperty,\n ...modifiers,\n comparison,\n };\n }\n if (this.ifRev) {\n return {\n type: 'if-rev',\n value: this.ifRev,\n ...modifiers,\n comparison,\n };\n }\n return this.else ? ELSE_RULE : NEVER_RULE;\n }\n\n private getComparison(): Comparison | undefined {\n return (\n this.comparisonFor(this.someValueEq, 'some', 'eq') ??\n this.comparisonFor(this.everyValueEq, 'every', 'eq') ??\n this.comparisonFor(this.someValueGt, 'some', 'gt') ??\n this.comparisonFor(this.everyValueGt, 'every', 'gt') ??\n this.comparisonFor(this.someValueGte, 'some', 'gte') ??\n this.comparisonFor(this.everyValueGte, 'every', 'gte') ??\n this.comparisonFor(this.someValueLt, 'some', 'lt') ??\n this.comparisonFor(this.everyValueLt, 'every', 'lt') ??\n this.comparisonFor(this.someValueLte, 'some', 'lte') ??\n this.comparisonFor(this.everyValueLte, 'every', 'lte')\n );\n }\n\n private comparisonFor(target: string | undefined, semantic: Semantic, operator: Operator): Comparison | undefined {\n if (target) {\n return { semantic, operator, target };\n }\n }\n\n componentWillLoad() {\n const templateElement = this.host.querySelector('template');\n if (templateElement == null) {\n this.error = 'No template element found';\n } else {\n this.templateHTML = templateElement.innerHTML;\n }\n }\n\n render() {\n if (this.error) return <div class=\"error\">{this.error}</div>;\n\n if (!this.active) {\n // because we set innerHTML for active case elements, we need to\n // unset it here to not leave state in the dom\n return <Host innerHTML=\"\"></Host>;\n }\n return <Host innerHTML={this.templateHTML}></Host>;\n }\n}\n"],"mappings":"uHA4FO,MAAMA,EAAwB,CACnCC,KAAM,QACNC,IAAK,MACLC,KAAM,OAGD,MAAMC,EAAsB,CACjCH,KAAM,OACNC,IAAK,MACLC,KAAM,MCrGR,MAAME,EAAa,IAAM,iK,MCYZC,EAAOC,EAAA,MAAAD,UAAAE,EALpB,WAAAC,CAAAC,G,4CAOWC,KAAAC,MAAuB,KACxBD,KAAAE,aAA8B,KAwF9BF,KAAAG,OAAS,KA8ElB,CAvGC,mBAAAC,GACE,MAAMC,EAAa,CAACL,KAAKM,SAAUN,KAAKO,WAAYP,KAAKQ,OAAOC,QAAOC,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KAAKwC,cAAcxC,KAAKoB,aAAc,OAAQ,UAAM,MAAAe,SAAA,EAAAA,EACpDnC,KAAKwC,cAAcxC,KAAKqB,cAAe,QAAS,UAAM,MAAAa,SAAA,EAAAA,EACtDlC,KAAKwC,cAAcxC,KAAKc,YAAa,OAAQ,SAAK,MAAAmB,SAAA,EAAAA,EAClDjC,KAAKwC,cAAcxC,KAAKe,aAAc,QAAS,SAAK,MAAAiB,SAAA,EAAAA,EACpDhC,KAAKwC,cAAcxC,KAAKgB,aAAc,OAAQ,UAAM,MAAAe,SAAA,EAAAA,EACpD/B,KAAKwC,cAAcxC,KAAKiB,cAAe,QAAS,M,CAI5C,aAAAuB,CAAcC,EAA4BC,EAAoBC,GACpE,GAAIF,EAAQ,CACV,MAAO,CAAEC,WAAUC,WAAUF,S,EAIjC,iBAAAG,GACE,MAAMC,EAAkB7C,KAAK8C,KAAKC,cAAc,YAChD,GAAIF,GAAmB,KAAM,CAC3B7C,KAAKC,MAAQ,2B,KACR,CACLD,KAAKE,aAAe2C,EAAgBG,S,EAIxC,MAAAC,GACE,GAAIjD,KAAKC,MAAO,OAAOiD,EAAA,OAAKC,MAAM,SAASnD,KAAKC,OAEhD,IAAKD,KAAKG,OAAQ,CAGhB,OAAO+C,EAACE,EAAI,CAACJ,UAAU,I,CAEzB,OAAOE,EAACE,EAAI,CAACJ,UAAWhD,KAAKE,c","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["NEVER_RULE","type","not","else","ELSE_RULE","posCaseCss","PosCase","__stencil_proxyCustomElement","HTMLElement","constructor","registerHost","this","error","templateHTML","active","componentWillRender","countRules","ifTypeof","ifProperty","ifRev","filter","it","undefined","length","countComparisons","someValueLt","everyValueLt","someValueLte","everyValueLte","someValueEq","everyValueEq","someValueGte","everyValueGte","someValueGt","everyValueGt","getRule","modifiers","comparison","getComparison","Object","assign","value","_j","_h","_g","_f","_e","_d","_c","_b","_a","comparisonFor","target","semantic","operator","componentWillLoad","templateElement","host","querySelector","innerHTML","render","h","class","Host","style","display"],"sources":["src/components/pos-switch/rules/index.ts","src/components/pos-switch/pos-case/pos-case.css?tag=pos-case","src/components/pos-switch/pos-case/pos-case.tsx"],"sourcesContent":["import { Literal, RdfType, Relation } from '@pod-os/core';\n\nexport { findMatchingRules } from './findMatchingRules';\n\n/**\n * A rule that matches if the resource is of a specific type\n */\nexport interface IfTypeofRule {\n type: 'if-typeof';\n /**\n * The URI of the type to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource is not of the specified type)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n}\n\n/**\n * A rule that matches if the resource has a specific property (literal or relation)\n */\nexport interface IfPropertyRule {\n type: 'if-property';\n /**\n * The value of the property to match against (either literal value or the URI of a relation)\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified property)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the value of the property matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that matches if the resource has a specific reverse relation\n */\nexport interface IfRevRule {\n type: 'if-rev';\n /**\n * The URI of the reverse relation to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified reverse relation)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the URI of the reverse relation matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that only matches if all others did not\n */\nexport interface ElseRule {\n type: 'else';\n not: false;\n else: true;\n}\n\n/**\n * A rule that never matches\n */\nexport interface NeverRule {\n type: 'never';\n not: false;\n else: false;\n}\n\n/**\n * A rule defined by a pos-case\n */\nexport type SwitchCaseRule = IfTypeofRule | IfPropertyRule | IfRevRule | ElseRule | NeverRule;\n\nexport const NEVER_RULE: NeverRule = {\n type: 'never',\n not: false,\n else: false,\n};\n\nexport const ELSE_RULE: ElseRule = {\n type: 'else',\n not: false,\n else: true,\n};\n\n/**\n * Contains the actual data a rule is matched against\n */\nexport interface RuleContext {\n types: RdfType[];\n literals: Literal[];\n relations: Relation[];\n reverseRelations: Relation[];\n}\n\n/**\n * Defines how to compare values to a specific target value\n */\nexport interface Comparison {\n /**\n * Does every value need to match, or only some?\n */\n semantic: Semantic;\n /**\n * The comparison operator to apply (e.g. value must be equal, greater than, etc.)\n */\n operator: Operator;\n /**\n * The target value to compare against.\n */\n target: string;\n}\n\nexport type equals = 'eq';\nexport type greaterThan = 'gt';\nexport type greaterThanOrEqual = 'gte';\nexport type lessThan = 'lt';\nexport type lessThanOrEqual = 'lte';\nexport type some = 'some';\nexport type every = 'every';\nexport type Operator = equals | greaterThan | greaterThanOrEqual | lessThan | lessThanOrEqual;\nexport type Semantic = some | every;\n",".error {\n background-color: var(--pos-error-background-color);\n border: 1px solid var(--pos-error-border-color);\n padding: var(--size-3);\n border-radius: var(--radius-md);\n}\n","import { Component, Element, h, Host, Method, Prop, State } from '@stencil/core';\nimport { Comparison, ELSE_RULE, NEVER_RULE, Operator, Semantic, SwitchCaseRule } from '../rules';\n\n/**\n * Defines a template to use if the specified condition is met - to be used with [pos-switch](https://pod-os.org/reference/elements/components/pos-switch/).\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n */\n@Component({\n tag: 'pos-case',\n shadow: false,\n styleUrl: 'pos-case.css',\n})\nexport class PosCase {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n private templateHTML: string | null = null;\n\n /**\n * Test if the resource is of the specified type\n */\n @Prop() ifTypeof?: string;\n /**\n * Test if the resource has the specified property (forward link)\n */\n @Prop() ifProperty?: string;\n /**\n * Test if the resource is the subject of the specified property (backward link)\n */\n @Prop() ifRev?: string;\n /**\n * Negates the result of the test\n */\n @Prop() not?: boolean;\n /**\n * The test only evaluates to true if tests for preceding cases have failed\n */\n @Prop() else?: boolean;\n /**\n * Test if some value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() someValueEq?: string;\n /**\n * Test if every value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() everyValueEq?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGt?: string;\n /**\n * Test if some value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGte?: string;\n /**\n * Test if every value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGte?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLt?: string;\n /**\n * Test if some value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLte?: string;\n /**\n * Test if every value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLte?: string;\n\n componentWillRender() {\n const countRules = [this.ifTypeof, this.ifProperty, this.ifRev].filter(it => it !== undefined).length;\n if (countRules > 1) {\n this.error = 'At most 1 \"if-\" must be present';\n }\n const countComparisons = [\n this.someValueLt,\n this.everyValueLt,\n this.someValueLte,\n this.everyValueLte,\n this.someValueEq,\n this.everyValueEq,\n this.someValueGte,\n this.everyValueGte,\n this.someValueGt,\n this.everyValueGt,\n ].filter(it => it !== undefined).length;\n if (countComparisons > 1) {\n this.error = 'At most 1 comparison (\"every-\" / \"some-\") must be present';\n }\n }\n\n /**\n * Whether this case is active, i.e. shown. Usually this is controlled by the surrounding pos-switch, and there is no need to set this manually.\n */\n @Prop() active = false;\n\n /**\n * Returns the rule definition for this case. The rule determines if the element's content gets rendered.\n */\n @Method()\n async getRule(): Promise<SwitchCaseRule> {\n const modifiers = {\n not: this.not,\n else: this.else,\n };\n const comparison = this.getComparison();\n if (this.ifTypeof) {\n return {\n type: 'if-typeof',\n value: this.ifTypeof,\n ...modifiers,\n };\n }\n if (this.ifProperty) {\n return {\n type: 'if-property',\n value: this.ifProperty,\n ...modifiers,\n comparison,\n };\n }\n if (this.ifRev) {\n return {\n type: 'if-rev',\n value: this.ifRev,\n ...modifiers,\n comparison,\n };\n }\n return this.else ? ELSE_RULE : NEVER_RULE;\n }\n\n private getComparison(): Comparison | undefined {\n return (\n this.comparisonFor(this.someValueEq, 'some', 'eq') ??\n this.comparisonFor(this.everyValueEq, 'every', 'eq') ??\n this.comparisonFor(this.someValueGt, 'some', 'gt') ??\n this.comparisonFor(this.everyValueGt, 'every', 'gt') ??\n this.comparisonFor(this.someValueGte, 'some', 'gte') ??\n this.comparisonFor(this.everyValueGte, 'every', 'gte') ??\n this.comparisonFor(this.someValueLt, 'some', 'lt') ??\n this.comparisonFor(this.everyValueLt, 'every', 'lt') ??\n this.comparisonFor(this.someValueLte, 'some', 'lte') ??\n this.comparisonFor(this.everyValueLte, 'every', 'lte')\n );\n }\n\n private comparisonFor(target: string | undefined, semantic: Semantic, operator: Operator): Comparison | undefined {\n if (target) {\n return { semantic, operator, target };\n }\n }\n\n componentWillLoad() {\n const templateElement = this.host.querySelector('template');\n if (templateElement == null) {\n this.error = 'No template element found';\n } else {\n this.templateHTML = templateElement.innerHTML;\n }\n }\n\n render() {\n if (this.error) return <div class=\"error\">{this.error}</div>;\n\n if (!this.active) {\n // because we set innerHTML for active case elements, we need to\n // unset it here to not leave state in the dom\n return <Host innerHTML=\"\"></Host>;\n }\n return <Host style={{ display: 'contents' }} innerHTML={this.templateHTML}></Host>;\n }\n}\n"],"mappings":"uHA4FO,MAAMA,EAAwB,CACnCC,KAAM,QACNC,IAAK,MACLC,KAAM,OAGD,MAAMC,EAAsB,CACjCH,KAAM,OACNC,IAAK,MACLC,KAAM,MCrGR,MAAME,EAAa,IAAM,iK,MCYZC,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/core/internal/client";import{s as i}from"./ResourceAware.js";import{c as o}from"./index3.js";function c(t,e){const{operator:s,semantic:r,target:n}=e;const i=t.map((t=>{let e;const r=Number(t);const i=Number(n);if(!Number.isNaN(r)&&!Number.isNaN(i)){e=r-i}else{e=String(t).localeCompare(String(n))}switch(s){case"eq":return e===0;case"gt":return e>0;case"gte":return e>=0;case"lt":return e<0;case"lte":return e<=0}}));if(r=="some"){return i.some(Boolean)}else if(r=="every"){return i.every(Boolean)}else{throw new Error(`Unknown semantic: ${r}`)}}function u(t,e){const s=l(t,e);return t.not?!s:s}function l(t,e){switch(t.type){case"if-typeof":return a(t,e);case"if-property":return f(t,e);case"if-rev":return h(t,e);case"else":return true;default:return false}}function a(t,e){return e.types.map((t=>t.uri)).includes(t.value)}function f(t,e){var s,r;const n=e.literals.find((e=>e.predicate==t.value));const i=e.relations.find((e=>e.predicate==t.value));if(t.comparison&&(n||i)){return c([...(s=n===null||n===void 0?void 0:n.values)!==null&&s!==void 0?s:[],...(r=i===null||i===void 0?void 0:i.uris)!==null&&r!==void 0?r:[]],t.comparison)}return n!==undefined||i!==undefined}function h(t,e){const s=e.reverseRelations.find((e=>e.predicate==t.value));if(t.comparison&&s){return c(s.uris,t.comparison)}return s!==undefined}function d(t,e){let s=0;let r=-1;return t.filter((t=>{if(t.rule.else&&r==s){return false}if(!t.rule.else){s++}const n=u(t.rule,e);if(n){r=s}return n}))}const p=()=>`:host{display:contents}`;const m=t(class t extends e{constructor(t){super();if(t!==false){this.__registerHost()}this.__attachShadow();this.subscribeResource=s(this,"pod-os:resource",7);this.error=null;this.cases=[];this.disconnected$=new o.Subject;this.receiveResource=t=>{this.disconnected$.next();this.resource=t;o.combineLatest([this.containsRule("if-typeof")?t.observeTypes():o.of([]),this.containsRule("if-property")?t.observeLiterals():o.of([]),this.containsRule("if-property")?t.observeRelations():o.of([]),this.containsRule("if-rev")?t.observeReverseRelations():o.of([])]).pipe(o.map((([t,e,s,r])=>({types:t,literals:e,relations:s,reverseRelations:r}))),o.takeUntil(this.disconnected$)).subscribe((t=>{const e=new Set(d(this.cases,t).map((t=>t.caseElement)));this.cases.forEach((t=>{if(e.has(t.caseElement)){t.caseElement.setAttribute("active","")}else{t.caseElement.removeAttribute("active")}}))}))}}componentWillLoad(){const t=Array.from(this.host.querySelectorAll("pos-case"));if(t.length==0){this.error="No pos-case elements found";return}Promise.all(t.map((async t=>({rule:await t.getRule(),caseElement:t})))).then((t=>{this.cases=t;i(this)}))}containsRule(t){return this.cases.some((e=>e.rule.type===t))}render(){if(this.error){return this.error}if(!this.resource){return null}return r("slot",null)}disconnectedCallback(){this.disconnected$.next();this.disconnected$.complete()}get host(){return this}static get style(){return p()}},[257,"pos-switch",{error:[32],resource:[32],cases:[32]}]);function v(){if(typeof customElements==="undefined"){return}const t=["pos-switch"];t.forEach((t=>{switch(t){case"pos-switch":if(!customElements.get(n(t))){customElements.define(n(t),m)}break}}))}const w=m;const y=v;export{w as PosSwitch,y as defineCustomElement};
|
|
2
2
|
//# sourceMappingURL=pos-switch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["doValuesMatch","values","comparison","operator","semantic","target","matches","map","val","cmp","numVal","Number","numTarget","isNaN","String","localeCompare","some","Boolean","every","Error","doesRuleMatch","rule","context","ruleResult","evaluateRule","not","type","doesTypeMatch","doesPropertyMatch","doesReverseRelationMatch","types","x","uri","includes","value","matchingLiteral","literals","find","it","predicate","matchingRelation","relations","_a","_b","uris","undefined","matchingRev","reverseRelations","findMatchingRules","cases","scope","previousRuleMatched","filter","else","match","PosSwitch","__stencil_proxyCustomElement","HTMLElement","constructor","registerHost","this","error","disconnected$","Subject","receiveResource","resource","next","combineLatest","containsRule","observeTypes","of","observeLiterals","observeRelations","observeReverseRelations","pipe","takeUntil","subscribe","activeElements","Set","caseElement","forEach","has","setAttribute","removeAttribute","componentWillLoad","caseElements","Array","from","host","querySelectorAll","length","Promise","all","async","getRule","then","subscribeResource","render","h","disconnectedCallback","complete"],"sources":["src/components/pos-switch/rules/doValuesMatch.ts","src/components/pos-switch/rules/doesRuleMatch.ts","src/components/pos-switch/rules/findMatchingRules.ts","src/components/pos-switch/pos-switch.tsx"],"sourcesContent":["import { Comparison } from './index';\n\n/**\n * Checks whether the given values match the given target according to the given comparison\n * @param values\n * @param comparison\n */\nexport function doValuesMatch(values: string[], comparison: Comparison): boolean {\n const { operator, semantic, target } = comparison;\n const matches = values.map(val => {\n let cmp;\n const numVal = Number(val);\n const numTarget = Number(target);\n if (!Number.isNaN(numVal) && !Number.isNaN(numTarget)) {\n cmp = numVal - numTarget;\n } else {\n cmp = String(val).localeCompare(String(target));\n }\n switch (operator) {\n case 'eq':\n return cmp === 0;\n case 'gt':\n return cmp > 0;\n case 'gte':\n return cmp >= 0;\n case 'lt':\n return cmp < 0;\n case 'lte':\n return cmp <= 0;\n }\n });\n if (semantic == 'some') {\n return matches.some(Boolean);\n } else if (semantic == 'every') {\n return matches.every(Boolean);\n } else {\n throw new Error(`Unknown semantic: ${semantic}`);\n }\n}\n","import { IfPropertyRule, IfRevRule, IfTypeofRule, RuleContext, SwitchCaseRule } from './index';\n\nimport { doValuesMatch } from './doValuesMatch';\n\nexport function doesRuleMatch(rule: SwitchCaseRule, context: RuleContext) {\n const ruleResult = evaluateRule(rule, context);\n return rule.not ? !ruleResult : ruleResult;\n}\n\nfunction evaluateRule(rule: SwitchCaseRule, context: RuleContext) {\n switch (rule.type) {\n case 'if-typeof':\n return doesTypeMatch(rule, context);\n case 'if-property':\n return doesPropertyMatch(rule, context);\n case 'if-rev':\n return doesReverseRelationMatch(rule, context);\n case 'else':\n return true;\n default:\n return false;\n }\n}\n\nfunction doesTypeMatch(rule: IfTypeofRule, context: RuleContext) {\n return context.types.map(x => x.uri).includes(rule.value);\n}\n\nfunction doesPropertyMatch(rule: IfPropertyRule, context: RuleContext) {\n const matchingLiteral = context.literals.find(it => it.predicate == rule.value);\n const matchingRelation = context.relations.find(it => it.predicate == rule.value);\n if (rule.comparison && (matchingLiteral || matchingRelation)) {\n return doValuesMatch([...(matchingLiteral?.values ?? []), ...(matchingRelation?.uris ?? [])], rule.comparison);\n }\n return matchingLiteral !== undefined || matchingRelation !== undefined;\n}\n\nfunction doesReverseRelationMatch(rule: IfRevRule, context: RuleContext) {\n const matchingRev = context.reverseRelations.find(x => x.predicate == rule.value);\n if (rule.comparison && matchingRev) {\n return doValuesMatch(matchingRev.uris, rule.comparison);\n }\n return matchingRev !== undefined;\n}\n","import { RuleContext, SwitchCaseRule } from './index';\nimport { doesRuleMatch } from './doesRuleMatch';\n\nexport function findMatchingRules<T extends { rule: SwitchCaseRule }>(cases: T[], context: RuleContext) {\n /**\n * scope of if-else statements\n * each plain if (without else) increases the scope by 1\n * else branches are ignored if we already found a match in the current scope\n */\n let scope = 0;\n /**\n * scope of the previous rule that matched\n */\n let previousRuleMatched = -1;\n return cases.filter(it => {\n if (it.rule.else && previousRuleMatched == scope) {\n return false; // else branches are ignored if we already found a match in the current scope\n }\n if (!it.rule.else) {\n scope++; // plain if rule -> new scope\n }\n const match = doesRuleMatch(it.rule, context);\n if (match) {\n previousRuleMatched = scope; // found a match in the current if-else scope\n }\n return match;\n });\n}\n","import { Thing } from '@pod-os/core';\nimport { Component, Element, Event, h, State } from '@stencil/core';\nimport { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware';\nimport { combineLatest, map, of, Subject, takeUntil } from 'rxjs';\nimport { findMatchingRules, RuleContext, SwitchCaseRule } from './rules';\n\ninterface CaseWithRule {\n caseElement: HTMLPosCaseElement;\n rule: SwitchCaseRule;\n}\n\n/**\n * Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n * See [pos-case](https://pod-os.org/reference/elements/components/pos-switch/pos-case/) for available filter conditions.\n */\n@Component({\n tag: 'pos-switch',\n shadow: true,\n})\nexport class PosSwitch implements ResourceAware {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n @State() resource?: Thing;\n @State() cases: CaseWithRule[] = [];\n\n private readonly disconnected$ = new Subject<void>();\n\n @Event({ eventName: 'pod-os:resource' })\n subscribeResource!: ResourceEventEmitter;\n\n componentWillLoad() {\n const caseElements = Array.from(this.host.querySelectorAll('pos-case'));\n if (caseElements.length == 0) {\n this.error = 'No pos-case elements found';\n return;\n }\n // Do NOT await: awaiting a child @Method in componentWillLoad deadlocks the\n // lazy load graph (the child can't render until this component renders).\n // Build the rules once the children have upgraded, then subscribe to the resource\n Promise.all(\n caseElements.map(async it => ({\n rule: await it.getRule(),\n caseElement: it,\n })),\n ).then(cases => {\n this.cases = cases;\n subscribeResource(this);\n });\n }\n\n receiveResource = (resource: Thing) => {\n // reset any existing resource\n this.disconnected$.next();\n this.resource = resource;\n\n combineLatest([\n this.containsRule('if-typeof') ? resource.observeTypes() : of([]),\n this.containsRule('if-property') ? resource.observeLiterals() : of([]),\n this.containsRule('if-property') ? resource.observeRelations() : of([]),\n this.containsRule('if-rev') ? resource.observeReverseRelations() : of([]),\n ])\n .pipe(\n map(([types, literals, relations, reverseRelations]) => ({\n types,\n literals,\n relations,\n reverseRelations,\n })),\n takeUntil(this.disconnected$),\n )\n .subscribe((context: RuleContext) => {\n const activeElements = new Set(findMatchingRules(this.cases, context).map(it => it.caseElement));\n this.cases.forEach(it => {\n if (activeElements.has(it.caseElement)) {\n it.caseElement.setAttribute('active', '');\n } else {\n it.caseElement.removeAttribute('active');\n }\n });\n });\n };\n\n private containsRule(type: SwitchCaseRule['type']) {\n return this.cases.some(it => it.rule.type === type);\n }\n\n render() {\n if (this.error) {\n return this.error;\n }\n if (!this.resource) {\n return null;\n }\n\n return <slot></slot>;\n }\n\n disconnectedCallback() {\n this.disconnected$.next();\n this.disconnected$.complete();\n }\n}\n"],"mappings":"qMAOM,SAAUA,EAAcC,EAAkBC,GAC9C,MAAMC,SAAEA,EAAQC,SAAEA,EAAQC,OAAEA,GAAWH,EACvC,MAAMI,E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,EAAUK,EAAWM,MAAiB,CACjDjB,QACAM,WACAK,YACAM,uBAEF4B,YAAUf,KAAKE,gBAEhBc,WAAWtD,IACV,MAAMuD,EAAiB,IAAIC,IAAI9B,EAAkBY,KAAKX,MAAO3B,GAASf,KAAI+B,GAAMA,EAAGyC,eACnFnB,KAAKX,MAAM+B,SAAQ1C,IACjB,GAAIuC,EAAeI,IAAI3C,EAAGyC,aAAc,CACtCzC,EAAGyC,YAAYG,aAAa,SAAU,G,KACjC,CACL5C,EAAGyC,YAAYI,gBAAgB,S,IAEjC,GACF,CAsBP,CAvEC,iBAAAC,GACE,MAAMC,EAAeC,MAAMC,KAAK3B,KAAK4B,KAAKC,iBAAiB,aAC3D,GAAIJ,EAAaK,QAAU,EAAG,CAC5B9B,KAAKC,MAAQ,6BACb,M,CAKF8B,QAAQC,IACNP,EAAa9E,KAAIsF,MAAMvD,IAAE,CACvBjB,WAAYiB,EAAGwD,UACff,YAAazC,OAEfyD,MAAK9C,IACLW,KAAKX,MAAQA,EACb+C,EAAkBpC,KAAK,G,CAoCnB,YAAAQ,CAAa1C,GACnB,OAAOkC,KAAKX,MAAMjC,MAAKsB,GAAMA,EAAGjB,KAAKK,OAASA,G,CAGhD,MAAAuE,GACE,GAAIrC,KAAKC,MAAO,CACd,OAAOD,KAAKC,K,CAEd,IAAKD,KAAKK,SAAU,CAClB,OAAO,I,CAGT,OAAOiC,EAAA,Y,CAGT,oBAAAC,GACEvC,KAAKE,cAAcI,OACnBN,KAAKE,cAAcsC,U","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["doValuesMatch","values","comparison","operator","semantic","target","matches","map","val","cmp","numVal","Number","numTarget","isNaN","String","localeCompare","some","Boolean","every","Error","doesRuleMatch","rule","context","ruleResult","evaluateRule","not","type","doesTypeMatch","doesPropertyMatch","doesReverseRelationMatch","types","x","uri","includes","value","matchingLiteral","literals","find","it","predicate","matchingRelation","relations","_a","_b","uris","undefined","matchingRev","reverseRelations","findMatchingRules","cases","scope","previousRuleMatched","filter","else","match","posSwitchCss","PosSwitch","__stencil_proxyCustomElement","HTMLElement","constructor","registerHost","this","error","disconnected$","Subject","receiveResource","resource","next","combineLatest","containsRule","observeTypes","of","observeLiterals","observeRelations","observeReverseRelations","pipe","takeUntil","subscribe","activeElements","Set","caseElement","forEach","has","setAttribute","removeAttribute","componentWillLoad","caseElements","Array","from","host","querySelectorAll","length","Promise","all","async","getRule","then","subscribeResource","render","h","disconnectedCallback","complete"],"sources":["src/components/pos-switch/rules/doValuesMatch.ts","src/components/pos-switch/rules/doesRuleMatch.ts","src/components/pos-switch/rules/findMatchingRules.ts","src/components/pos-switch/pos-switch.css?tag=pos-switch&encapsulation=shadow","src/components/pos-switch/pos-switch.tsx"],"sourcesContent":["import { Comparison } from './index';\n\n/**\n * Checks whether the given values match the given target according to the given comparison\n * @param values\n * @param comparison\n */\nexport function doValuesMatch(values: string[], comparison: Comparison): boolean {\n const { operator, semantic, target } = comparison;\n const matches = values.map(val => {\n let cmp;\n const numVal = Number(val);\n const numTarget = Number(target);\n if (!Number.isNaN(numVal) && !Number.isNaN(numTarget)) {\n cmp = numVal - numTarget;\n } else {\n cmp = String(val).localeCompare(String(target));\n }\n switch (operator) {\n case 'eq':\n return cmp === 0;\n case 'gt':\n return cmp > 0;\n case 'gte':\n return cmp >= 0;\n case 'lt':\n return cmp < 0;\n case 'lte':\n return cmp <= 0;\n }\n });\n if (semantic == 'some') {\n return matches.some(Boolean);\n } else if (semantic == 'every') {\n return matches.every(Boolean);\n } else {\n throw new Error(`Unknown semantic: ${semantic}`);\n }\n}\n","import { IfPropertyRule, IfRevRule, IfTypeofRule, RuleContext, SwitchCaseRule } from './index';\n\nimport { doValuesMatch } from './doValuesMatch';\n\nexport function doesRuleMatch(rule: SwitchCaseRule, context: RuleContext) {\n const ruleResult = evaluateRule(rule, context);\n return rule.not ? !ruleResult : ruleResult;\n}\n\nfunction evaluateRule(rule: SwitchCaseRule, context: RuleContext) {\n switch (rule.type) {\n case 'if-typeof':\n return doesTypeMatch(rule, context);\n case 'if-property':\n return doesPropertyMatch(rule, context);\n case 'if-rev':\n return doesReverseRelationMatch(rule, context);\n case 'else':\n return true;\n default:\n return false;\n }\n}\n\nfunction doesTypeMatch(rule: IfTypeofRule, context: RuleContext) {\n return context.types.map(x => x.uri).includes(rule.value);\n}\n\nfunction doesPropertyMatch(rule: IfPropertyRule, context: RuleContext) {\n const matchingLiteral = context.literals.find(it => it.predicate == rule.value);\n const matchingRelation = context.relations.find(it => it.predicate == rule.value);\n if (rule.comparison && (matchingLiteral || matchingRelation)) {\n return doValuesMatch([...(matchingLiteral?.values ?? []), ...(matchingRelation?.uris ?? [])], rule.comparison);\n }\n return matchingLiteral !== undefined || matchingRelation !== undefined;\n}\n\nfunction doesReverseRelationMatch(rule: IfRevRule, context: RuleContext) {\n const matchingRev = context.reverseRelations.find(x => x.predicate == rule.value);\n if (rule.comparison && matchingRev) {\n return doValuesMatch(matchingRev.uris, rule.comparison);\n }\n return matchingRev !== undefined;\n}\n","import { RuleContext, SwitchCaseRule } from './index';\nimport { doesRuleMatch } from './doesRuleMatch';\n\nexport function findMatchingRules<T extends { rule: SwitchCaseRule }>(cases: T[], context: RuleContext) {\n /**\n * scope of if-else statements\n * each plain if (without else) increases the scope by 1\n * else branches are ignored if we already found a match in the current scope\n */\n let scope = 0;\n /**\n * scope of the previous rule that matched\n */\n let previousRuleMatched = -1;\n return cases.filter(it => {\n if (it.rule.else && previousRuleMatched == scope) {\n return false; // else branches are ignored if we already found a match in the current scope\n }\n if (!it.rule.else) {\n scope++; // plain if rule -> new scope\n }\n const match = doesRuleMatch(it.rule, context);\n if (match) {\n previousRuleMatched = scope; // found a match in the current if-else scope\n }\n return match;\n });\n}\n",":host {\n display: contents;\n}\n","import { Thing } from '@pod-os/core';\nimport { Component, Element, Event, h, State } from '@stencil/core';\nimport { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware';\nimport { combineLatest, map, of, Subject, takeUntil } from 'rxjs';\nimport { findMatchingRules, RuleContext, SwitchCaseRule } from './rules';\n\ninterface CaseWithRule {\n caseElement: HTMLPosCaseElement;\n rule: SwitchCaseRule;\n}\n\n/**\n * Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n * See [pos-case](https://pod-os.org/reference/elements/components/pos-switch/pos-case/) for available filter conditions.\n */\n@Component({\n tag: 'pos-switch',\n shadow: true,\n styleUrl: 'pos-switch.css',\n})\nexport class PosSwitch implements ResourceAware {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n @State() resource?: Thing;\n @State() cases: CaseWithRule[] = [];\n\n private readonly disconnected$ = new Subject<void>();\n\n @Event({ eventName: 'pod-os:resource' })\n subscribeResource!: ResourceEventEmitter;\n\n componentWillLoad() {\n const caseElements = Array.from(this.host.querySelectorAll('pos-case'));\n if (caseElements.length == 0) {\n this.error = 'No pos-case elements found';\n return;\n }\n // Do NOT await: awaiting a child @Method in componentWillLoad deadlocks the\n // lazy load graph (the child can't render until this component renders).\n // Build the rules once the children have upgraded, then subscribe to the resource\n Promise.all(\n caseElements.map(async it => ({\n rule: await it.getRule(),\n caseElement: it,\n })),\n ).then(cases => {\n this.cases = cases;\n subscribeResource(this);\n });\n }\n\n receiveResource = (resource: Thing) => {\n // reset any existing resource\n this.disconnected$.next();\n this.resource = resource;\n\n combineLatest([\n this.containsRule('if-typeof') ? resource.observeTypes() : of([]),\n this.containsRule('if-property') ? resource.observeLiterals() : of([]),\n this.containsRule('if-property') ? resource.observeRelations() : of([]),\n this.containsRule('if-rev') ? resource.observeReverseRelations() : of([]),\n ])\n .pipe(\n map(([types, literals, relations, reverseRelations]) => ({\n types,\n literals,\n relations,\n reverseRelations,\n })),\n takeUntil(this.disconnected$),\n )\n .subscribe((context: RuleContext) => {\n const activeElements = new Set(findMatchingRules(this.cases, context).map(it => it.caseElement));\n this.cases.forEach(it => {\n if (activeElements.has(it.caseElement)) {\n it.caseElement.setAttribute('active', '');\n } else {\n it.caseElement.removeAttribute('active');\n }\n });\n });\n };\n\n private containsRule(type: SwitchCaseRule['type']) {\n return this.cases.some(it => it.rule.type === type);\n }\n\n render() {\n if (this.error) {\n return this.error;\n }\n if (!this.resource) {\n return null;\n }\n\n return <slot></slot>;\n }\n\n disconnectedCallback() {\n this.disconnected$.next();\n this.disconnected$.complete();\n }\n}\n"],"mappings":"qMAOM,SAAUA,EAAcC,EAAkBC,GAC9C,MAAMC,SAAEA,EAAQC,SAAEA,EAAQC,OAAEA,GAAWH,EACvC,MAAMI,EAAUL,EAAOM,KAAIC,IACzB,IAAIC,EACJ,MAAMC,EAASC,OAAOH,GACtB,MAAMI,EAAYD,OAAON,GACzB,IAAKM,OAAOE,MAAMH,KAAYC,OAAOE,MAAMD,GAAY,CACrDH,EAAMC,EAASE,C,KACV,CACLH,EAAMK,OAAON,GAAKO,cAAcD,OAAOT,G,CAEzC,OAAQF,GACN,IAAK,KACH,OAAOM,IAAQ,EACjB,IAAK,KACH,OAAOA,EAAM,EACf,IAAK,MACH,OAAOA,GAAO,EAChB,IAAK,KACH,OAAOA,EAAM,EACf,IAAK,MACH,OAAOA,GAAO,E,IAGpB,GAAIL,GAAY,OAAQ,CACtB,OAAOE,EAAQU,KAAKC,Q,MACf,GAAIb,GAAY,QAAS,CAC9B,OAAOE,EAAQY,MAAMD,Q,KAChB,CACL,MAAM,IAAIE,MAAM,qBAAqBf,I,CAEzC,CClCM,SAAUgB,EAAcC,EAAsBC,GAClD,MAAMC,EAAaC,EAAaH,EAAMC,GACtC,OAAOD,EAAKI,KAAOF,EAAaA,CAClC,CAEA,SAASC,EAAaH,EAAsBC,GAC1C,OAAQD,EAAKK,MACX,IAAK,YACH,OAAOC,EAAcN,EAAMC,GAC7B,IAAK,cACH,OAAOM,EAAkBP,EAAMC,GACjC,IAAK,SACH,OAAOO,EAAyBR,EAAMC,GACxC,IAAK,OACH,OAAO,KACT,QACE,OAAO,M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KD,KAAKK,SAAU,CAClB,OAAO,I,CAGT,OAAOiC,EAAA,Y,CAGT,oBAAAC,GACEvC,KAAKE,cAAcI,OACnBN,KAAKE,cAAcsC,U","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{p as e,B as o,d as r,w as
|
|
1
|
+
import{p as e,B as o,d as r,w as a,N as t,H as i,g as n,b as l}from"./p-DHgULnQH.js";export{s as setNonce}from"./p-DHgULnQH.js";var p=()=>{if(o.isDev&&!o.isTesting){r("Running in development mode.")}if(o.cloneNodeFix){d(i.prototype)}const s=o.scriptDataOpts?a.document&&Array.from(a.document.querySelectorAll("script")).find((e=>new RegExp(`/${t}(\\.esm)?\\.js($|\\?|#)`).test(e.src)||e.getAttribute("data-stencil-namespace")===t)):null;const n=import.meta.url;const l=o.scriptDataOpts?(s||{})["data-opts"]||{}:{};if(n!==""){l.resourcesUrl=new URL(".",n).href}return e(l)};var d=e=>{const o=e.cloneNode;e.cloneNode=function(e){if(this.nodeName==="TEMPLATE"){return o.call(this,e)}const s=o.call(this,false);const r=this.childNodes;if(e){for(let e=0;e<r.length;e++){if(r[e].nodeType!==2){s.appendChild(r[e].cloneNode(true))}}}return s}};p().then((async e=>{await n();return l([["p-56f09e49",[[1,"pos-app-generic"]]],["p-c7876f5a",[[1,"pos-app-ldp-container"]]],["p-f0a03045",[[1,"pos-app-rdf-document"]]],["p-11e5e761",[[1,"pos-app-image-viewer",{resource:[32]}]]],["p-b8f4f44a",[[1,"pos-tool-attachments",{os:[32],resource:[32]}]]],["p-af7f2b1b",[[1,"pos-app-document-viewer",{resource:[32]}]]],["p-459ad102",[[0,"pos-list",{rel:[1],ifTypeof:[1,"if-typeof"],fetch:[4],error:[32],os:[32],resource:[32],items:[32],templateString:[32]}]]],["p-a16ec07a",[[0,"pos-case",{ifTypeof:[1,"if-typeof"],ifProperty:[1,"if-property"],ifRev:[1,"if-rev"],not:[4],else:[4],someValueEq:[1,"some-value-eq"],everyValueEq:[1,"every-value-eq"],someValueGt:[1,"some-value-gt"],everyValueGt:[1,"every-value-gt"],someValueGte:[1,"some-value-gte"],everyValueGte:[1,"every-value-gte"],someValueLt:[1,"some-value-lt"],everyValueLt:[1,"every-value-lt"],someValueLte:[1,"some-value-lte"],everyValueLte:[1,"every-value-lte"],active:[4],error:[32],getRule:[64]}]]],["p-7b27a836",[[257,"pos-switch",{error:[32],resource:[32],cases:[32]}]]],["p-eff1a928",[[1,"pos-value",{predicate:[513],resource:[32],value:[32]},null,{predicate:[{observeAnyValue:0}]}]]],["p-fa42a1b4",[[1,"pos-attachments",{resource:[32],attachments:[32],addToList:[64]}]]],["p-aeec72a8",[[1,"pos-container-contents",{container:[32],contents:[32],loading:[32],createNewItem:[32]},[[0,"keydown","handleKeyDown"]]]]],["p-f938e764",[[1,"pos-document",{src:[1],alt:[1],os:[32],file:[32],brokenFile:[32],error:[32],saveStatus:[32],loading:[32],isEditable:[32]},[[0,"pod-os:document-modified","handleDocumentModified"]],{os:[{fetchBlob:0}],src:[{fetchBlob:0}]}]]],["p-83f96998",[[0,"pos-app-browser",{restorePreviousSession:[4,"restore-previous-session"],mode:[1],uri:[32]}],[0,"pos-internal-router",{uri:[1]}],[257,"pos-login",{os:[32],customLoggedInComponent:[32]},[[4,"pod-os:logout","logout"],[4,"pod-os:login","onLogin"]]],[1,"pos-navigation",{uri:[1],os:[32],inputValue:[32],searchIndex:[32],suggestions:[32],selectedIndex:[32],resource:[32]},[[0,"pod-os:search:index-created","buildSearchIndex"],[0,"pod-os:search:index-updated","rebuildSearchIndex"],[0,"pod-os:navigate","openNavigationDialog"],[4,"click","closeDialog"],[0,"pod-os:link","clearSuggestions"],[0,"click","onClickSelf"],[0,"keydown","handleKeyDown"]],{uri:[{updateResource:0}],os:[{updateResource:0}]}],[1,"pos-user-menu",{webId:[1,"web-id"]},[[0,"sl-select","onSelect"]]],[1,"pos-add-new-thing",{referenceUri:[1,"reference-uri"]}],[1,"pos-type-router",{initialTool:[32],availableTools:[32],oldTool:[32],currentTool:[32],transitioning:[32]},[[0,"pod-os:tool-selected","handleToolSelected"]]],[257,"pos-app",{restorePreviousSession:[4,"restore-previous-session"],os:[32],unsubscribeSettings:[32],loading:[32]},[[0,"pod-os:init","initializeOs"],[0,"pod-os:module","loadModule"]]],[257,"pos-error-toast",{title:[32],message:[32]},[[8,"unhandledrejection","unhandledRejection"],[0,"pod-os:error","catchError"]]],[260,"pos-router",{mode:[1],uri:[32]},[[0,"pod-os:link","linkClicked"],[8,"pod-os:session-restored","sessionRestored"]]],[1,"pos-app-dashboard"],[1,"pos-navigation-bar",{current:[16],searchIndexReady:[4,"search-index-ready"]},[[4,"keydown","activate"]]],[1,"pos-app-settings"],[17,"pos-new-thing-form",{referenceUri:[1,"reference-uri"],os:[32],newUri:[32],name:[32],selectedTypeUri:[32],canSubmit:[32]},null,{name:[{validate:0}],selectedTypeUri:[{validate:0}]}],[17,"pos-login-form",{idpUrl:[32],canSubmit:[32],rememberMe:[32]},null,{idpUrl:[{validate:0}]}],[1,"pos-tool-select",{selected:[16],tools:[16]}],[1,"pos-type-index-entries",{uri:[1],entries:[32]}],[1,"pos-example-resources"],[1,"pos-make-findable",{uri:[1],os:[32],thing:[32],indexes:[32],unsubscribeSessionChange:[32],showOptions:[32],isIndexed:[32]},[[0,"sl-select","onSelect"]],{uri:[{updateUri:0}]}],[260,"pos-dialog",{showModal:[64],close:[64]}],[1,"pos-getting-started"],[1,"pos-setting-offline-cache"],[1,"pos-share",{uri:[1],apps:[32],os:[32]},[[4,"pod-os:resource-loaded","resourceLoaded"],[0,"sl-select","onSelect"]],{uri:[{updateApps:0}]}],[257,"pos-picture",{blurredBackground:[4,"blurred-background"],noUpload:[4,"no-upload"],resource:[32],os:[32],isUploading:[32]}],[1,"pos-image",{src:[1],alt:[1],blurredBackground:[4,"blurred-background"],os:[32],dataUri:[32],brokenFile:[32],networkError:[32],imageError:[32],loading:[32]},null,{os:[{fetchBlob:0}],src:[{fetchBlob:0}]}],[1,"pos-upload",{accept:[16],uploader:[16]}],[1,"pos-predicate",{uri:[1],label:[1],expanded:[32]}],[17,"pos-select-term",{placeholder:[1],value:[1],os:[32],terms:[32]},null,{os:[{setTerms:0}]}],[257,"pos-rich-link",{uri:[1],rel:[1],rev:[1],link:[32],followPredicate:[32],error:[32],showCustomContent:[32]}],[1,"pos-description",{description:[32]}],[1,"pos-label",{label:[32]}],[257,"pos-resource",{uri:[1],lazy:[4],os:[32],resource:[32],consumers:[32],error:[32],loading:[32],fetch:[64]},[[0,"pod-os:resource","provideResource"]],{os:[{loadResource:0}],uri:[{loadResource:0}]}]]],["p-d6f6edce",[[1,"pos-subjects",{data:[32]}]]],["p-0071209c",[[1,"pos-add-relation",{os:[32],resource:[32],selectedTermUri:[32],currentValue:[32]}]]],["p-6ce482b4",[[1,"pos-relations",{data:[32]}],[1,"pos-reverse-relations",{data:[32]}]]],["p-01fb754e",[[1,"pos-markdown-document",{file:[16],saveStatus:[1,"save-status"],editable:[4],markdown:[32],isModified:[32],isEditing:[32],startEditing:[64],stopEditing:[64]}]]],["p-d89e1a7a",[[257,"pos-container-item",{resource:[32]}],[1,"pos-container-toolbar"],[1,"pos-create-new-container-item",{type:[1],container:[16],os:[32],name:[32]}]]],["p-23321381",[[1,"pos-literals",{data:[32]}],[1,"pos-type-badges",{data:[32],typeLabels:[32],isExpanded:[32]}],[1,"pos-add-literal-value",{os:[32],resource:[32],currentValue:[32],selectedTermUri:[32]},null,{os:[{setName:0}]}]]]],e)}));
|
|
2
2
|
//# sourceMappingURL=elements.esm.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{r as t,c as e,h as r,a as s}from"./p-DHgULnQH.js";import{s as n}from"./p-BW_CkW1K.js";import{c as i}from"./p-vFMstSdt.js";function o(t,e){const{operator:r,semantic:s,target:n}=e;const i=t.map((t=>{let e;const s=Number(t);const i=Number(n);if(!Number.isNaN(s)&&!Number.isNaN(i)){e=s-i}else{e=String(t).localeCompare(String(n))}switch(r){case"eq":return e===0;case"gt":return e>0;case"gte":return e>=0;case"lt":return e<0;case"lte":return e<=0}}));if(s=="some"){return i.some(Boolean)}else if(s=="every"){return i.every(Boolean)}else{throw new Error(`Unknown semantic: ${s}`)}}function u(t,e){const r=c(t,e);return t.not?!r:r}function c(t,e){switch(t.type){case"if-typeof":return a(t,e);case"if-property":return l(t,e);case"if-rev":return f(t,e);case"else":return true;default:return false}}function a(t,e){return e.types.map((t=>t.uri)).includes(t.value)}function l(t,e){var r,s;const n=e.literals.find((e=>e.predicate==t.value));const i=e.relations.find((e=>e.predicate==t.value));if(t.comparison&&(n||i)){return o([...(r=n===null||n===void 0?void 0:n.values)!==null&&r!==void 0?r:[],...(s=i===null||i===void 0?void 0:i.uris)!==null&&s!==void 0?s:[]],t.comparison)}return n!==undefined||i!==undefined}function f(t,e){const r=e.reverseRelations.find((e=>e.predicate==t.value));if(t.comparison&&r){return o(r.uris,t.comparison)}return r!==undefined}function h(t,e){let r=0;let s=-1;return t.filter((t=>{if(t.rule.else&&s==r){return false}if(!t.rule.else){r++}const n=u(t.rule,e);if(n){s=r}return n}))}const p=()=>`:host{display:contents}`;const d=class{constructor(r){t(this,r);this.subscribeResource=e(this,"pod-os:resource",7);this.error=null;this.cases=[];this.disconnected$=new i.Subject;this.receiveResource=t=>{this.disconnected$.next();this.resource=t;i.combineLatest([this.containsRule("if-typeof")?t.observeTypes():i.of([]),this.containsRule("if-property")?t.observeLiterals():i.of([]),this.containsRule("if-property")?t.observeRelations():i.of([]),this.containsRule("if-rev")?t.observeReverseRelations():i.of([])]).pipe(i.map((([t,e,r,s])=>({types:t,literals:e,relations:r,reverseRelations:s}))),i.takeUntil(this.disconnected$)).subscribe((t=>{const e=new Set(h(this.cases,t).map((t=>t.caseElement)));this.cases.forEach((t=>{if(e.has(t.caseElement)){t.caseElement.setAttribute("active","")}else{t.caseElement.removeAttribute("active")}}))}))}}componentWillLoad(){const t=Array.from(this.host.querySelectorAll("pos-case"));if(t.length==0){this.error="No pos-case elements found";return}Promise.all(t.map((async t=>({rule:await t.getRule(),caseElement:t})))).then((t=>{this.cases=t;n(this)}))}containsRule(t){return this.cases.some((e=>e.rule.type===t))}render(){if(this.error){return this.error}if(!this.resource){return null}return r("slot",null)}disconnectedCallback(){this.disconnected$.next();this.disconnected$.complete()}get host(){return s(this)}};d.style=p();export{d as pos_switch};
|
|
2
|
+
//# sourceMappingURL=p-7b27a836.entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["doValuesMatch","values","comparison","operator","semantic","target","matches","map","val","cmp","numVal","Number","numTarget","isNaN","String","localeCompare","some","Boolean","every","Error","doesRuleMatch","rule","context","ruleResult","evaluateRule","not","type","doesTypeMatch","doesPropertyMatch","doesReverseRelationMatch","types","x","uri","includes","value","matchingLiteral","literals","find","it","predicate","matchingRelation","relations","_a","_b","uris","undefined","matchingRev","reverseRelations","findMatchingRules","cases","scope","previousRuleMatched","filter","else","match","posSwitchCss","PosSwitch","constructor","hostRef","this","error","disconnected$","Subject","receiveResource","resource","next","combineLatest","containsRule","observeTypes","of","observeLiterals","observeRelations","observeReverseRelations","pipe","takeUntil","subscribe","activeElements","Set","caseElement","forEach","has","setAttribute","removeAttribute","componentWillLoad","caseElements","Array","from","host","querySelectorAll","length","Promise","all","async","getRule","then","subscribeResource","render","h","disconnectedCallback","complete"],"sources":["src/components/pos-switch/rules/doValuesMatch.ts","src/components/pos-switch/rules/doesRuleMatch.ts","src/components/pos-switch/rules/findMatchingRules.ts","src/components/pos-switch/pos-switch.css?tag=pos-switch&encapsulation=shadow","src/components/pos-switch/pos-switch.tsx"],"sourcesContent":["import { Comparison } from './index';\n\n/**\n * Checks whether the given values match the given target according to the given comparison\n * @param values\n * @param comparison\n */\nexport function doValuesMatch(values: string[], comparison: Comparison): boolean {\n const { operator, semantic, target } = comparison;\n const matches = values.map(val => {\n let cmp;\n const numVal = Number(val);\n const numTarget = Number(target);\n if (!Number.isNaN(numVal) && !Number.isNaN(numTarget)) {\n cmp = numVal - numTarget;\n } else {\n cmp = String(val).localeCompare(String(target));\n }\n switch (operator) {\n case 'eq':\n return cmp === 0;\n case 'gt':\n return cmp > 0;\n case 'gte':\n return cmp >= 0;\n case 'lt':\n return cmp < 0;\n case 'lte':\n return cmp <= 0;\n }\n });\n if (semantic == 'some') {\n return matches.some(Boolean);\n } else if (semantic == 'every') {\n return matches.every(Boolean);\n } else {\n throw new Error(`Unknown semantic: ${semantic}`);\n }\n}\n","import { IfPropertyRule, IfRevRule, IfTypeofRule, RuleContext, SwitchCaseRule } from './index';\n\nimport { doValuesMatch } from './doValuesMatch';\n\nexport function doesRuleMatch(rule: SwitchCaseRule, context: RuleContext) {\n const ruleResult = evaluateRule(rule, context);\n return rule.not ? !ruleResult : ruleResult;\n}\n\nfunction evaluateRule(rule: SwitchCaseRule, context: RuleContext) {\n switch (rule.type) {\n case 'if-typeof':\n return doesTypeMatch(rule, context);\n case 'if-property':\n return doesPropertyMatch(rule, context);\n case 'if-rev':\n return doesReverseRelationMatch(rule, context);\n case 'else':\n return true;\n default:\n return false;\n }\n}\n\nfunction doesTypeMatch(rule: IfTypeofRule, context: RuleContext) {\n return context.types.map(x => x.uri).includes(rule.value);\n}\n\nfunction doesPropertyMatch(rule: IfPropertyRule, context: RuleContext) {\n const matchingLiteral = context.literals.find(it => it.predicate == rule.value);\n const matchingRelation = context.relations.find(it => it.predicate == rule.value);\n if (rule.comparison && (matchingLiteral || matchingRelation)) {\n return doValuesMatch([...(matchingLiteral?.values ?? []), ...(matchingRelation?.uris ?? [])], rule.comparison);\n }\n return matchingLiteral !== undefined || matchingRelation !== undefined;\n}\n\nfunction doesReverseRelationMatch(rule: IfRevRule, context: RuleContext) {\n const matchingRev = context.reverseRelations.find(x => x.predicate == rule.value);\n if (rule.comparison && matchingRev) {\n return doValuesMatch(matchingRev.uris, rule.comparison);\n }\n return matchingRev !== undefined;\n}\n","import { RuleContext, SwitchCaseRule } from './index';\nimport { doesRuleMatch } from './doesRuleMatch';\n\nexport function findMatchingRules<T extends { rule: SwitchCaseRule }>(cases: T[], context: RuleContext) {\n /**\n * scope of if-else statements\n * each plain if (without else) increases the scope by 1\n * else branches are ignored if we already found a match in the current scope\n */\n let scope = 0;\n /**\n * scope of the previous rule that matched\n */\n let previousRuleMatched = -1;\n return cases.filter(it => {\n if (it.rule.else && previousRuleMatched == scope) {\n return false; // else branches are ignored if we already found a match in the current scope\n }\n if (!it.rule.else) {\n scope++; // plain if rule -> new scope\n }\n const match = doesRuleMatch(it.rule, context);\n if (match) {\n previousRuleMatched = scope; // found a match in the current if-else scope\n }\n return match;\n });\n}\n",":host {\n display: contents;\n}\n","import { Thing } from '@pod-os/core';\nimport { Component, Element, Event, h, State } from '@stencil/core';\nimport { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware';\nimport { combineLatest, map, of, Subject, takeUntil } from 'rxjs';\nimport { findMatchingRules, RuleContext, SwitchCaseRule } from './rules';\n\ninterface CaseWithRule {\n caseElement: HTMLPosCaseElement;\n rule: SwitchCaseRule;\n}\n\n/**\n * Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n * See [pos-case](https://pod-os.org/reference/elements/components/pos-switch/pos-case/) for available filter conditions.\n */\n@Component({\n tag: 'pos-switch',\n shadow: true,\n styleUrl: 'pos-switch.css',\n})\nexport class PosSwitch implements ResourceAware {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n @State() resource?: Thing;\n @State() cases: CaseWithRule[] = [];\n\n private readonly disconnected$ = new Subject<void>();\n\n @Event({ eventName: 'pod-os:resource' })\n subscribeResource!: ResourceEventEmitter;\n\n componentWillLoad() {\n const caseElements = Array.from(this.host.querySelectorAll('pos-case'));\n if (caseElements.length == 0) {\n this.error = 'No pos-case elements found';\n return;\n }\n // Do NOT await: awaiting a child @Method in componentWillLoad deadlocks the\n // lazy load graph (the child can't render until this component renders).\n // Build the rules once the children have upgraded, then subscribe to the resource\n Promise.all(\n caseElements.map(async it => ({\n rule: await it.getRule(),\n caseElement: it,\n })),\n ).then(cases => {\n this.cases = cases;\n subscribeResource(this);\n });\n }\n\n receiveResource = (resource: Thing) => {\n // reset any existing resource\n this.disconnected$.next();\n this.resource = resource;\n\n combineLatest([\n this.containsRule('if-typeof') ? resource.observeTypes() : of([]),\n this.containsRule('if-property') ? resource.observeLiterals() : of([]),\n this.containsRule('if-property') ? resource.observeRelations() : of([]),\n this.containsRule('if-rev') ? resource.observeReverseRelations() : of([]),\n ])\n .pipe(\n map(([types, literals, relations, reverseRelations]) => ({\n types,\n literals,\n relations,\n reverseRelations,\n })),\n takeUntil(this.disconnected$),\n )\n .subscribe((context: RuleContext) => {\n const activeElements = new Set(findMatchingRules(this.cases, context).map(it => it.caseElement));\n this.cases.forEach(it => {\n if (activeElements.has(it.caseElement)) {\n it.caseElement.setAttribute('active', '');\n } else {\n it.caseElement.removeAttribute('active');\n }\n });\n });\n };\n\n private containsRule(type: SwitchCaseRule['type']) {\n return this.cases.some(it => it.rule.type === type);\n }\n\n render() {\n if (this.error) {\n return this.error;\n }\n if (!this.resource) {\n return null;\n }\n\n return <slot></slot>;\n }\n\n disconnectedCallback() {\n this.disconnected$.next();\n this.disconnected$.complete();\n }\n}\n"],"mappings":"iIAOM,SAAUA,EAAcC,EAAkBC,GAC9C,MAAMC,SAAEA,EAAQC,SAAEA,EAAQC,OAAEA,GAAWH,EACvC,MAAMI,EAAUL,EAAOM,KAAIC,IACzB,IAAIC,EACJ,MAAMC,EAASC,OAAOH,GACtB,MAAMI,EAAYD,OAAON,GACzB,IAAKM,OAAOE,MAAMH,KAAYC,OAAOE,MAAMD,GAAY,CACrDH,EAAMC,EAASE,C,KACV,CACLH,EAAMK,OAAON,GAAKO,cAAcD,OAAOT,G,CAEzC,OAAQF,GACN,IAAK,KACH,OAAOM,IAAQ,EACjB,IAAK,KACH,OAAOA,EAAM,EACf,IAAK,MACH,OAAOA,GAA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C,EAAGwC,YAAYI,gBAAgB,S,IAEjC,GACF,CAsBP,CAvEC,iBAAAC,GACE,MAAMC,EAAeC,MAAMC,KAAK3B,KAAK4B,KAAKC,iBAAiB,aAC3D,GAAIJ,EAAaK,QAAU,EAAG,CAC5B9B,KAAKC,MAAQ,6BACb,M,CAKF8B,QAAQC,IACNP,EAAa7E,KAAIqF,MAAMtD,IAAE,CACvBjB,WAAYiB,EAAGuD,UACff,YAAaxC,OAEfwD,MAAK7C,IACLU,KAAKV,MAAQA,EACb8C,EAAkBpC,KAAK,G,CAoCnB,YAAAQ,CAAazC,GACnB,OAAOiC,KAAKV,MAAMjC,MAAKsB,GAAMA,EAAGjB,KAAKK,OAASA,G,CAGhD,MAAAsE,GACE,GAAIrC,KAAKC,MAAO,CACd,OAAOD,KAAKC,K,CAEd,IAAKD,KAAKK,SAAU,CAClB,OAAO,I,CAGT,OAAOiC,EAAA,Y,CAGT,oBAAAC,GACEvC,KAAKE,cAAcI,OACnBN,KAAKE,cAAcsC,U","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as t,h as s,e,a as i}from"./p-DHgULnQH.js";const r={type:"never",not:false,else:false};const o={type:"else",not:false,else:true};const n=()=>`.error{background-color:var(--pos-error-background-color);border:1px solid var(--pos-error-border-color);padding:var(--size-3);border-radius:var(--radius-md)}`;const h=class{constructor(s){t(this,s);this.error=null;this.templateHTML=null;this.active=false}componentWillRender(){const t=[this.ifTypeof,this.ifProperty,this.ifRev].filter((t=>t!==undefined)).length;if(t>1){this.error='At most 1 "if-" must be present'}const s=[this.someValueLt,this.everyValueLt,this.someValueLte,this.everyValueLte,this.someValueEq,this.everyValueEq,this.someValueGte,this.everyValueGte,this.someValueGt,this.everyValueGt].filter((t=>t!==undefined)).length;if(s>1){this.error='At most 1 comparison ("every-" / "some-") must be present'}}async getRule(){const t={not:this.not,else:this.else};const s=this.getComparison();if(this.ifTypeof){return Object.assign({type:"if-typeof",value:this.ifTypeof},t)}if(this.ifProperty){return Object.assign(Object.assign({type:"if-property",value:this.ifProperty},t),{comparison:s})}if(this.ifRev){return Object.assign(Object.assign({type:"if-rev",value:this.ifRev},t),{comparison:s})}return this.else?o:r}getComparison(){var t,s,e,i,r,o,n,h,l;return(l=(h=(n=(o=(r=(i=(e=(s=(t=this.comparisonFor(this.someValueEq,"some","eq"))!==null&&t!==void 0?t:this.comparisonFor(this.everyValueEq,"every","eq"))!==null&&s!==void 0?s:this.comparisonFor(this.someValueGt,"some","gt"))!==null&&e!==void 0?e:this.comparisonFor(this.everyValueGt,"every","gt"))!==null&&i!==void 0?i:this.comparisonFor(this.someValueGte,"some","gte"))!==null&&r!==void 0?r:this.comparisonFor(this.everyValueGte,"every","gte"))!==null&&o!==void 0?o:this.comparisonFor(this.someValueLt,"some","lt"))!==null&&n!==void 0?n:this.comparisonFor(this.everyValueLt,"every","lt"))!==null&&h!==void 0?h:this.comparisonFor(this.someValueLte,"some","lte"))!==null&&l!==void 0?l:this.comparisonFor(this.everyValueLte,"every","lte")}comparisonFor(t,s,e){if(t){return{semantic:s,operator:e,target:t}}}componentWillLoad(){const t=this.host.querySelector("template");if(t==null){this.error="No template element found"}else{this.templateHTML=t.innerHTML}}render(){if(this.error)return s("div",{class:"error"},this.error);if(!this.active){return s(e,{innerHTML:""})}return s(e,{innerHTML:this.templateHTML})}get host(){return i(this)}};h.style=n();export{h as pos_case};
|
|
2
|
-
//# sourceMappingURL=p-
|
|
1
|
+
import{r as t,h as s,e,a as i}from"./p-DHgULnQH.js";const r={type:"never",not:false,else:false};const o={type:"else",not:false,else:true};const n=()=>`.error{background-color:var(--pos-error-background-color);border:1px solid var(--pos-error-border-color);padding:var(--size-3);border-radius:var(--radius-md)}`;const h=class{constructor(s){t(this,s);this.error=null;this.templateHTML=null;this.active=false}componentWillRender(){const t=[this.ifTypeof,this.ifProperty,this.ifRev].filter((t=>t!==undefined)).length;if(t>1){this.error='At most 1 "if-" must be present'}const s=[this.someValueLt,this.everyValueLt,this.someValueLte,this.everyValueLte,this.someValueEq,this.everyValueEq,this.someValueGte,this.everyValueGte,this.someValueGt,this.everyValueGt].filter((t=>t!==undefined)).length;if(s>1){this.error='At most 1 comparison ("every-" / "some-") must be present'}}async getRule(){const t={not:this.not,else:this.else};const s=this.getComparison();if(this.ifTypeof){return Object.assign({type:"if-typeof",value:this.ifTypeof},t)}if(this.ifProperty){return Object.assign(Object.assign({type:"if-property",value:this.ifProperty},t),{comparison:s})}if(this.ifRev){return Object.assign(Object.assign({type:"if-rev",value:this.ifRev},t),{comparison:s})}return this.else?o:r}getComparison(){var t,s,e,i,r,o,n,h,l;return(l=(h=(n=(o=(r=(i=(e=(s=(t=this.comparisonFor(this.someValueEq,"some","eq"))!==null&&t!==void 0?t:this.comparisonFor(this.everyValueEq,"every","eq"))!==null&&s!==void 0?s:this.comparisonFor(this.someValueGt,"some","gt"))!==null&&e!==void 0?e:this.comparisonFor(this.everyValueGt,"every","gt"))!==null&&i!==void 0?i:this.comparisonFor(this.someValueGte,"some","gte"))!==null&&r!==void 0?r:this.comparisonFor(this.everyValueGte,"every","gte"))!==null&&o!==void 0?o:this.comparisonFor(this.someValueLt,"some","lt"))!==null&&n!==void 0?n:this.comparisonFor(this.everyValueLt,"every","lt"))!==null&&h!==void 0?h:this.comparisonFor(this.someValueLte,"some","lte"))!==null&&l!==void 0?l:this.comparisonFor(this.everyValueLte,"every","lte")}comparisonFor(t,s,e){if(t){return{semantic:s,operator:e,target:t}}}componentWillLoad(){const t=this.host.querySelector("template");if(t==null){this.error="No template element found"}else{this.templateHTML=t.innerHTML}}render(){if(this.error)return s("div",{class:"error"},this.error);if(!this.active){return s(e,{innerHTML:""})}return s(e,{style:{display:"contents"},innerHTML:this.templateHTML})}get host(){return i(this)}};h.style=n();export{h as pos_case};
|
|
2
|
+
//# sourceMappingURL=p-a16ec07a.entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NEVER_RULE","type","not","else","ELSE_RULE","posCaseCss","PosCase","constructor","hostRef","this","error","templateHTML","active","componentWillRender","countRules","ifTypeof","ifProperty","ifRev","filter","it","undefined","length","countComparisons","someValueLt","everyValueLt","someValueLte","everyValueLte","someValueEq","everyValueEq","someValueGte","everyValueGte","someValueGt","everyValueGt","getRule","modifiers","comparison","getComparison","Object","assign","value","_j","_h","_g","_f","_e","_d","_c","_b","_a","comparisonFor","target","semantic","operator","componentWillLoad","templateElement","host","querySelector","innerHTML","render","h","class","Host","style","display"],"sources":["src/components/pos-switch/rules/index.ts","src/components/pos-switch/pos-case/pos-case.css?tag=pos-case","src/components/pos-switch/pos-case/pos-case.tsx"],"sourcesContent":["import { Literal, RdfType, Relation } from '@pod-os/core';\n\nexport { findMatchingRules } from './findMatchingRules';\n\n/**\n * A rule that matches if the resource is of a specific type\n */\nexport interface IfTypeofRule {\n type: 'if-typeof';\n /**\n * The URI of the type to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource is not of the specified type)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n}\n\n/**\n * A rule that matches if the resource has a specific property (literal or relation)\n */\nexport interface IfPropertyRule {\n type: 'if-property';\n /**\n * The value of the property to match against (either literal value or the URI of a relation)\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified property)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the value of the property matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that matches if the resource has a specific reverse relation\n */\nexport interface IfRevRule {\n type: 'if-rev';\n /**\n * The URI of the reverse relation to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified reverse relation)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the URI of the reverse relation matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that only matches if all others did not\n */\nexport interface ElseRule {\n type: 'else';\n not: false;\n else: true;\n}\n\n/**\n * A rule that never matches\n */\nexport interface NeverRule {\n type: 'never';\n not: false;\n else: false;\n}\n\n/**\n * A rule defined by a pos-case\n */\nexport type SwitchCaseRule = IfTypeofRule | IfPropertyRule | IfRevRule | ElseRule | NeverRule;\n\nexport const NEVER_RULE: NeverRule = {\n type: 'never',\n not: false,\n else: false,\n};\n\nexport const ELSE_RULE: ElseRule = {\n type: 'else',\n not: false,\n else: true,\n};\n\n/**\n * Contains the actual data a rule is matched against\n */\nexport interface RuleContext {\n types: RdfType[];\n literals: Literal[];\n relations: Relation[];\n reverseRelations: Relation[];\n}\n\n/**\n * Defines how to compare values to a specific target value\n */\nexport interface Comparison {\n /**\n * Does every value need to match, or only some?\n */\n semantic: Semantic;\n /**\n * The comparison operator to apply (e.g. value must be equal, greater than, etc.)\n */\n operator: Operator;\n /**\n * The target value to compare against.\n */\n target: string;\n}\n\nexport type equals = 'eq';\nexport type greaterThan = 'gt';\nexport type greaterThanOrEqual = 'gte';\nexport type lessThan = 'lt';\nexport type lessThanOrEqual = 'lte';\nexport type some = 'some';\nexport type every = 'every';\nexport type Operator = equals | greaterThan | greaterThanOrEqual | lessThan | lessThanOrEqual;\nexport type Semantic = some | every;\n",".error {\n background-color: var(--pos-error-background-color);\n border: 1px solid var(--pos-error-border-color);\n padding: var(--size-3);\n border-radius: var(--radius-md);\n}\n","import { Component, Element, h, Host, Method, Prop, State } from '@stencil/core';\nimport { Comparison, ELSE_RULE, NEVER_RULE, Operator, Semantic, SwitchCaseRule } from '../rules';\n\n/**\n * Defines a template to use if the specified condition is met - to be used with [pos-switch](https://pod-os.org/reference/elements/components/pos-switch/).\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n */\n@Component({\n tag: 'pos-case',\n shadow: false,\n styleUrl: 'pos-case.css',\n})\nexport class PosCase {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n private templateHTML: string | null = null;\n\n /**\n * Test if the resource is of the specified type\n */\n @Prop() ifTypeof?: string;\n /**\n * Test if the resource has the specified property (forward link)\n */\n @Prop() ifProperty?: string;\n /**\n * Test if the resource is the subject of the specified property (backward link)\n */\n @Prop() ifRev?: string;\n /**\n * Negates the result of the test\n */\n @Prop() not?: boolean;\n /**\n * The test only evaluates to true if tests for preceding cases have failed\n */\n @Prop() else?: boolean;\n /**\n * Test if some value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() someValueEq?: string;\n /**\n * Test if every value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() everyValueEq?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGt?: string;\n /**\n * Test if some value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGte?: string;\n /**\n * Test if every value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGte?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLt?: string;\n /**\n * Test if some value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLte?: string;\n /**\n * Test if every value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLte?: string;\n\n componentWillRender() {\n const countRules = [this.ifTypeof, this.ifProperty, this.ifRev].filter(it => it !== undefined).length;\n if (countRules > 1) {\n this.error = 'At most 1 \"if-\" must be present';\n }\n const countComparisons = [\n this.someValueLt,\n this.everyValueLt,\n this.someValueLte,\n this.everyValueLte,\n this.someValueEq,\n this.everyValueEq,\n this.someValueGte,\n this.everyValueGte,\n this.someValueGt,\n this.everyValueGt,\n ].filter(it => it !== undefined).length;\n if (countComparisons > 1) {\n this.error = 'At most 1 comparison (\"every-\" / \"some-\") must be present';\n }\n }\n\n /**\n * Whether this case is active, i.e. shown. Usually this is controlled by the surrounding pos-switch, and there is no need to set this manually.\n */\n @Prop() active = false;\n\n /**\n * Returns the rule definition for this case. The rule determines if the element's content gets rendered.\n */\n @Method()\n async getRule(): Promise<SwitchCaseRule> {\n const modifiers = {\n not: this.not,\n else: this.else,\n };\n const comparison = this.getComparison();\n if (this.ifTypeof) {\n return {\n type: 'if-typeof',\n value: this.ifTypeof,\n ...modifiers,\n };\n }\n if (this.ifProperty) {\n return {\n type: 'if-property',\n value: this.ifProperty,\n ...modifiers,\n comparison,\n };\n }\n if (this.ifRev) {\n return {\n type: 'if-rev',\n value: this.ifRev,\n ...modifiers,\n comparison,\n };\n }\n return this.else ? ELSE_RULE : NEVER_RULE;\n }\n\n private getComparison(): Comparison | undefined {\n return (\n this.comparisonFor(this.someValueEq, 'some', 'eq') ??\n this.comparisonFor(this.everyValueEq, 'every', 'eq') ??\n this.comparisonFor(this.someValueGt, 'some', 'gt') ??\n this.comparisonFor(this.everyValueGt, 'every', 'gt') ??\n this.comparisonFor(this.someValueGte, 'some', 'gte') ??\n this.comparisonFor(this.everyValueGte, 'every', 'gte') ??\n this.comparisonFor(this.someValueLt, 'some', 'lt') ??\n this.comparisonFor(this.everyValueLt, 'every', 'lt') ??\n this.comparisonFor(this.someValueLte, 'some', 'lte') ??\n this.comparisonFor(this.everyValueLte, 'every', 'lte')\n );\n }\n\n private comparisonFor(target: string | undefined, semantic: Semantic, operator: Operator): Comparison | undefined {\n if (target) {\n return { semantic, operator, target };\n }\n }\n\n componentWillLoad() {\n const templateElement = this.host.querySelector('template');\n if (templateElement == null) {\n this.error = 'No template element found';\n } else {\n this.templateHTML = templateElement.innerHTML;\n }\n }\n\n render() {\n if (this.error) return <div class=\"error\">{this.error}</div>;\n\n if (!this.active) {\n // because we set innerHTML for active case elements, we need to\n // unset it here to not leave state in the dom\n return <Host innerHTML=\"\"></Host>;\n }\n return <Host style={{ display: 'contents' }} innerHTML={this.templateHTML}></Host>;\n }\n}\n"],"mappings":"oDA4FO,MAAMA,EAAwB,CACnCC,KAAM,QACNC,IAAK,MACLC,KAAM,OAGD,MAAMC,EAAsB,CACjCH,KAAM,OACNC,IAAK,MACLC,KAAM,MCrGR,MAAME,EAAa,IAAM,iK,MCYZC,EAAO,MALpB,WAAAC,CAAAC,G,UAOWC,KAAAC,MAAuB,KACxBD,KAAAE,aAA8B,KAwF9BF,KAAAG,OAAS,KA8ElB,CAvGC,mBAAAC,GACE,MAAMC,EAAa,CAACL,KAAKM,SAAUN,KAAKO,WAAYP,KAAKQ,OAAOC,QAAOC,GAAMA,IAAOC,YAAWC,OAC/F,GAAIP,EAAa,EAAG,CAClBL,KAAKC,MAAQ,iC,CAEf,MAAMY,EAAmB,CACvBb,KAAKc,YACLd,KAAKe,aACLf,KAAKgB,aACLhB,KAAKiB,cACLjB,KAAKkB,YACLlB,KAAKmB,aACLnB,KAAKoB,aACLpB,KAAKqB,cACLrB,KAAKsB,YACLtB,KAAKuB,cACLd,QAAOC,GAAMA,IAAOC,YAAWC,OACjC,GAAIC,EAAmB,EAAG,CACxBb,KAAKC,MAAQ,2D,EAajB,aAAMuB,GACJ,MAAMC,EAAY,CAChBhC,IAAKO,KAAKP,IACVC,KAAMM,KAAKN,MAEb,MAAMgC,EAAa1B,KAAK2B,gBACxB,GAAI3B,KAAKM,SAAU,CACjB,OAAAsB,OAAAC,OAAA,CACErC,KAAM,YACNsC,MAAO9B,KAAKM,UACTmB,E,CAGP,GAAIzB,KAAKO,WAAY,CACnB,OAAAqB,OAAAC,OAAAD,OAAAC,OAAA,CACErC,KAAM,cACNsC,MAAO9B,KAAKO,YACTkB,GAAS,CACZC,c,CAGJ,GAAI1B,KAAKQ,MAAO,CACd,OAAAoB,OAAAC,OAAAD,OAAAC,OAAA,CACErC,KAAM,SACNs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,CAGhB,OAAO+C,EAACE,EAAI,CAACJ,UAAU,I,CAEzB,OAAOE,EAACE,EAAI,CAACC,MAAO,CAAEC,QAAS,YAAcN,UAAWhD,KAAKE,c","ignoreList":[]}
|
package/dist/esm/elements.js
CHANGED
|
@@ -43,7 +43,7 @@ var patchCloneNodeFix = (HTMLElementPrototype) => {
|
|
|
43
43
|
|
|
44
44
|
patchBrowser().then(async (options) => {
|
|
45
45
|
await globalScripts();
|
|
46
|
-
return bootstrapLazy([["pos-app-generic",[[1,"pos-app-generic"]]],["pos-app-ldp-container",[[1,"pos-app-ldp-container"]]],["pos-app-rdf-document",[[1,"pos-app-rdf-document"]]],["pos-app-image-viewer",[[1,"pos-app-image-viewer",{"resource":[32]}]]],["pos-tool-attachments",[[1,"pos-tool-attachments",{"os":[32],"resource":[32]}]]],["pos-app-document-viewer",[[1,"pos-app-document-viewer",{"resource":[32]}]]],["pos-list",[[0,"pos-list",{"rel":[1],"ifTypeof":[1,"if-typeof"],"fetch":[4],"error":[32],"os":[32],"resource":[32],"items":[32],"templateString":[32]}]]],["pos-case",[[0,"pos-case",{"ifTypeof":[1,"if-typeof"],"ifProperty":[1,"if-property"],"ifRev":[1,"if-rev"],"not":[4],"else":[4],"someValueEq":[1,"some-value-eq"],"everyValueEq":[1,"every-value-eq"],"someValueGt":[1,"some-value-gt"],"everyValueGt":[1,"every-value-gt"],"someValueGte":[1,"some-value-gte"],"everyValueGte":[1,"every-value-gte"],"someValueLt":[1,"some-value-lt"],"everyValueLt":[1,"every-value-lt"],"someValueLte":[1,"some-value-lte"],"everyValueLte":[1,"every-value-lte"],"active":[4],"error":[32],"getRule":[64]}]]],["pos-switch",[[257,"pos-switch",{"error":[32],"resource":[32],"cases":[32]}]]],["pos-value",[[1,"pos-value",{"predicate":[513],"resource":[32],"value":[32]},null,{"predicate":[{"observeAnyValue":0}]}]]],["pos-attachments",[[1,"pos-attachments",{"resource":[32],"attachments":[32],"addToList":[64]}]]],["pos-container-contents",[[1,"pos-container-contents",{"container":[32],"contents":[32],"loading":[32],"createNewItem":[32]},[[0,"keydown","handleKeyDown"]]]]],["pos-document",[[1,"pos-document",{"src":[1],"alt":[1],"os":[32],"file":[32],"brokenFile":[32],"error":[32],"saveStatus":[32],"loading":[32],"isEditable":[32]},[[0,"pod-os:document-modified","handleDocumentModified"]],{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}]]],["pos-add-new-thing_32",[[0,"pos-app-browser",{"restorePreviousSession":[4,"restore-previous-session"],"mode":[1],"uri":[32]}],[0,"pos-internal-router",{"uri":[1]}],[257,"pos-login",{"os":[32],"customLoggedInComponent":[32]},[[4,"pod-os:logout","logout"],[4,"pod-os:login","onLogin"]]],[1,"pos-navigation",{"uri":[1],"os":[32],"inputValue":[32],"searchIndex":[32],"suggestions":[32],"selectedIndex":[32],"resource":[32]},[[0,"pod-os:search:index-created","buildSearchIndex"],[0,"pod-os:search:index-updated","rebuildSearchIndex"],[0,"pod-os:navigate","openNavigationDialog"],[4,"click","closeDialog"],[0,"pod-os:link","clearSuggestions"],[0,"click","onClickSelf"],[0,"keydown","handleKeyDown"]],{"uri":[{"updateResource":0}],"os":[{"updateResource":0}]}],[1,"pos-user-menu",{"webId":[1,"web-id"]},[[0,"sl-select","onSelect"]]],[1,"pos-add-new-thing",{"referenceUri":[1,"reference-uri"]}],[1,"pos-type-router",{"initialTool":[32],"availableTools":[32],"oldTool":[32],"currentTool":[32],"transitioning":[32]},[[0,"pod-os:tool-selected","handleToolSelected"]]],[257,"pos-app",{"restorePreviousSession":[4,"restore-previous-session"],"os":[32],"unsubscribeSettings":[32],"loading":[32]},[[0,"pod-os:init","initializeOs"],[0,"pod-os:module","loadModule"]]],[257,"pos-error-toast",{"title":[32],"message":[32]},[[8,"unhandledrejection","unhandledRejection"],[0,"pod-os:error","catchError"]]],[260,"pos-router",{"mode":[1],"uri":[32]},[[0,"pod-os:link","linkClicked"],[8,"pod-os:session-restored","sessionRestored"]]],[1,"pos-app-dashboard"],[1,"pos-navigation-bar",{"current":[16],"searchIndexReady":[4,"search-index-ready"]},[[4,"keydown","activate"]]],[1,"pos-app-settings"],[17,"pos-new-thing-form",{"referenceUri":[1,"reference-uri"],"os":[32],"newUri":[32],"name":[32],"selectedTypeUri":[32],"canSubmit":[32]},null,{"name":[{"validate":0}],"selectedTypeUri":[{"validate":0}]}],[17,"pos-login-form",{"idpUrl":[32],"canSubmit":[32],"rememberMe":[32]},null,{"idpUrl":[{"validate":0}]}],[1,"pos-tool-select",{"selected":[16],"tools":[16]}],[1,"pos-type-index-entries",{"uri":[1],"entries":[32]}],[1,"pos-example-resources"],[1,"pos-make-findable",{"uri":[1],"os":[32],"thing":[32],"indexes":[32],"unsubscribeSessionChange":[32],"showOptions":[32],"isIndexed":[32]},[[0,"sl-select","onSelect"]],{"uri":[{"updateUri":0}]}],[260,"pos-dialog",{"showModal":[64],"close":[64]}],[1,"pos-getting-started"],[1,"pos-setting-offline-cache"],[1,"pos-share",{"uri":[1],"apps":[32],"os":[32]},[[4,"pod-os:resource-loaded","resourceLoaded"],[0,"sl-select","onSelect"]],{"uri":[{"updateApps":0}]}],[257,"pos-picture",{"blurredBackground":[4,"blurred-background"],"noUpload":[4,"no-upload"],"resource":[32],"os":[32],"isUploading":[32]}],[1,"pos-image",{"src":[1],"alt":[1],"blurredBackground":[4,"blurred-background"],"os":[32],"dataUri":[32],"brokenFile":[32],"networkError":[32],"imageError":[32],"loading":[32]},null,{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}],[1,"pos-upload",{"accept":[16],"uploader":[16]}],[1,"pos-predicate",{"uri":[1],"label":[1],"expanded":[32]}],[17,"pos-select-term",{"placeholder":[1],"value":[1],"os":[32],"terms":[32]},null,{"os":[{"setTerms":0}]}],[257,"pos-rich-link",{"uri":[1],"rel":[1],"rev":[1],"link":[32],"followPredicate":[32],"error":[32],"showCustomContent":[32]}],[1,"pos-description",{"description":[32]}],[1,"pos-label",{"label":[32]}],[257,"pos-resource",{"uri":[1],"lazy":[4],"os":[32],"resource":[32],"consumers":[32],"error":[32],"loading":[32],"fetch":[64]},[[0,"pod-os:resource","provideResource"]],{"os":[{"loadResource":0}],"uri":[{"loadResource":0}]}]]],["pos-
|
|
46
|
+
return bootstrapLazy([["pos-app-generic",[[1,"pos-app-generic"]]],["pos-app-ldp-container",[[1,"pos-app-ldp-container"]]],["pos-app-rdf-document",[[1,"pos-app-rdf-document"]]],["pos-app-image-viewer",[[1,"pos-app-image-viewer",{"resource":[32]}]]],["pos-tool-attachments",[[1,"pos-tool-attachments",{"os":[32],"resource":[32]}]]],["pos-app-document-viewer",[[1,"pos-app-document-viewer",{"resource":[32]}]]],["pos-list",[[0,"pos-list",{"rel":[1],"ifTypeof":[1,"if-typeof"],"fetch":[4],"error":[32],"os":[32],"resource":[32],"items":[32],"templateString":[32]}]]],["pos-case",[[0,"pos-case",{"ifTypeof":[1,"if-typeof"],"ifProperty":[1,"if-property"],"ifRev":[1,"if-rev"],"not":[4],"else":[4],"someValueEq":[1,"some-value-eq"],"everyValueEq":[1,"every-value-eq"],"someValueGt":[1,"some-value-gt"],"everyValueGt":[1,"every-value-gt"],"someValueGte":[1,"some-value-gte"],"everyValueGte":[1,"every-value-gte"],"someValueLt":[1,"some-value-lt"],"everyValueLt":[1,"every-value-lt"],"someValueLte":[1,"some-value-lte"],"everyValueLte":[1,"every-value-lte"],"active":[4],"error":[32],"getRule":[64]}]]],["pos-switch",[[257,"pos-switch",{"error":[32],"resource":[32],"cases":[32]}]]],["pos-value",[[1,"pos-value",{"predicate":[513],"resource":[32],"value":[32]},null,{"predicate":[{"observeAnyValue":0}]}]]],["pos-attachments",[[1,"pos-attachments",{"resource":[32],"attachments":[32],"addToList":[64]}]]],["pos-container-contents",[[1,"pos-container-contents",{"container":[32],"contents":[32],"loading":[32],"createNewItem":[32]},[[0,"keydown","handleKeyDown"]]]]],["pos-document",[[1,"pos-document",{"src":[1],"alt":[1],"os":[32],"file":[32],"brokenFile":[32],"error":[32],"saveStatus":[32],"loading":[32],"isEditable":[32]},[[0,"pod-os:document-modified","handleDocumentModified"]],{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}]]],["pos-add-new-thing_32",[[0,"pos-app-browser",{"restorePreviousSession":[4,"restore-previous-session"],"mode":[1],"uri":[32]}],[0,"pos-internal-router",{"uri":[1]}],[257,"pos-login",{"os":[32],"customLoggedInComponent":[32]},[[4,"pod-os:logout","logout"],[4,"pod-os:login","onLogin"]]],[1,"pos-navigation",{"uri":[1],"os":[32],"inputValue":[32],"searchIndex":[32],"suggestions":[32],"selectedIndex":[32],"resource":[32]},[[0,"pod-os:search:index-created","buildSearchIndex"],[0,"pod-os:search:index-updated","rebuildSearchIndex"],[0,"pod-os:navigate","openNavigationDialog"],[4,"click","closeDialog"],[0,"pod-os:link","clearSuggestions"],[0,"click","onClickSelf"],[0,"keydown","handleKeyDown"]],{"uri":[{"updateResource":0}],"os":[{"updateResource":0}]}],[1,"pos-user-menu",{"webId":[1,"web-id"]},[[0,"sl-select","onSelect"]]],[1,"pos-add-new-thing",{"referenceUri":[1,"reference-uri"]}],[1,"pos-type-router",{"initialTool":[32],"availableTools":[32],"oldTool":[32],"currentTool":[32],"transitioning":[32]},[[0,"pod-os:tool-selected","handleToolSelected"]]],[257,"pos-app",{"restorePreviousSession":[4,"restore-previous-session"],"os":[32],"unsubscribeSettings":[32],"loading":[32]},[[0,"pod-os:init","initializeOs"],[0,"pod-os:module","loadModule"]]],[257,"pos-error-toast",{"title":[32],"message":[32]},[[8,"unhandledrejection","unhandledRejection"],[0,"pod-os:error","catchError"]]],[260,"pos-router",{"mode":[1],"uri":[32]},[[0,"pod-os:link","linkClicked"],[8,"pod-os:session-restored","sessionRestored"]]],[1,"pos-app-dashboard"],[1,"pos-navigation-bar",{"current":[16],"searchIndexReady":[4,"search-index-ready"]},[[4,"keydown","activate"]]],[1,"pos-app-settings"],[17,"pos-new-thing-form",{"referenceUri":[1,"reference-uri"],"os":[32],"newUri":[32],"name":[32],"selectedTypeUri":[32],"canSubmit":[32]},null,{"name":[{"validate":0}],"selectedTypeUri":[{"validate":0}]}],[17,"pos-login-form",{"idpUrl":[32],"canSubmit":[32],"rememberMe":[32]},null,{"idpUrl":[{"validate":0}]}],[1,"pos-tool-select",{"selected":[16],"tools":[16]}],[1,"pos-type-index-entries",{"uri":[1],"entries":[32]}],[1,"pos-example-resources"],[1,"pos-make-findable",{"uri":[1],"os":[32],"thing":[32],"indexes":[32],"unsubscribeSessionChange":[32],"showOptions":[32],"isIndexed":[32]},[[0,"sl-select","onSelect"]],{"uri":[{"updateUri":0}]}],[260,"pos-dialog",{"showModal":[64],"close":[64]}],[1,"pos-getting-started"],[1,"pos-setting-offline-cache"],[1,"pos-share",{"uri":[1],"apps":[32],"os":[32]},[[4,"pod-os:resource-loaded","resourceLoaded"],[0,"sl-select","onSelect"]],{"uri":[{"updateApps":0}]}],[257,"pos-picture",{"blurredBackground":[4,"blurred-background"],"noUpload":[4,"no-upload"],"resource":[32],"os":[32],"isUploading":[32]}],[1,"pos-image",{"src":[1],"alt":[1],"blurredBackground":[4,"blurred-background"],"os":[32],"dataUri":[32],"brokenFile":[32],"networkError":[32],"imageError":[32],"loading":[32]},null,{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}],[1,"pos-upload",{"accept":[16],"uploader":[16]}],[1,"pos-predicate",{"uri":[1],"label":[1],"expanded":[32]}],[17,"pos-select-term",{"placeholder":[1],"value":[1],"os":[32],"terms":[32]},null,{"os":[{"setTerms":0}]}],[257,"pos-rich-link",{"uri":[1],"rel":[1],"rev":[1],"link":[32],"followPredicate":[32],"error":[32],"showCustomContent":[32]}],[1,"pos-description",{"description":[32]}],[1,"pos-label",{"label":[32]}],[257,"pos-resource",{"uri":[1],"lazy":[4],"os":[32],"resource":[32],"consumers":[32],"error":[32],"loading":[32],"fetch":[64]},[[0,"pod-os:resource","provideResource"]],{"os":[{"loadResource":0}],"uri":[{"loadResource":0}]}]]],["pos-subjects",[[1,"pos-subjects",{"data":[32]}]]],["pos-add-relation",[[1,"pos-add-relation",{"os":[32],"resource":[32],"selectedTermUri":[32],"currentValue":[32]}]]],["pos-relations_2",[[1,"pos-relations",{"data":[32]}],[1,"pos-reverse-relations",{"data":[32]}]]],["pos-markdown-document",[[1,"pos-markdown-document",{"file":[16],"saveStatus":[1,"save-status"],"editable":[4],"markdown":[32],"isModified":[32],"isEditing":[32],"startEditing":[64],"stopEditing":[64]}]]],["pos-container-item_3",[[257,"pos-container-item",{"resource":[32]}],[1,"pos-container-toolbar"],[1,"pos-create-new-container-item",{"type":[1],"container":[16],"os":[32],"name":[32]}]]],["pos-add-literal-value_3",[[1,"pos-literals",{"data":[32]}],[1,"pos-type-badges",{"data":[32],"typeLabels":[32],"isExpanded":[32]}],[1,"pos-add-literal-value",{"os":[32],"resource":[32],"currentValue":[32],"selectedTermUri":[32]},null,{"os":[{"setName":0}]}]]]], options);
|
|
47
47
|
});
|
|
48
48
|
//# sourceMappingURL=elements.js.map
|
|
49
49
|
|
package/dist/esm/loader.js
CHANGED
|
@@ -4,7 +4,7 @@ export { s as setNonce } from './index-DHgULnQH.js';
|
|
|
4
4
|
const defineCustomElements = async (win, options) => {
|
|
5
5
|
if (typeof window === 'undefined') return undefined;
|
|
6
6
|
await globalScripts();
|
|
7
|
-
return bootstrapLazy([["pos-app-generic",[[1,"pos-app-generic"]]],["pos-app-ldp-container",[[1,"pos-app-ldp-container"]]],["pos-app-rdf-document",[[1,"pos-app-rdf-document"]]],["pos-app-image-viewer",[[1,"pos-app-image-viewer",{"resource":[32]}]]],["pos-tool-attachments",[[1,"pos-tool-attachments",{"os":[32],"resource":[32]}]]],["pos-app-document-viewer",[[1,"pos-app-document-viewer",{"resource":[32]}]]],["pos-list",[[0,"pos-list",{"rel":[1],"ifTypeof":[1,"if-typeof"],"fetch":[4],"error":[32],"os":[32],"resource":[32],"items":[32],"templateString":[32]}]]],["pos-case",[[0,"pos-case",{"ifTypeof":[1,"if-typeof"],"ifProperty":[1,"if-property"],"ifRev":[1,"if-rev"],"not":[4],"else":[4],"someValueEq":[1,"some-value-eq"],"everyValueEq":[1,"every-value-eq"],"someValueGt":[1,"some-value-gt"],"everyValueGt":[1,"every-value-gt"],"someValueGte":[1,"some-value-gte"],"everyValueGte":[1,"every-value-gte"],"someValueLt":[1,"some-value-lt"],"everyValueLt":[1,"every-value-lt"],"someValueLte":[1,"some-value-lte"],"everyValueLte":[1,"every-value-lte"],"active":[4],"error":[32],"getRule":[64]}]]],["pos-switch",[[257,"pos-switch",{"error":[32],"resource":[32],"cases":[32]}]]],["pos-value",[[1,"pos-value",{"predicate":[513],"resource":[32],"value":[32]},null,{"predicate":[{"observeAnyValue":0}]}]]],["pos-attachments",[[1,"pos-attachments",{"resource":[32],"attachments":[32],"addToList":[64]}]]],["pos-container-contents",[[1,"pos-container-contents",{"container":[32],"contents":[32],"loading":[32],"createNewItem":[32]},[[0,"keydown","handleKeyDown"]]]]],["pos-document",[[1,"pos-document",{"src":[1],"alt":[1],"os":[32],"file":[32],"brokenFile":[32],"error":[32],"saveStatus":[32],"loading":[32],"isEditable":[32]},[[0,"pod-os:document-modified","handleDocumentModified"]],{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}]]],["pos-add-new-thing_32",[[0,"pos-app-browser",{"restorePreviousSession":[4,"restore-previous-session"],"mode":[1],"uri":[32]}],[0,"pos-internal-router",{"uri":[1]}],[257,"pos-login",{"os":[32],"customLoggedInComponent":[32]},[[4,"pod-os:logout","logout"],[4,"pod-os:login","onLogin"]]],[1,"pos-navigation",{"uri":[1],"os":[32],"inputValue":[32],"searchIndex":[32],"suggestions":[32],"selectedIndex":[32],"resource":[32]},[[0,"pod-os:search:index-created","buildSearchIndex"],[0,"pod-os:search:index-updated","rebuildSearchIndex"],[0,"pod-os:navigate","openNavigationDialog"],[4,"click","closeDialog"],[0,"pod-os:link","clearSuggestions"],[0,"click","onClickSelf"],[0,"keydown","handleKeyDown"]],{"uri":[{"updateResource":0}],"os":[{"updateResource":0}]}],[1,"pos-user-menu",{"webId":[1,"web-id"]},[[0,"sl-select","onSelect"]]],[1,"pos-add-new-thing",{"referenceUri":[1,"reference-uri"]}],[1,"pos-type-router",{"initialTool":[32],"availableTools":[32],"oldTool":[32],"currentTool":[32],"transitioning":[32]},[[0,"pod-os:tool-selected","handleToolSelected"]]],[257,"pos-app",{"restorePreviousSession":[4,"restore-previous-session"],"os":[32],"unsubscribeSettings":[32],"loading":[32]},[[0,"pod-os:init","initializeOs"],[0,"pod-os:module","loadModule"]]],[257,"pos-error-toast",{"title":[32],"message":[32]},[[8,"unhandledrejection","unhandledRejection"],[0,"pod-os:error","catchError"]]],[260,"pos-router",{"mode":[1],"uri":[32]},[[0,"pod-os:link","linkClicked"],[8,"pod-os:session-restored","sessionRestored"]]],[1,"pos-app-dashboard"],[1,"pos-navigation-bar",{"current":[16],"searchIndexReady":[4,"search-index-ready"]},[[4,"keydown","activate"]]],[1,"pos-app-settings"],[17,"pos-new-thing-form",{"referenceUri":[1,"reference-uri"],"os":[32],"newUri":[32],"name":[32],"selectedTypeUri":[32],"canSubmit":[32]},null,{"name":[{"validate":0}],"selectedTypeUri":[{"validate":0}]}],[17,"pos-login-form",{"idpUrl":[32],"canSubmit":[32],"rememberMe":[32]},null,{"idpUrl":[{"validate":0}]}],[1,"pos-tool-select",{"selected":[16],"tools":[16]}],[1,"pos-type-index-entries",{"uri":[1],"entries":[32]}],[1,"pos-example-resources"],[1,"pos-make-findable",{"uri":[1],"os":[32],"thing":[32],"indexes":[32],"unsubscribeSessionChange":[32],"showOptions":[32],"isIndexed":[32]},[[0,"sl-select","onSelect"]],{"uri":[{"updateUri":0}]}],[260,"pos-dialog",{"showModal":[64],"close":[64]}],[1,"pos-getting-started"],[1,"pos-setting-offline-cache"],[1,"pos-share",{"uri":[1],"apps":[32],"os":[32]},[[4,"pod-os:resource-loaded","resourceLoaded"],[0,"sl-select","onSelect"]],{"uri":[{"updateApps":0}]}],[257,"pos-picture",{"blurredBackground":[4,"blurred-background"],"noUpload":[4,"no-upload"],"resource":[32],"os":[32],"isUploading":[32]}],[1,"pos-image",{"src":[1],"alt":[1],"blurredBackground":[4,"blurred-background"],"os":[32],"dataUri":[32],"brokenFile":[32],"networkError":[32],"imageError":[32],"loading":[32]},null,{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}],[1,"pos-upload",{"accept":[16],"uploader":[16]}],[1,"pos-predicate",{"uri":[1],"label":[1],"expanded":[32]}],[17,"pos-select-term",{"placeholder":[1],"value":[1],"os":[32],"terms":[32]},null,{"os":[{"setTerms":0}]}],[257,"pos-rich-link",{"uri":[1],"rel":[1],"rev":[1],"link":[32],"followPredicate":[32],"error":[32],"showCustomContent":[32]}],[1,"pos-description",{"description":[32]}],[1,"pos-label",{"label":[32]}],[257,"pos-resource",{"uri":[1],"lazy":[4],"os":[32],"resource":[32],"consumers":[32],"error":[32],"loading":[32],"fetch":[64]},[[0,"pod-os:resource","provideResource"]],{"os":[{"loadResource":0}],"uri":[{"loadResource":0}]}]]],["pos-
|
|
7
|
+
return bootstrapLazy([["pos-app-generic",[[1,"pos-app-generic"]]],["pos-app-ldp-container",[[1,"pos-app-ldp-container"]]],["pos-app-rdf-document",[[1,"pos-app-rdf-document"]]],["pos-app-image-viewer",[[1,"pos-app-image-viewer",{"resource":[32]}]]],["pos-tool-attachments",[[1,"pos-tool-attachments",{"os":[32],"resource":[32]}]]],["pos-app-document-viewer",[[1,"pos-app-document-viewer",{"resource":[32]}]]],["pos-list",[[0,"pos-list",{"rel":[1],"ifTypeof":[1,"if-typeof"],"fetch":[4],"error":[32],"os":[32],"resource":[32],"items":[32],"templateString":[32]}]]],["pos-case",[[0,"pos-case",{"ifTypeof":[1,"if-typeof"],"ifProperty":[1,"if-property"],"ifRev":[1,"if-rev"],"not":[4],"else":[4],"someValueEq":[1,"some-value-eq"],"everyValueEq":[1,"every-value-eq"],"someValueGt":[1,"some-value-gt"],"everyValueGt":[1,"every-value-gt"],"someValueGte":[1,"some-value-gte"],"everyValueGte":[1,"every-value-gte"],"someValueLt":[1,"some-value-lt"],"everyValueLt":[1,"every-value-lt"],"someValueLte":[1,"some-value-lte"],"everyValueLte":[1,"every-value-lte"],"active":[4],"error":[32],"getRule":[64]}]]],["pos-switch",[[257,"pos-switch",{"error":[32],"resource":[32],"cases":[32]}]]],["pos-value",[[1,"pos-value",{"predicate":[513],"resource":[32],"value":[32]},null,{"predicate":[{"observeAnyValue":0}]}]]],["pos-attachments",[[1,"pos-attachments",{"resource":[32],"attachments":[32],"addToList":[64]}]]],["pos-container-contents",[[1,"pos-container-contents",{"container":[32],"contents":[32],"loading":[32],"createNewItem":[32]},[[0,"keydown","handleKeyDown"]]]]],["pos-document",[[1,"pos-document",{"src":[1],"alt":[1],"os":[32],"file":[32],"brokenFile":[32],"error":[32],"saveStatus":[32],"loading":[32],"isEditable":[32]},[[0,"pod-os:document-modified","handleDocumentModified"]],{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}]]],["pos-add-new-thing_32",[[0,"pos-app-browser",{"restorePreviousSession":[4,"restore-previous-session"],"mode":[1],"uri":[32]}],[0,"pos-internal-router",{"uri":[1]}],[257,"pos-login",{"os":[32],"customLoggedInComponent":[32]},[[4,"pod-os:logout","logout"],[4,"pod-os:login","onLogin"]]],[1,"pos-navigation",{"uri":[1],"os":[32],"inputValue":[32],"searchIndex":[32],"suggestions":[32],"selectedIndex":[32],"resource":[32]},[[0,"pod-os:search:index-created","buildSearchIndex"],[0,"pod-os:search:index-updated","rebuildSearchIndex"],[0,"pod-os:navigate","openNavigationDialog"],[4,"click","closeDialog"],[0,"pod-os:link","clearSuggestions"],[0,"click","onClickSelf"],[0,"keydown","handleKeyDown"]],{"uri":[{"updateResource":0}],"os":[{"updateResource":0}]}],[1,"pos-user-menu",{"webId":[1,"web-id"]},[[0,"sl-select","onSelect"]]],[1,"pos-add-new-thing",{"referenceUri":[1,"reference-uri"]}],[1,"pos-type-router",{"initialTool":[32],"availableTools":[32],"oldTool":[32],"currentTool":[32],"transitioning":[32]},[[0,"pod-os:tool-selected","handleToolSelected"]]],[257,"pos-app",{"restorePreviousSession":[4,"restore-previous-session"],"os":[32],"unsubscribeSettings":[32],"loading":[32]},[[0,"pod-os:init","initializeOs"],[0,"pod-os:module","loadModule"]]],[257,"pos-error-toast",{"title":[32],"message":[32]},[[8,"unhandledrejection","unhandledRejection"],[0,"pod-os:error","catchError"]]],[260,"pos-router",{"mode":[1],"uri":[32]},[[0,"pod-os:link","linkClicked"],[8,"pod-os:session-restored","sessionRestored"]]],[1,"pos-app-dashboard"],[1,"pos-navigation-bar",{"current":[16],"searchIndexReady":[4,"search-index-ready"]},[[4,"keydown","activate"]]],[1,"pos-app-settings"],[17,"pos-new-thing-form",{"referenceUri":[1,"reference-uri"],"os":[32],"newUri":[32],"name":[32],"selectedTypeUri":[32],"canSubmit":[32]},null,{"name":[{"validate":0}],"selectedTypeUri":[{"validate":0}]}],[17,"pos-login-form",{"idpUrl":[32],"canSubmit":[32],"rememberMe":[32]},null,{"idpUrl":[{"validate":0}]}],[1,"pos-tool-select",{"selected":[16],"tools":[16]}],[1,"pos-type-index-entries",{"uri":[1],"entries":[32]}],[1,"pos-example-resources"],[1,"pos-make-findable",{"uri":[1],"os":[32],"thing":[32],"indexes":[32],"unsubscribeSessionChange":[32],"showOptions":[32],"isIndexed":[32]},[[0,"sl-select","onSelect"]],{"uri":[{"updateUri":0}]}],[260,"pos-dialog",{"showModal":[64],"close":[64]}],[1,"pos-getting-started"],[1,"pos-setting-offline-cache"],[1,"pos-share",{"uri":[1],"apps":[32],"os":[32]},[[4,"pod-os:resource-loaded","resourceLoaded"],[0,"sl-select","onSelect"]],{"uri":[{"updateApps":0}]}],[257,"pos-picture",{"blurredBackground":[4,"blurred-background"],"noUpload":[4,"no-upload"],"resource":[32],"os":[32],"isUploading":[32]}],[1,"pos-image",{"src":[1],"alt":[1],"blurredBackground":[4,"blurred-background"],"os":[32],"dataUri":[32],"brokenFile":[32],"networkError":[32],"imageError":[32],"loading":[32]},null,{"os":[{"fetchBlob":0}],"src":[{"fetchBlob":0}]}],[1,"pos-upload",{"accept":[16],"uploader":[16]}],[1,"pos-predicate",{"uri":[1],"label":[1],"expanded":[32]}],[17,"pos-select-term",{"placeholder":[1],"value":[1],"os":[32],"terms":[32]},null,{"os":[{"setTerms":0}]}],[257,"pos-rich-link",{"uri":[1],"rel":[1],"rev":[1],"link":[32],"followPredicate":[32],"error":[32],"showCustomContent":[32]}],[1,"pos-description",{"description":[32]}],[1,"pos-label",{"label":[32]}],[257,"pos-resource",{"uri":[1],"lazy":[4],"os":[32],"resource":[32],"consumers":[32],"error":[32],"loading":[32],"fetch":[64]},[[0,"pod-os:resource","provideResource"]],{"os":[{"loadResource":0}],"uri":[{"loadResource":0}]}]]],["pos-subjects",[[1,"pos-subjects",{"data":[32]}]]],["pos-add-relation",[[1,"pos-add-relation",{"os":[32],"resource":[32],"selectedTermUri":[32],"currentValue":[32]}]]],["pos-relations_2",[[1,"pos-relations",{"data":[32]}],[1,"pos-reverse-relations",{"data":[32]}]]],["pos-markdown-document",[[1,"pos-markdown-document",{"file":[16],"saveStatus":[1,"save-status"],"editable":[4],"markdown":[32],"isModified":[32],"isEditing":[32],"startEditing":[64],"stopEditing":[64]}]]],["pos-container-item_3",[[257,"pos-container-item",{"resource":[32]}],[1,"pos-container-toolbar"],[1,"pos-create-new-container-item",{"type":[1],"container":[16],"os":[32],"name":[32]}]]],["pos-add-literal-value_3",[[1,"pos-literals",{"data":[32]}],[1,"pos-type-badges",{"data":[32],"typeLabels":[32],"isExpanded":[32]}],[1,"pos-add-literal-value",{"os":[32],"resource":[32],"currentValue":[32],"selectedTermUri":[32]},null,{"os":[{"setName":0}]}]]]], options);
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export { defineCustomElements };
|
|
@@ -90,7 +90,7 @@ const PosCase = class {
|
|
|
90
90
|
// unset it here to not leave state in the dom
|
|
91
91
|
return h(Host, { innerHTML: "" });
|
|
92
92
|
}
|
|
93
|
-
return h(Host, { innerHTML: this.templateHTML });
|
|
93
|
+
return h(Host, { style: { display: 'contents' }, innerHTML: this.templateHTML });
|
|
94
94
|
}
|
|
95
95
|
get host() { return getElement(this); }
|
|
96
96
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pos-case.entry.js","sources":["src/components/pos-switch/rules/index.ts","src/components/pos-switch/pos-case/pos-case.css?tag=pos-case","src/components/pos-switch/pos-case/pos-case.tsx"],"sourcesContent":["import { Literal, RdfType, Relation } from '@pod-os/core';\n\nexport { findMatchingRules } from './findMatchingRules';\n\n/**\n * A rule that matches if the resource is of a specific type\n */\nexport interface IfTypeofRule {\n type: 'if-typeof';\n /**\n * The URI of the type to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource is not of the specified type)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n}\n\n/**\n * A rule that matches if the resource has a specific property (literal or relation)\n */\nexport interface IfPropertyRule {\n type: 'if-property';\n /**\n * The value of the property to match against (either literal value or the URI of a relation)\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified property)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the value of the property matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that matches if the resource has a specific reverse relation\n */\nexport interface IfRevRule {\n type: 'if-rev';\n /**\n * The URI of the reverse relation to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified reverse relation)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the URI of the reverse relation matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that only matches if all others did not\n */\nexport interface ElseRule {\n type: 'else';\n not: false;\n else: true;\n}\n\n/**\n * A rule that never matches\n */\nexport interface NeverRule {\n type: 'never';\n not: false;\n else: false;\n}\n\n/**\n * A rule defined by a pos-case\n */\nexport type SwitchCaseRule = IfTypeofRule | IfPropertyRule | IfRevRule | ElseRule | NeverRule;\n\nexport const NEVER_RULE: NeverRule = {\n type: 'never',\n not: false,\n else: false,\n};\n\nexport const ELSE_RULE: ElseRule = {\n type: 'else',\n not: false,\n else: true,\n};\n\n/**\n * Contains the actual data a rule is matched against\n */\nexport interface RuleContext {\n types: RdfType[];\n literals: Literal[];\n relations: Relation[];\n reverseRelations: Relation[];\n}\n\n/**\n * Defines how to compare values to a specific target value\n */\nexport interface Comparison {\n /**\n * Does every value need to match, or only some?\n */\n semantic: Semantic;\n /**\n * The comparison operator to apply (e.g. value must be equal, greater than, etc.)\n */\n operator: Operator;\n /**\n * The target value to compare against.\n */\n target: string;\n}\n\nexport type equals = 'eq';\nexport type greaterThan = 'gt';\nexport type greaterThanOrEqual = 'gte';\nexport type lessThan = 'lt';\nexport type lessThanOrEqual = 'lte';\nexport type some = 'some';\nexport type every = 'every';\nexport type Operator = equals | greaterThan | greaterThanOrEqual | lessThan | lessThanOrEqual;\nexport type Semantic = some | every;\n",".error {\n background-color: var(--pos-error-background-color);\n border: 1px solid var(--pos-error-border-color);\n padding: var(--size-3);\n border-radius: var(--radius-md);\n}\n","import { Component, Element, h, Host, Method, Prop, State } from '@stencil/core';\nimport { Comparison, ELSE_RULE, NEVER_RULE, Operator, Semantic, SwitchCaseRule } from '../rules';\n\n/**\n * Defines a template to use if the specified condition is met - to be used with [pos-switch](https://pod-os.org/reference/elements/components/pos-switch/).\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n */\n@Component({\n tag: 'pos-case',\n shadow: false,\n styleUrl: 'pos-case.css',\n})\nexport class PosCase {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n private templateHTML: string | null = null;\n\n /**\n * Test if the resource is of the specified type\n */\n @Prop() ifTypeof?: string;\n /**\n * Test if the resource has the specified property (forward link)\n */\n @Prop() ifProperty?: string;\n /**\n * Test if the resource is the subject of the specified property (backward link)\n */\n @Prop() ifRev?: string;\n /**\n * Negates the result of the test\n */\n @Prop() not?: boolean;\n /**\n * The test only evaluates to true if tests for preceding cases have failed\n */\n @Prop() else?: boolean;\n /**\n * Test if some value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() someValueEq?: string;\n /**\n * Test if every value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() everyValueEq?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGt?: string;\n /**\n * Test if some value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGte?: string;\n /**\n * Test if every value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGte?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLt?: string;\n /**\n * Test if some value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLte?: string;\n /**\n * Test if every value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLte?: string;\n\n componentWillRender() {\n const countRules = [this.ifTypeof, this.ifProperty, this.ifRev].filter(it => it !== undefined).length;\n if (countRules > 1) {\n this.error = 'At most 1 \"if-\" must be present';\n }\n const countComparisons = [\n this.someValueLt,\n this.everyValueLt,\n this.someValueLte,\n this.everyValueLte,\n this.someValueEq,\n this.everyValueEq,\n this.someValueGte,\n this.everyValueGte,\n this.someValueGt,\n this.everyValueGt,\n ].filter(it => it !== undefined).length;\n if (countComparisons > 1) {\n this.error = 'At most 1 comparison (\"every-\" / \"some-\") must be present';\n }\n }\n\n /**\n * Whether this case is active, i.e. shown. Usually this is controlled by the surrounding pos-switch, and there is no need to set this manually.\n */\n @Prop() active = false;\n\n /**\n * Returns the rule definition for this case. The rule determines if the element's content gets rendered.\n */\n @Method()\n async getRule(): Promise<SwitchCaseRule> {\n const modifiers = {\n not: this.not,\n else: this.else,\n };\n const comparison = this.getComparison();\n if (this.ifTypeof) {\n return {\n type: 'if-typeof',\n value: this.ifTypeof,\n ...modifiers,\n };\n }\n if (this.ifProperty) {\n return {\n type: 'if-property',\n value: this.ifProperty,\n ...modifiers,\n comparison,\n };\n }\n if (this.ifRev) {\n return {\n type: 'if-rev',\n value: this.ifRev,\n ...modifiers,\n comparison,\n };\n }\n return this.else ? ELSE_RULE : NEVER_RULE;\n }\n\n private getComparison(): Comparison | undefined {\n return (\n this.comparisonFor(this.someValueEq, 'some', 'eq') ??\n this.comparisonFor(this.everyValueEq, 'every', 'eq') ??\n this.comparisonFor(this.someValueGt, 'some', 'gt') ??\n this.comparisonFor(this.everyValueGt, 'every', 'gt') ??\n this.comparisonFor(this.someValueGte, 'some', 'gte') ??\n this.comparisonFor(this.everyValueGte, 'every', 'gte') ??\n this.comparisonFor(this.someValueLt, 'some', 'lt') ??\n this.comparisonFor(this.everyValueLt, 'every', 'lt') ??\n this.comparisonFor(this.someValueLte, 'some', 'lte') ??\n this.comparisonFor(this.everyValueLte, 'every', 'lte')\n );\n }\n\n private comparisonFor(target: string | undefined, semantic: Semantic, operator: Operator): Comparison | undefined {\n if (target) {\n return { semantic, operator, target };\n }\n }\n\n componentWillLoad() {\n const templateElement = this.host.querySelector('template');\n if (templateElement == null) {\n this.error = 'No template element found';\n } else {\n this.templateHTML = templateElement.innerHTML;\n }\n }\n\n render() {\n if (this.error) return <div class=\"error\">{this.error}</div>;\n\n if (!this.active) {\n // because we set innerHTML for active case elements, we need to\n // unset it here to not leave state in the dom\n return <Host innerHTML=\"\"></Host>;\n }\n return <Host innerHTML={this.templateHTML}></Host>;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BAAiB,GAAA;QACf,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC;AAC3D,QAAA,IAAI,eAAe,IAAI,IAAI,EAAE;AAC3B,YAAA,IAAI,CAAC,KAAK,GAAG,2BAA2B;;aACnC;AACL,YAAA,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC,SAAS;;;IAIjD,MAAM,GAAA;QACJ,IAAI,IAAI,CAAC,KAAK;AAAE,YAAA,OAAO,CAAA,CAAA,KAAA,EAAA,EAAK,KAAK,EAAC,OAAO,IAAE,IAAI,CAAC,KAAK,CAAO;AAE5D,QAAA,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;;;YAGhB,OAAO,EAAC,IAAI,EAAA,EAAC,SAAS,EAAC,EAAE,GAAQ;;AAEnC,QAAA,OAAO,CAAA,CAAC,IAAI,EAAA,EAAC,SAAS,EAAE,IAAI,CAAC,YAAY,EAAA,CAAS;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"pos-case.entry.js","sources":["src/components/pos-switch/rules/index.ts","src/components/pos-switch/pos-case/pos-case.css?tag=pos-case","src/components/pos-switch/pos-case/pos-case.tsx"],"sourcesContent":["import { Literal, RdfType, Relation } from '@pod-os/core';\n\nexport { findMatchingRules } from './findMatchingRules';\n\n/**\n * A rule that matches if the resource is of a specific type\n */\nexport interface IfTypeofRule {\n type: 'if-typeof';\n /**\n * The URI of the type to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource is not of the specified type)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n}\n\n/**\n * A rule that matches if the resource has a specific property (literal or relation)\n */\nexport interface IfPropertyRule {\n type: 'if-property';\n /**\n * The value of the property to match against (either literal value or the URI of a relation)\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified property)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the value of the property matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that matches if the resource has a specific reverse relation\n */\nexport interface IfRevRule {\n type: 'if-rev';\n /**\n * The URI of the reverse relation to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified reverse relation)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the URI of the reverse relation matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that only matches if all others did not\n */\nexport interface ElseRule {\n type: 'else';\n not: false;\n else: true;\n}\n\n/**\n * A rule that never matches\n */\nexport interface NeverRule {\n type: 'never';\n not: false;\n else: false;\n}\n\n/**\n * A rule defined by a pos-case\n */\nexport type SwitchCaseRule = IfTypeofRule | IfPropertyRule | IfRevRule | ElseRule | NeverRule;\n\nexport const NEVER_RULE: NeverRule = {\n type: 'never',\n not: false,\n else: false,\n};\n\nexport const ELSE_RULE: ElseRule = {\n type: 'else',\n not: false,\n else: true,\n};\n\n/**\n * Contains the actual data a rule is matched against\n */\nexport interface RuleContext {\n types: RdfType[];\n literals: Literal[];\n relations: Relation[];\n reverseRelations: Relation[];\n}\n\n/**\n * Defines how to compare values to a specific target value\n */\nexport interface Comparison {\n /**\n * Does every value need to match, or only some?\n */\n semantic: Semantic;\n /**\n * The comparison operator to apply (e.g. value must be equal, greater than, etc.)\n */\n operator: Operator;\n /**\n * The target value to compare against.\n */\n target: string;\n}\n\nexport type equals = 'eq';\nexport type greaterThan = 'gt';\nexport type greaterThanOrEqual = 'gte';\nexport type lessThan = 'lt';\nexport type lessThanOrEqual = 'lte';\nexport type some = 'some';\nexport type every = 'every';\nexport type Operator = equals | greaterThan | greaterThanOrEqual | lessThan | lessThanOrEqual;\nexport type Semantic = some | every;\n",".error {\n background-color: var(--pos-error-background-color);\n border: 1px solid var(--pos-error-border-color);\n padding: var(--size-3);\n border-radius: var(--radius-md);\n}\n","import { Component, Element, h, Host, Method, Prop, State } from '@stencil/core';\nimport { Comparison, ELSE_RULE, NEVER_RULE, Operator, Semantic, SwitchCaseRule } from '../rules';\n\n/**\n * Defines a template to use if the specified condition is met - to be used with [pos-switch](https://pod-os.org/reference/elements/components/pos-switch/).\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n */\n@Component({\n tag: 'pos-case',\n shadow: false,\n styleUrl: 'pos-case.css',\n})\nexport class PosCase {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n private templateHTML: string | null = null;\n\n /**\n * Test if the resource is of the specified type\n */\n @Prop() ifTypeof?: string;\n /**\n * Test if the resource has the specified property (forward link)\n */\n @Prop() ifProperty?: string;\n /**\n * Test if the resource is the subject of the specified property (backward link)\n */\n @Prop() ifRev?: string;\n /**\n * Negates the result of the test\n */\n @Prop() not?: boolean;\n /**\n * The test only evaluates to true if tests for preceding cases have failed\n */\n @Prop() else?: boolean;\n /**\n * Test if some value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() someValueEq?: string;\n /**\n * Test if every value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() everyValueEq?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGt?: string;\n /**\n * Test if some value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGte?: string;\n /**\n * Test if every value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGte?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLt?: string;\n /**\n * Test if some value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLte?: string;\n /**\n * Test if every value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLte?: string;\n\n componentWillRender() {\n const countRules = [this.ifTypeof, this.ifProperty, this.ifRev].filter(it => it !== undefined).length;\n if (countRules > 1) {\n this.error = 'At most 1 \"if-\" must be present';\n }\n const countComparisons = [\n this.someValueLt,\n this.everyValueLt,\n this.someValueLte,\n this.everyValueLte,\n this.someValueEq,\n this.everyValueEq,\n this.someValueGte,\n this.everyValueGte,\n this.someValueGt,\n this.everyValueGt,\n ].filter(it => it !== undefined).length;\n if (countComparisons > 1) {\n this.error = 'At most 1 comparison (\"every-\" / \"some-\") must be present';\n }\n }\n\n /**\n * Whether this case is active, i.e. shown. Usually this is controlled by the surrounding pos-switch, and there is no need to set this manually.\n */\n @Prop() active = false;\n\n /**\n * Returns the rule definition for this case. The rule determines if the element's content gets rendered.\n */\n @Method()\n async getRule(): Promise<SwitchCaseRule> {\n const modifiers = {\n not: this.not,\n else: this.else,\n };\n const comparison = this.getComparison();\n if (this.ifTypeof) {\n return {\n type: 'if-typeof',\n value: this.ifTypeof,\n ...modifiers,\n };\n }\n if (this.ifProperty) {\n return {\n type: 'if-property',\n value: this.ifProperty,\n ...modifiers,\n comparison,\n };\n }\n if (this.ifRev) {\n return {\n type: 'if-rev',\n value: this.ifRev,\n ...modifiers,\n comparison,\n };\n }\n return this.else ? ELSE_RULE : NEVER_RULE;\n }\n\n private getComparison(): Comparison | undefined {\n return (\n this.comparisonFor(this.someValueEq, 'some', 'eq') ??\n this.comparisonFor(this.everyValueEq, 'every', 'eq') ??\n this.comparisonFor(this.someValueGt, 'some', 'gt') ??\n this.comparisonFor(this.everyValueGt, 'every', 'gt') ??\n this.comparisonFor(this.someValueGte, 'some', 'gte') ??\n this.comparisonFor(this.everyValueGte, 'every', 'gte') ??\n this.comparisonFor(this.someValueLt, 'some', 'lt') ??\n this.comparisonFor(this.everyValueLt, 'every', 'lt') ??\n this.comparisonFor(this.someValueLte, 'some', 'lte') ??\n this.comparisonFor(this.everyValueLte, 'every', 'lte')\n );\n }\n\n private comparisonFor(target: string | undefined, semantic: Semantic, operator: Operator): Comparison | undefined {\n if (target) {\n return { semantic, operator, target };\n }\n }\n\n componentWillLoad() {\n const templateElement = this.host.querySelector('template');\n if (templateElement == null) {\n this.error = 'No template element found';\n } else {\n this.templateHTML = templateElement.innerHTML;\n }\n }\n\n render() {\n if (this.error) return <div class=\"error\">{this.error}</div>;\n\n if (!this.active) {\n // because we set innerHTML for active case elements, we need to\n // unset it here to not leave state in the dom\n return <Host innerHTML=\"\"></Host>;\n }\n return <Host style={{ display: 'contents' }} innerHTML={this.templateHTML}></Host>;\n }\n}\n"],"names":[],"mappings":";;AA4FO,MAAM,UAAU,GAAc;AACnC,IAAA,IAAI,EAAE,OAAO;AACb,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,IAAI,EAAE,KAAK;CACZ;AAEM,MAAM,SAAS,GAAa;AACjC,IAAA,IAAI,EAAE,MAAM;AACZ,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,IAAI,EAAE,IAAI;CACX;;ACtGD,MAAM,UAAU,GAAG,MAAM,CAAC,8JAA8J,CAAC;;MCY5K,OAAO,GAAA,MAAA;AALpB,IAAA,WAAA,CAAA,OAAA,EAAA;;AAOW,QAAA,IAAA,CAAA,KAAK,GAAkB,IAAI;AAC5B,QAAA,IAAA,CAAA,YAAY,GAAkB,IAAI;AAqF1C;;AAEG;AACK,QAAA,IAAA,CAAA,MAAM,GAAG,KAAK;AA8EvB;IAvGC,mBAAmB,GAAA;AACjB,QAAA,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,SAAS,CAAC,CAAC,MAAM;AACrG,QAAA,IAAI,UAAU,GAAG,CAAC,EAAE;AAClB,YAAA,IAAI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= class {
|
|
111
113
|
constructor(hostRef) {
|
|
112
114
|
registerInstance(this, hostRef);
|
|
@@ -178,6 +180,7 @@ const PosSwitch = class {
|
|
|
178
180
|
}
|
|
179
181
|
get host() { return getElement(this); }
|
|
180
182
|
};
|
|
183
|
+
PosSwitch.style = posSwitchCss();
|
|
181
184
|
|
|
182
185
|
export { PosSwitch as pos_switch };
|
|
183
186
|
//# sourceMappingURL=pos-switch.entry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pos-switch.entry.js","sources":["src/components/pos-switch/rules/doValuesMatch.ts","src/components/pos-switch/rules/doesRuleMatch.ts","src/components/pos-switch/rules/findMatchingRules.ts","src/components/pos-switch/pos-switch.tsx"],"sourcesContent":["import { Comparison } from './index';\n\n/**\n * Checks whether the given values match the given target according to the given comparison\n * @param values\n * @param comparison\n */\nexport function doValuesMatch(values: string[], comparison: Comparison): boolean {\n const { operator, semantic, target } = comparison;\n const matches = values.map(val => {\n let cmp;\n const numVal = Number(val);\n const numTarget = Number(target);\n if (!Number.isNaN(numVal) && !Number.isNaN(numTarget)) {\n cmp = numVal - numTarget;\n } else {\n cmp = String(val).localeCompare(String(target));\n }\n switch (operator) {\n case 'eq':\n return cmp === 0;\n case 'gt':\n return cmp > 0;\n case 'gte':\n return cmp >= 0;\n case 'lt':\n return cmp < 0;\n case 'lte':\n return cmp <= 0;\n }\n });\n if (semantic == 'some') {\n return matches.some(Boolean);\n } else if (semantic == 'every') {\n return matches.every(Boolean);\n } else {\n throw new Error(`Unknown semantic: ${semantic}`);\n }\n}\n","import { IfPropertyRule, IfRevRule, IfTypeofRule, RuleContext, SwitchCaseRule } from './index';\n\nimport { doValuesMatch } from './doValuesMatch';\n\nexport function doesRuleMatch(rule: SwitchCaseRule, context: RuleContext) {\n const ruleResult = evaluateRule(rule, context);\n return rule.not ? !ruleResult : ruleResult;\n}\n\nfunction evaluateRule(rule: SwitchCaseRule, context: RuleContext) {\n switch (rule.type) {\n case 'if-typeof':\n return doesTypeMatch(rule, context);\n case 'if-property':\n return doesPropertyMatch(rule, context);\n case 'if-rev':\n return doesReverseRelationMatch(rule, context);\n case 'else':\n return true;\n default:\n return false;\n }\n}\n\nfunction doesTypeMatch(rule: IfTypeofRule, context: RuleContext) {\n return context.types.map(x => x.uri).includes(rule.value);\n}\n\nfunction doesPropertyMatch(rule: IfPropertyRule, context: RuleContext) {\n const matchingLiteral = context.literals.find(it => it.predicate == rule.value);\n const matchingRelation = context.relations.find(it => it.predicate == rule.value);\n if (rule.comparison && (matchingLiteral || matchingRelation)) {\n return doValuesMatch([...(matchingLiteral?.values ?? []), ...(matchingRelation?.uris ?? [])], rule.comparison);\n }\n return matchingLiteral !== undefined || matchingRelation !== undefined;\n}\n\nfunction doesReverseRelationMatch(rule: IfRevRule, context: RuleContext) {\n const matchingRev = context.reverseRelations.find(x => x.predicate == rule.value);\n if (rule.comparison && matchingRev) {\n return doValuesMatch(matchingRev.uris, rule.comparison);\n }\n return matchingRev !== undefined;\n}\n","import { RuleContext, SwitchCaseRule } from './index';\nimport { doesRuleMatch } from './doesRuleMatch';\n\nexport function findMatchingRules<T extends { rule: SwitchCaseRule }>(cases: T[], context: RuleContext) {\n /**\n * scope of if-else statements\n * each plain if (without else) increases the scope by 1\n * else branches are ignored if we already found a match in the current scope\n */\n let scope = 0;\n /**\n * scope of the previous rule that matched\n */\n let previousRuleMatched = -1;\n return cases.filter(it => {\n if (it.rule.else && previousRuleMatched == scope) {\n return false; // else branches are ignored if we already found a match in the current scope\n }\n if (!it.rule.else) {\n scope++; // plain if rule -> new scope\n }\n const match = doesRuleMatch(it.rule, context);\n if (match) {\n previousRuleMatched = scope; // found a match in the current if-else scope\n }\n return match;\n });\n}\n","import { Thing } from '@pod-os/core';\nimport { Component, Element, Event, h, State } from '@stencil/core';\nimport { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware';\nimport { combineLatest, map, of, Subject, takeUntil } from 'rxjs';\nimport { findMatchingRules, RuleContext, SwitchCaseRule } from './rules';\n\ninterface CaseWithRule {\n caseElement: HTMLPosCaseElement;\n rule: SwitchCaseRule;\n}\n\n/**\n * Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n * See [pos-case](https://pod-os.org/reference/elements/components/pos-switch/pos-case/) for available filter conditions.\n */\n@Component({\n tag: 'pos-switch',\n shadow: true,\n})\nexport class PosSwitch implements ResourceAware {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n @State() resource?: Thing;\n @State() cases: CaseWithRule[] = [];\n\n private readonly disconnected$ = new Subject<void>();\n\n @Event({ eventName: 'pod-os:resource' })\n subscribeResource!: ResourceEventEmitter;\n\n componentWillLoad() {\n const caseElements = Array.from(this.host.querySelectorAll('pos-case'));\n if (caseElements.length == 0) {\n this.error = 'No pos-case elements found';\n return;\n }\n // Do NOT await: awaiting a child @Method in componentWillLoad deadlocks the\n // lazy load graph (the child can't render until this component renders).\n // Build the rules once the children have upgraded, then subscribe to the resource\n Promise.all(\n caseElements.map(async it => ({\n rule: await it.getRule(),\n caseElement: it,\n })),\n ).then(cases => {\n this.cases = cases;\n subscribeResource(this);\n });\n }\n\n receiveResource = (resource: Thing) => {\n // reset any existing resource\n this.disconnected$.next();\n this.resource = resource;\n\n combineLatest([\n this.containsRule('if-typeof') ? resource.observeTypes() : of([]),\n this.containsRule('if-property') ? resource.observeLiterals() : of([]),\n this.containsRule('if-property') ? resource.observeRelations() : of([]),\n this.containsRule('if-rev') ? resource.observeReverseRelations() : of([]),\n ])\n .pipe(\n map(([types, literals, relations, reverseRelations]) => ({\n types,\n literals,\n relations,\n reverseRelations,\n })),\n takeUntil(this.disconnected$),\n )\n .subscribe((context: RuleContext) => {\n const activeElements = new Set(findMatchingRules(this.cases, context).map(it => it.caseElement));\n this.cases.forEach(it => {\n if (activeElements.has(it.caseElement)) {\n it.caseElement.setAttribute('active', '');\n } else {\n it.caseElement.removeAttribute('active');\n }\n });\n });\n };\n\n private containsRule(type: SwitchCaseRule['type']) {\n return this.cases.some(it => it.rule.type === type);\n }\n\n render() {\n if (this.error) {\n return this.error;\n }\n if (!this.resource) {\n return null;\n }\n\n return <slot></slot>;\n }\n\n disconnectedCallback() {\n this.disconnected$.next();\n this.disconnected$.complete();\n }\n}\n"],"names":["Subject","combineLatest","of","map","takeUntil"],"mappings":";;;;AAEA;;;;AAIG;AACG,SAAU,aAAa,CAAC,MAAgB,EAAE,UAAsB,EAAA;IACpE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAU;IACjD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,IAAG;AAC/B,QAAA,IAAI,GAAG;AACP,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC;AAC1B,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;AAChC,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;AACrD,YAAA,GAAG,GAAG,MAAM,GAAG,SAAS;;aACnB;AACL,YAAA,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;;QAEjD,QAAQ,QAAQ;AACd,YAAA,KAAK,IAAI;gBACP,OAAO,GAAG,KAAK,CAAC;AAClB,YAAA,KAAK,IAAI;gBACP,OAAO,GAAG,GAAG,CAAC;AAChB,YAAA,KAAK,KAAK;gBACR,OAAO,GAAG,IAAI,CAAC;AACjB,YAAA,KAAK,IAAI;gBACP,OAAO,GAAG,GAAG,CAAC;AAChB,YAAA,KAAK,KAAK;gBACR,OAAO,GAAG,IAAI,CAAC;;AAErB,KAAC,CAAC;AACF,IAAA,IAAI,QAAQ,IAAI,MAAM,EAAE;AACtB,QAAA,OAAO,OAAO,CAAC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AAC,IAA4B,EAAA;AAC/C,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;;IAGrD,MAAM,GAAA;AACJ,QAAA,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,OAAO,IAAI,CAAC,KAAK;;AAEnB,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AAClB,YAAA,OAAO,IAAI;;AAGb,QAAA,OAAO,eAAa;;IAGtB,oBAAoB,GAAA;AAClB,QAAA,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE;AACzB,QAAA,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"pos-switch.entry.js","sources":["src/components/pos-switch/rules/doValuesMatch.ts","src/components/pos-switch/rules/doesRuleMatch.ts","src/components/pos-switch/rules/findMatchingRules.ts","src/components/pos-switch/pos-switch.css?tag=pos-switch&encapsulation=shadow","src/components/pos-switch/pos-switch.tsx"],"sourcesContent":["import { Comparison } from './index';\n\n/**\n * Checks whether the given values match the given target according to the given comparison\n * @param values\n * @param comparison\n */\nexport function doValuesMatch(values: string[], comparison: Comparison): boolean {\n const { operator, semantic, target } = comparison;\n const matches = values.map(val => {\n let cmp;\n const numVal = Number(val);\n const numTarget = Number(target);\n if (!Number.isNaN(numVal) && !Number.isNaN(numTarget)) {\n cmp = numVal - numTarget;\n } else {\n cmp = String(val).localeCompare(String(target));\n }\n switch (operator) {\n case 'eq':\n return cmp === 0;\n case 'gt':\n return cmp > 0;\n case 'gte':\n return cmp >= 0;\n case 'lt':\n return cmp < 0;\n case 'lte':\n return cmp <= 0;\n }\n });\n if (semantic == 'some') {\n return matches.some(Boolean);\n } else if (semantic == 'every') {\n return matches.every(Boolean);\n } else {\n throw new Error(`Unknown semantic: ${semantic}`);\n }\n}\n","import { IfPropertyRule, IfRevRule, IfTypeofRule, RuleContext, SwitchCaseRule } from './index';\n\nimport { doValuesMatch } from './doValuesMatch';\n\nexport function doesRuleMatch(rule: SwitchCaseRule, context: RuleContext) {\n const ruleResult = evaluateRule(rule, context);\n return rule.not ? !ruleResult : ruleResult;\n}\n\nfunction evaluateRule(rule: SwitchCaseRule, context: RuleContext) {\n switch (rule.type) {\n case 'if-typeof':\n return doesTypeMatch(rule, context);\n case 'if-property':\n return doesPropertyMatch(rule, context);\n case 'if-rev':\n return doesReverseRelationMatch(rule, context);\n case 'else':\n return true;\n default:\n return false;\n }\n}\n\nfunction doesTypeMatch(rule: IfTypeofRule, context: RuleContext) {\n return context.types.map(x => x.uri).includes(rule.value);\n}\n\nfunction doesPropertyMatch(rule: IfPropertyRule, context: RuleContext) {\n const matchingLiteral = context.literals.find(it => it.predicate == rule.value);\n const matchingRelation = context.relations.find(it => it.predicate == rule.value);\n if (rule.comparison && (matchingLiteral || matchingRelation)) {\n return doValuesMatch([...(matchingLiteral?.values ?? []), ...(matchingRelation?.uris ?? [])], rule.comparison);\n }\n return matchingLiteral !== undefined || matchingRelation !== undefined;\n}\n\nfunction doesReverseRelationMatch(rule: IfRevRule, context: RuleContext) {\n const matchingRev = context.reverseRelations.find(x => x.predicate == rule.value);\n if (rule.comparison && matchingRev) {\n return doValuesMatch(matchingRev.uris, rule.comparison);\n }\n return matchingRev !== undefined;\n}\n","import { RuleContext, SwitchCaseRule } from './index';\nimport { doesRuleMatch } from './doesRuleMatch';\n\nexport function findMatchingRules<T extends { rule: SwitchCaseRule }>(cases: T[], context: RuleContext) {\n /**\n * scope of if-else statements\n * each plain if (without else) increases the scope by 1\n * else branches are ignored if we already found a match in the current scope\n */\n let scope = 0;\n /**\n * scope of the previous rule that matched\n */\n let previousRuleMatched = -1;\n return cases.filter(it => {\n if (it.rule.else && previousRuleMatched == scope) {\n return false; // else branches are ignored if we already found a match in the current scope\n }\n if (!it.rule.else) {\n scope++; // plain if rule -> new scope\n }\n const match = doesRuleMatch(it.rule, context);\n if (match) {\n previousRuleMatched = scope; // found a match in the current if-else scope\n }\n return match;\n });\n}\n",":host {\n display: contents;\n}\n","import { Thing } from '@pod-os/core';\nimport { Component, Element, Event, h, State } from '@stencil/core';\nimport { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware';\nimport { combineLatest, map, of, Subject, takeUntil } from 'rxjs';\nimport { findMatchingRules, RuleContext, SwitchCaseRule } from './rules';\n\ninterface CaseWithRule {\n caseElement: HTMLPosCaseElement;\n rule: SwitchCaseRule;\n}\n\n/**\n * Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n * See [pos-case](https://pod-os.org/reference/elements/components/pos-switch/pos-case/) for available filter conditions.\n */\n@Component({\n tag: 'pos-switch',\n shadow: true,\n styleUrl: 'pos-switch.css',\n})\nexport class PosSwitch implements ResourceAware {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n @State() resource?: Thing;\n @State() cases: CaseWithRule[] = [];\n\n private readonly disconnected$ = new Subject<void>();\n\n @Event({ eventName: 'pod-os:resource' })\n subscribeResource!: ResourceEventEmitter;\n\n componentWillLoad() {\n const caseElements = Array.from(this.host.querySelectorAll('pos-case'));\n if (caseElements.length == 0) {\n this.error = 'No pos-case elements found';\n return;\n }\n // Do NOT await: awaiting a child @Method in componentWillLoad deadlocks the\n // lazy load graph (the child can't render until this component renders).\n // Build the rules once the children have upgraded, then subscribe to the resource\n Promise.all(\n caseElements.map(async it => ({\n rule: await it.getRule(),\n caseElement: it,\n })),\n ).then(cases => {\n this.cases = cases;\n subscribeResource(this);\n });\n }\n\n receiveResource = (resource: Thing) => {\n // reset any existing resource\n this.disconnected$.next();\n this.resource = resource;\n\n combineLatest([\n this.containsRule('if-typeof') ? resource.observeTypes() : of([]),\n this.containsRule('if-property') ? resource.observeLiterals() : of([]),\n this.containsRule('if-property') ? resource.observeRelations() : of([]),\n this.containsRule('if-rev') ? resource.observeReverseRelations() : of([]),\n ])\n .pipe(\n map(([types, literals, relations, reverseRelations]) => ({\n types,\n literals,\n relations,\n reverseRelations,\n })),\n takeUntil(this.disconnected$),\n )\n .subscribe((context: RuleContext) => {\n const activeElements = new Set(findMatchingRules(this.cases, context).map(it => it.caseElement));\n this.cases.forEach(it => {\n if (activeElements.has(it.caseElement)) {\n it.caseElement.setAttribute('active', '');\n } else {\n it.caseElement.removeAttribute('active');\n }\n });\n });\n };\n\n private containsRule(type: SwitchCaseRule['type']) {\n return this.cases.some(it => it.rule.type === type);\n }\n\n render() {\n if (this.error) {\n return this.error;\n }\n if (!this.resource) {\n return null;\n }\n\n return <slot></slot>;\n }\n\n disconnectedCallback() {\n this.disconnected$.next();\n this.disconnected$.complete();\n }\n}\n"],"names":["Subject","combineLatest","of","map","takeUntil"],"mappings":";;;;AAEA;;;;AAIG;AACG,SAAU,aAAa,CAAC,MAAgB,EAAE,UAAsB,EAAA;IACpE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,UAAU;IACjD,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,IAAG;AAC/B,QAAA,IAAI,GAAG;AACP,QAAA,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC;AAC1B,QAAA,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;AAChC,QAAA,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;AACrD,YAAA,GAAG,GAAG,MAAM,GAAG,SAAS;;aACnB;AACL,YAAA,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;;QAEjD,QAAQ,QAAQ;AACd,YAAA,KAAK,IAAI;gBACP,OAAO,GAAG,KAAK,CAAC;AAClB,YAAA,KAAK,IAAI;gBACP,OAAO,GAAG,GAAG,CAAC;AAChB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,YAAY,CAAC,GAAG,CAAC,OAAM,EAAE,MAAK;AAC5B,YAAA,IAAI,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE;AACxB,YAAA,WAAW,EAAE,EAAE;AAChB,SAAA,CAAC,CAAC,CACJ,CAAC,IAAI,CAAC,KAAK,IAAG;AACb,YAAA,IAAI,CAAC,KAAK,GAAG,KAAK;YAClB,iBAAiB,CAAC,IAAI,CAAC;AACzB,SAAC,CAAC;;AAmCI,IAAA,YAAY,CAAC,IAA4B,EAAA;AAC/C,QAAA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;;IAGrD,MAAM,GAAA;AACJ,QAAA,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,OAAO,IAAI,CAAC,KAAK;;AAEnB,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AAClB,YAAA,OAAO,IAAI;;AAGb,QAAA,OAAO,eAAa;;IAGtB,oBAAoB,GAAA;AAClB,QAAA,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE;AACzB,QAAA,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pod-os/elements",
|
|
3
|
-
"version": "0.43.0-rc.
|
|
3
|
+
"version": "0.43.0-rc.9c5d5f9.0",
|
|
4
4
|
"description": "Custom elements for usage with Solid Pods",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"generate": "stencil generate"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@pod-os/core": "v0.32.0-rc.
|
|
31
|
+
"@pod-os/core": "v0.32.0-rc.9c5d5f9.0",
|
|
32
32
|
"@shoelace-style/shoelace": "^2.20.1",
|
|
33
33
|
"@stencil/core": "^4.43.2",
|
|
34
34
|
"@stencil/store": "^2.2.2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["NEVER_RULE","type","not","else","ELSE_RULE","posCaseCss","PosCase","constructor","hostRef","this","error","templateHTML","active","componentWillRender","countRules","ifTypeof","ifProperty","ifRev","filter","it","undefined","length","countComparisons","someValueLt","everyValueLt","someValueLte","everyValueLte","someValueEq","everyValueEq","someValueGte","everyValueGte","someValueGt","everyValueGt","getRule","modifiers","comparison","getComparison","Object","assign","value","_j","_h","_g","_f","_e","_d","_c","_b","_a","comparisonFor","target","semantic","operator","componentWillLoad","templateElement","host","querySelector","innerHTML","render","h","class","Host"],"sources":["src/components/pos-switch/rules/index.ts","src/components/pos-switch/pos-case/pos-case.css?tag=pos-case","src/components/pos-switch/pos-case/pos-case.tsx"],"sourcesContent":["import { Literal, RdfType, Relation } from '@pod-os/core';\n\nexport { findMatchingRules } from './findMatchingRules';\n\n/**\n * A rule that matches if the resource is of a specific type\n */\nexport interface IfTypeofRule {\n type: 'if-typeof';\n /**\n * The URI of the type to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource is not of the specified type)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n}\n\n/**\n * A rule that matches if the resource has a specific property (literal or relation)\n */\nexport interface IfPropertyRule {\n type: 'if-property';\n /**\n * The value of the property to match against (either literal value or the URI of a relation)\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified property)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the value of the property matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that matches if the resource has a specific reverse relation\n */\nexport interface IfRevRule {\n type: 'if-rev';\n /**\n * The URI of the reverse relation to match against.\n */\n value: string;\n /**\n * Negate the rule (match if the resource does not have the specified reverse relation)\n */\n not?: boolean;\n /**\n * Only apply the rule if no predecessor matched\n */\n else?: boolean;\n /**\n * If set, the rule only matches if the URI of the reverse relation matches the specified comparison\n */\n comparison?: Comparison;\n}\n\n/**\n * A rule that only matches if all others did not\n */\nexport interface ElseRule {\n type: 'else';\n not: false;\n else: true;\n}\n\n/**\n * A rule that never matches\n */\nexport interface NeverRule {\n type: 'never';\n not: false;\n else: false;\n}\n\n/**\n * A rule defined by a pos-case\n */\nexport type SwitchCaseRule = IfTypeofRule | IfPropertyRule | IfRevRule | ElseRule | NeverRule;\n\nexport const NEVER_RULE: NeverRule = {\n type: 'never',\n not: false,\n else: false,\n};\n\nexport const ELSE_RULE: ElseRule = {\n type: 'else',\n not: false,\n else: true,\n};\n\n/**\n * Contains the actual data a rule is matched against\n */\nexport interface RuleContext {\n types: RdfType[];\n literals: Literal[];\n relations: Relation[];\n reverseRelations: Relation[];\n}\n\n/**\n * Defines how to compare values to a specific target value\n */\nexport interface Comparison {\n /**\n * Does every value need to match, or only some?\n */\n semantic: Semantic;\n /**\n * The comparison operator to apply (e.g. value must be equal, greater than, etc.)\n */\n operator: Operator;\n /**\n * The target value to compare against.\n */\n target: string;\n}\n\nexport type equals = 'eq';\nexport type greaterThan = 'gt';\nexport type greaterThanOrEqual = 'gte';\nexport type lessThan = 'lt';\nexport type lessThanOrEqual = 'lte';\nexport type some = 'some';\nexport type every = 'every';\nexport type Operator = equals | greaterThan | greaterThanOrEqual | lessThan | lessThanOrEqual;\nexport type Semantic = some | every;\n",".error {\n background-color: var(--pos-error-background-color);\n border: 1px solid var(--pos-error-border-color);\n padding: var(--size-3);\n border-radius: var(--radius-md);\n}\n","import { Component, Element, h, Host, Method, Prop, State } from '@stencil/core';\nimport { Comparison, ELSE_RULE, NEVER_RULE, Operator, Semantic, SwitchCaseRule } from '../rules';\n\n/**\n * Defines a template to use if the specified condition is met - to be used with [pos-switch](https://pod-os.org/reference/elements/components/pos-switch/).\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n */\n@Component({\n tag: 'pos-case',\n shadow: false,\n styleUrl: 'pos-case.css',\n})\nexport class PosCase {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n private templateHTML: string | null = null;\n\n /**\n * Test if the resource is of the specified type\n */\n @Prop() ifTypeof?: string;\n /**\n * Test if the resource has the specified property (forward link)\n */\n @Prop() ifProperty?: string;\n /**\n * Test if the resource is the subject of the specified property (backward link)\n */\n @Prop() ifRev?: string;\n /**\n * Negates the result of the test\n */\n @Prop() not?: boolean;\n /**\n * The test only evaluates to true if tests for preceding cases have failed\n */\n @Prop() else?: boolean;\n /**\n * Test if some value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() someValueEq?: string;\n /**\n * Test if every value linked by if-property or if-rev is equal to the attribute\n */\n @Prop() everyValueEq?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly greater than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGt?: string;\n /**\n * Test if some value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueGte?: string;\n /**\n * Test if every value linked by if-property or if-rev is greater than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueGte?: string;\n /**\n * Test if some value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLt?: string;\n /**\n * Test if every value linked by if-property or if-rev is strictly less than the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLt?: string;\n /**\n * Test if some value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() someValueLte?: string;\n /**\n * Test if every value linked by if-property or if-rev is less than or equal to the attribute. First a number comparison is attempted, then string.\n */\n @Prop() everyValueLte?: string;\n\n componentWillRender() {\n const countRules = [this.ifTypeof, this.ifProperty, this.ifRev].filter(it => it !== undefined).length;\n if (countRules > 1) {\n this.error = 'At most 1 \"if-\" must be present';\n }\n const countComparisons = [\n this.someValueLt,\n this.everyValueLt,\n this.someValueLte,\n this.everyValueLte,\n this.someValueEq,\n this.everyValueEq,\n this.someValueGte,\n this.everyValueGte,\n this.someValueGt,\n this.everyValueGt,\n ].filter(it => it !== undefined).length;\n if (countComparisons > 1) {\n this.error = 'At most 1 comparison (\"every-\" / \"some-\") must be present';\n }\n }\n\n /**\n * Whether this case is active, i.e. shown. Usually this is controlled by the surrounding pos-switch, and there is no need to set this manually.\n */\n @Prop() active = false;\n\n /**\n * Returns the rule definition for this case. The rule determines if the element's content gets rendered.\n */\n @Method()\n async getRule(): Promise<SwitchCaseRule> {\n const modifiers = {\n not: this.not,\n else: this.else,\n };\n const comparison = this.getComparison();\n if (this.ifTypeof) {\n return {\n type: 'if-typeof',\n value: this.ifTypeof,\n ...modifiers,\n };\n }\n if (this.ifProperty) {\n return {\n type: 'if-property',\n value: this.ifProperty,\n ...modifiers,\n comparison,\n };\n }\n if (this.ifRev) {\n return {\n type: 'if-rev',\n value: this.ifRev,\n ...modifiers,\n comparison,\n };\n }\n return this.else ? ELSE_RULE : NEVER_RULE;\n }\n\n private getComparison(): Comparison | undefined {\n return (\n this.comparisonFor(this.someValueEq, 'some', 'eq') ??\n this.comparisonFor(this.everyValueEq, 'every', 'eq') ??\n this.comparisonFor(this.someValueGt, 'some', 'gt') ??\n this.comparisonFor(this.everyValueGt, 'every', 'gt') ??\n this.comparisonFor(this.someValueGte, 'some', 'gte') ??\n this.comparisonFor(this.everyValueGte, 'every', 'gte') ??\n this.comparisonFor(this.someValueLt, 'some', 'lt') ??\n this.comparisonFor(this.everyValueLt, 'every', 'lt') ??\n this.comparisonFor(this.someValueLte, 'some', 'lte') ??\n this.comparisonFor(this.everyValueLte, 'every', 'lte')\n );\n }\n\n private comparisonFor(target: string | undefined, semantic: Semantic, operator: Operator): Comparison | undefined {\n if (target) {\n return { semantic, operator, target };\n }\n }\n\n componentWillLoad() {\n const templateElement = this.host.querySelector('template');\n if (templateElement == null) {\n this.error = 'No template element found';\n } else {\n this.templateHTML = templateElement.innerHTML;\n }\n }\n\n render() {\n if (this.error) return <div class=\"error\">{this.error}</div>;\n\n if (!this.active) {\n // because we set innerHTML for active case elements, we need to\n // unset it here to not leave state in the dom\n return <Host innerHTML=\"\"></Host>;\n }\n return <Host innerHTML={this.templateHTML}></Host>;\n }\n}\n"],"mappings":"oDA4FO,MAAMA,EAAwB,CACnCC,KAAM,QACNC,IAAK,MACLC,KAAM,OAGD,MAAMC,EAAsB,CACjCH,KAAM,OACNC,IAAK,MACLC,KAAM,MCrGR,MAAME,EAAa,IAAM,iK,MCYZC,EAAO,MALpB,WAAAC,CAAAC,G,UAOWC,KAAAC,MAAuB,KACxBD,KAAAE,aAA8B,KAwF9BF,KAAAG,OAAS,KA8ElB,CAvGC,mBAAAC,GACE,MAAMC,EAAa,CAACL,KAAKM,SAAUN,KAAKO,WAAYP,KAAKQ,OAAOC,QAAOC,GAAMA,IAAOC,YAAWC,OAC/F,GAAIP,EAAa,EAAG,CAClBL,KAAKC,MAAQ,iC,CAEf,MAAMY,EAAmB,CACvBb,KAAKc,YACLd,KAAKe,aACLf,KAAKgB,aACLhB,KAAKiB,cACLjB,KAAKkB,YACLlB,KAAKmB,aACLnB,KAAKoB,aACLpB,KAAKqB,cACLrB,KAAKsB,YACLtB,KAAKuB,cACLd,QAAOC,GAAMA,IAAOC,YAAWC,OACjC,GAAIC,EAAmB,EAAG,CACxBb,KAAKC,MAAQ,2D,EAajB,aAAMuB,GACJ,MAAMC,EAAY,CAChBhC,IAAKO,KAAKP,IACVC,KAAMM,KAAKN,MAEb,MAAMgC,EAAa1B,KAAK2B,gBACxB,GAAI3B,KAAKM,SAAU,CACjB,OAAAsB,OAAAC,OAAA,CACErC,KAAM,YACNsC,MAAO9B,KAAKM,UACTmB,E,CAGP,GAAIzB,KAAKO,WAAY,CACnB,OAAAqB,OAAAC,OAAAD,OAAAC,OAAA,CACErC,KAAM,cACNsC,MAAO9B,KAAK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,EAIxC,MAAAC,GACE,GAAIjD,KAAKC,MAAO,OAAOiD,EAAA,OAAKC,MAAM,SAASnD,KAAKC,OAEhD,IAAKD,KAAKG,OAAQ,CAGhB,OAAO+C,EAACE,EAAI,CAACJ,UAAU,I,CAEzB,OAAOE,EAACE,EAAI,CAACJ,UAAWhD,KAAKE,c","ignoreList":[]}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as t,c as e,h as r,a as s}from"./p-DHgULnQH.js";import{s as n}from"./p-BW_CkW1K.js";import{c as i}from"./p-vFMstSdt.js";function o(t,e){const{operator:r,semantic:s,target:n}=e;const i=t.map((t=>{let e;const s=Number(t);const i=Number(n);if(!Number.isNaN(s)&&!Number.isNaN(i)){e=s-i}else{e=String(t).localeCompare(String(n))}switch(r){case"eq":return e===0;case"gt":return e>0;case"gte":return e>=0;case"lt":return e<0;case"lte":return e<=0}}));if(s=="some"){return i.some(Boolean)}else if(s=="every"){return i.every(Boolean)}else{throw new Error(`Unknown semantic: ${s}`)}}function u(t,e){const r=c(t,e);return t.not?!r:r}function c(t,e){switch(t.type){case"if-typeof":return a(t,e);case"if-property":return l(t,e);case"if-rev":return f(t,e);case"else":return true;default:return false}}function a(t,e){return e.types.map((t=>t.uri)).includes(t.value)}function l(t,e){var r,s;const n=e.literals.find((e=>e.predicate==t.value));const i=e.relations.find((e=>e.predicate==t.value));if(t.comparison&&(n||i)){return o([...(r=n===null||n===void 0?void 0:n.values)!==null&&r!==void 0?r:[],...(s=i===null||i===void 0?void 0:i.uris)!==null&&s!==void 0?s:[]],t.comparison)}return n!==undefined||i!==undefined}function f(t,e){const r=e.reverseRelations.find((e=>e.predicate==t.value));if(t.comparison&&r){return o(r.uris,t.comparison)}return r!==undefined}function h(t,e){let r=0;let s=-1;return t.filter((t=>{if(t.rule.else&&s==r){return false}if(!t.rule.else){r++}const n=u(t.rule,e);if(n){s=r}return n}))}const p=class{constructor(r){t(this,r);this.subscribeResource=e(this,"pod-os:resource",7);this.error=null;this.cases=[];this.disconnected$=new i.Subject;this.receiveResource=t=>{this.disconnected$.next();this.resource=t;i.combineLatest([this.containsRule("if-typeof")?t.observeTypes():i.of([]),this.containsRule("if-property")?t.observeLiterals():i.of([]),this.containsRule("if-property")?t.observeRelations():i.of([]),this.containsRule("if-rev")?t.observeReverseRelations():i.of([])]).pipe(i.map((([t,e,r,s])=>({types:t,literals:e,relations:r,reverseRelations:s}))),i.takeUntil(this.disconnected$)).subscribe((t=>{const e=new Set(h(this.cases,t).map((t=>t.caseElement)));this.cases.forEach((t=>{if(e.has(t.caseElement)){t.caseElement.setAttribute("active","")}else{t.caseElement.removeAttribute("active")}}))}))}}componentWillLoad(){const t=Array.from(this.host.querySelectorAll("pos-case"));if(t.length==0){this.error="No pos-case elements found";return}Promise.all(t.map((async t=>({rule:await t.getRule(),caseElement:t})))).then((t=>{this.cases=t;n(this)}))}containsRule(t){return this.cases.some((e=>e.rule.type===t))}render(){if(this.error){return this.error}if(!this.resource){return null}return r("slot",null)}disconnectedCallback(){this.disconnected$.next();this.disconnected$.complete()}get host(){return s(this)}};export{p as pos_switch};
|
|
2
|
-
//# sourceMappingURL=p-92e490db.entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["doValuesMatch","values","comparison","operator","semantic","target","matches","map","val","cmp","numVal","Number","numTarget","isNaN","String","localeCompare","some","Boolean","every","Error","doesRuleMatch","rule","context","ruleResult","evaluateRule","not","type","doesTypeMatch","doesPropertyMatch","doesReverseRelationMatch","types","x","uri","includes","value","matchingLiteral","literals","find","it","predicate","matchingRelation","relations","_a","_b","uris","undefined","matchingRev","reverseRelations","findMatchingRules","cases","scope","previousRuleMatched","filter","else","match","PosSwitch","constructor","hostRef","this","error","disconnected$","Subject","receiveResource","resource","next","combineLatest","containsRule","observeTypes","of","observeLiterals","observeRelations","observeReverseRelations","pipe","takeUntil","subscribe","activeElements","Set","caseElement","forEach","has","setAttribute","removeAttribute","componentWillLoad","caseElements","Array","from","host","querySelectorAll","length","Promise","all","async","getRule","then","subscribeResource","render","h","disconnectedCallback","complete"],"sources":["src/components/pos-switch/rules/doValuesMatch.ts","src/components/pos-switch/rules/doesRuleMatch.ts","src/components/pos-switch/rules/findMatchingRules.ts","src/components/pos-switch/pos-switch.tsx"],"sourcesContent":["import { Comparison } from './index';\n\n/**\n * Checks whether the given values match the given target according to the given comparison\n * @param values\n * @param comparison\n */\nexport function doValuesMatch(values: string[], comparison: Comparison): boolean {\n const { operator, semantic, target } = comparison;\n const matches = values.map(val => {\n let cmp;\n const numVal = Number(val);\n const numTarget = Number(target);\n if (!Number.isNaN(numVal) && !Number.isNaN(numTarget)) {\n cmp = numVal - numTarget;\n } else {\n cmp = String(val).localeCompare(String(target));\n }\n switch (operator) {\n case 'eq':\n return cmp === 0;\n case 'gt':\n return cmp > 0;\n case 'gte':\n return cmp >= 0;\n case 'lt':\n return cmp < 0;\n case 'lte':\n return cmp <= 0;\n }\n });\n if (semantic == 'some') {\n return matches.some(Boolean);\n } else if (semantic == 'every') {\n return matches.every(Boolean);\n } else {\n throw new Error(`Unknown semantic: ${semantic}`);\n }\n}\n","import { IfPropertyRule, IfRevRule, IfTypeofRule, RuleContext, SwitchCaseRule } from './index';\n\nimport { doValuesMatch } from './doValuesMatch';\n\nexport function doesRuleMatch(rule: SwitchCaseRule, context: RuleContext) {\n const ruleResult = evaluateRule(rule, context);\n return rule.not ? !ruleResult : ruleResult;\n}\n\nfunction evaluateRule(rule: SwitchCaseRule, context: RuleContext) {\n switch (rule.type) {\n case 'if-typeof':\n return doesTypeMatch(rule, context);\n case 'if-property':\n return doesPropertyMatch(rule, context);\n case 'if-rev':\n return doesReverseRelationMatch(rule, context);\n case 'else':\n return true;\n default:\n return false;\n }\n}\n\nfunction doesTypeMatch(rule: IfTypeofRule, context: RuleContext) {\n return context.types.map(x => x.uri).includes(rule.value);\n}\n\nfunction doesPropertyMatch(rule: IfPropertyRule, context: RuleContext) {\n const matchingLiteral = context.literals.find(it => it.predicate == rule.value);\n const matchingRelation = context.relations.find(it => it.predicate == rule.value);\n if (rule.comparison && (matchingLiteral || matchingRelation)) {\n return doValuesMatch([...(matchingLiteral?.values ?? []), ...(matchingRelation?.uris ?? [])], rule.comparison);\n }\n return matchingLiteral !== undefined || matchingRelation !== undefined;\n}\n\nfunction doesReverseRelationMatch(rule: IfRevRule, context: RuleContext) {\n const matchingRev = context.reverseRelations.find(x => x.predicate == rule.value);\n if (rule.comparison && matchingRev) {\n return doValuesMatch(matchingRev.uris, rule.comparison);\n }\n return matchingRev !== undefined;\n}\n","import { RuleContext, SwitchCaseRule } from './index';\nimport { doesRuleMatch } from './doesRuleMatch';\n\nexport function findMatchingRules<T extends { rule: SwitchCaseRule }>(cases: T[], context: RuleContext) {\n /**\n * scope of if-else statements\n * each plain if (without else) increases the scope by 1\n * else branches are ignored if we already found a match in the current scope\n */\n let scope = 0;\n /**\n * scope of the previous rule that matched\n */\n let previousRuleMatched = -1;\n return cases.filter(it => {\n if (it.rule.else && previousRuleMatched == scope) {\n return false; // else branches are ignored if we already found a match in the current scope\n }\n if (!it.rule.else) {\n scope++; // plain if rule -> new scope\n }\n const match = doesRuleMatch(it.rule, context);\n if (match) {\n previousRuleMatched = scope; // found a match in the current if-else scope\n }\n return match;\n });\n}\n","import { Thing } from '@pod-os/core';\nimport { Component, Element, Event, h, State } from '@stencil/core';\nimport { ResourceAware, ResourceEventEmitter, subscribeResource } from '../events/ResourceAware';\nimport { combineLatest, map, of, Subject, takeUntil } from 'rxjs';\nimport { findMatchingRules, RuleContext, SwitchCaseRule } from './rules';\n\ninterface CaseWithRule {\n caseElement: HTMLPosCaseElement;\n rule: SwitchCaseRule;\n}\n\n/**\n * Selects a child template to render based on properties of the subject resource, usually defined by an ancestor `pos-resource` element.\n * See [storybook](https://pod-os.github.io/PodOS/storybook/?path=/story/basics--pos-switch) for an example.\n * See [pos-case](https://pod-os.org/reference/elements/components/pos-switch/pos-case/) for available filter conditions.\n */\n@Component({\n tag: 'pos-switch',\n shadow: true,\n})\nexport class PosSwitch implements ResourceAware {\n @Element() host!: HTMLElement;\n @State() error: string | null = null;\n @State() resource?: Thing;\n @State() cases: CaseWithRule[] = [];\n\n private readonly disconnected$ = new Subject<void>();\n\n @Event({ eventName: 'pod-os:resource' })\n subscribeResource!: ResourceEventEmitter;\n\n componentWillLoad() {\n const caseElements = Array.from(this.host.querySelectorAll('pos-case'));\n if (caseElements.length == 0) {\n this.error = 'No pos-case elements found';\n return;\n }\n // Do NOT await: awaiting a child @Method in componentWillLoad deadlocks the\n // lazy load graph (the child can't render until this component renders).\n // Build the rules once the children have upgraded, then subscribe to the resource\n Promise.all(\n caseElements.map(async it => ({\n rule: await it.getRule(),\n caseElement: it,\n })),\n ).then(cases => {\n this.cases = cases;\n subscribeResource(this);\n });\n }\n\n receiveResource = (resource: Thing) => {\n // reset any existing resource\n this.disconnected$.next();\n this.resource = resource;\n\n combineLatest([\n this.containsRule('if-typeof') ? resource.observeTypes() : of([]),\n this.containsRule('if-property') ? resource.observeLiterals() : of([]),\n this.containsRule('if-property') ? resource.observeRelations() : of([]),\n this.containsRule('if-rev') ? resource.observeReverseRelations() : of([]),\n ])\n .pipe(\n map(([types, literals, relations, reverseRelations]) => ({\n types,\n literals,\n relations,\n reverseRelations,\n })),\n takeUntil(this.disconnected$),\n )\n .subscribe((context: RuleContext) => {\n const activeElements = new Set(findMatchingRules(this.cases, context).map(it => it.caseElement));\n this.cases.forEach(it => {\n if (activeElements.has(it.caseElement)) {\n it.caseElement.setAttribute('active', '');\n } else {\n it.caseElement.removeAttribute('active');\n }\n });\n });\n };\n\n private containsRule(type: SwitchCaseRule['type']) {\n return this.cases.some(it => it.rule.type === type);\n }\n\n render() {\n if (this.error) {\n return this.error;\n }\n if (!this.resource) {\n return null;\n }\n\n return <slot></slot>;\n }\n\n disconnectedCallback() {\n this.disconnected$.next();\n this.disconnected$.complete();\n }\n}\n"],"mappings":"iIAOM,SAAUA,EAAcC,EAAkBC,GAC9C,MAAMC,S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