@kedem/okdb 2.5.0 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +90 -0
- package/algorithm-worker-thread.js +1 -1
- package/bin/okdb.js +1 -1
- package/docs/auth-permissions.md +31 -5
- package/okdb-functions-sandbox-worker.js +1 -1
- package/okdb-http-worker-child.js +1 -1
- package/okdb-views-bootstrap-worker.js +1 -1
- package/okdb.js +1 -1
- package/package.json +1 -1
- package/public/admin-app.js +1 -1
- package/public/components/schema-edit-modal.ok.js +1 -0
- package/public/core/db/db-section.ok.html +1 -0
- package/public/core/db/modals/add-item-modal.ok.js +1 -0
- package/public/core/db/modals/create-fts-modal.ok.js +1 -0
- package/public/core/db/modals/create-index-modal.ok.js +1 -0
- package/public/core/db/parts/db-overview.ok.js +1 -0
- package/public/core/db/parts/edit-row.ok.js +1 -0
- package/public/core/db/parts/type-changelog.ok.js +1 -0
- package/public/core/db/parts/type-data-tab.ok.js +1 -0
- package/public/core/db/parts/type-list.ok.js +1 -0
- package/public/core/db/parts/type-manage-tab.ok.js +1 -0
- package/public/core/db/parts/type-schema-tab.ok.js +1 -0
- package/public/core/db/parts/type-viewer.ok.js +1 -0
- package/public/core/db/type-ops.js +1 -0
- package/public/core/docs/docs-page.ok.html +1 -0
- package/public/core/license/license-panel.ok.js +1 -0
- package/public/core/system/parts/system-log.ok.js +1 -0
- package/public/core/system/parts/system-processing-panel.ok.js +1 -0
- package/public/core/system/parts/system-storage-panel.ok.js +1 -0
- package/public/core/system/system-events-page.ok.js +1 -0
- package/public/core/system/system-logs-page.ok.js +1 -0
- package/public/core/system/system-overview-page.ok.html +1 -0
- package/public/core/system/system-runtime-page.ok.js +1 -0
- package/public/core/system/system-section.ok.html +1 -0
- package/public/features/api/api-panel.ok.js +1 -0
- package/public/features/api/index.js +1 -0
- package/public/features/auth/auth-panel.ok.js +1 -0
- package/public/features/auth/index.js +1 -0
- package/public/features/files/files-section.ok.html +1 -0
- package/public/features/files/index.js +1 -0
- package/public/features/files/parts/files-file-list.ok.js +1 -0
- package/public/features/files/parts/files-path-browser.ok.js +1 -0
- package/public/features/files/parts/files-preview.ok.js +1 -0
- package/public/features/files/parts/files-upload-panel.ok.js +1 -0
- package/public/features/functions/exports.js +1 -0
- package/public/features/functions/functions-section.ok.html +1 -0
- package/public/features/functions/functions-store.js +1 -0
- package/public/features/functions/index.js +1 -0
- package/public/features/functions/modals/function-modal.ok.js +1 -0
- package/public/features/functions/parts/function-detail.ok.js +1 -0
- package/public/features/functions/parts/function-logs.ok.js +1 -0
- package/public/features/functions/parts/function-runner.ok.js +1 -0
- package/public/features/pipelines/engine-ui-utils.js +1 -0
- package/public/features/pipelines/exports.js +1 -0
- package/public/features/pipelines/index.js +1 -0
- package/public/features/pipelines/modals/create-pipeline-modal.ok.js +1 -0
- package/public/features/pipelines/modals/edit-pipeline-modal.ok.js +1 -0
- package/public/features/pipelines/modals/engine-modal.ok.js +1 -0
- package/public/features/pipelines/parts/embed-create-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embed-embedder-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embed-indexer-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embed-search-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embed-worker-panel.ok.js +1 -0
- package/public/features/pipelines/parts/embeddings-engine-panel.ok.js +1 -0
- package/public/features/pipelines/parts/engine-declaration-editor.ok.js +1 -0
- package/public/features/pipelines/parts/engines-overview.ok.js +1 -0
- package/public/features/pipelines/parts/generic-engine-panel.ok.js +1 -0
- package/public/features/pipelines/parts/pipeline-create-panel.ok.js +1 -0
- package/public/features/pipelines/parts/pipeline-flow-strip.ok.js +1 -0
- package/public/features/pipelines/parts/type-pipelines-tab.ok.js +1 -0
- package/public/features/pipelines/pipelines-section.ok.html +1 -0
- package/public/features/queue/index.js +1 -0
- package/public/features/queue/modals/create-bucket-modal.ok.js +1 -0
- package/public/features/queue/modals/edit-bucket-modal.ok.js +1 -0
- package/public/features/queue/modals/edit-job-modal.ok.js +1 -0
- package/public/features/queue/modals/enqueue-job-modal.ok.js +1 -0
- package/public/features/queue/modals/job-type-modal.ok.js +1 -0
- package/public/features/queue/parts/job-log-panel.ok.js +1 -0
- package/public/features/queue/parts/queue-buckets.ok.js +1 -0
- package/public/features/queue/parts/queue-job-types.ok.js +1 -0
- package/public/features/queue/parts/queue-jobs.ok.js +1 -0
- package/public/features/queue/parts/queue-types.ok.js +1 -0
- package/public/features/queue/parts/queue-workers.ok.js +1 -0
- package/public/features/queue/queue-section.ok.html +1 -0
- package/public/features/sync/index.js +1 -0
- package/public/features/sync/sync-panel.ok.js +1 -0
- package/public/features/views/index.js +1 -0
- package/public/features/views/modals/create-view-modal.ok.js +1 -0
- package/public/features/views/parts/views-list.ok.js +1 -0
- package/public/features/views/parts/views-overview.ok.js +1 -0
- package/public/features/views/views-section.ok.html +1 -0
- package/public/features/views/views-store.js +1 -0
- package/public/index.html +9 -3
- package/public/modules/ok.js +1 -1
- package/public/shell/admin-shell.ok.html +3 -0
- package/public/shell/core-manifest.js +1 -0
- package/public/shell/shell-piece.ok.js +1 -0
- package/public/shell/shell-section-host.ok.js +1 -0
- package/public/shell/shell-section.ok.js +1 -0
- package/public/shell/shell-store.js +1 -0
- package/public/stores/auth-store.js +1 -1
- package/public/stores/okdb-store.js +1 -1
- package/public/stores/storage-store.js +1 -0
- package/public/styles.css +1 -1
- package/public/vendor/okjs/ok.esm.min.js +1 -1
- package/public/vendor/okjs/toolkit/components/ok-chart.ok.js +1 -1
- package/public/vendor/okjs/toolkit/components/ok-doc-viewer.ok.js +1 -1
- package/public/vendor/okjs/toolkit/components/ok-marked.ok.js +1 -1
- package/public/vendor/okjs/toolkit/components/ok-monaco.ok.js +1 -1
- package/public/vendor/okjs/toolkit/core/virtualized.ok.js +1 -1
- package/public/vendor/okjs/toolkit/editor/ok-live-shell.ok.js +1 -1
- package/public/vendor/okjs/toolkit/elements/ok-select.ok.js +1 -1
- package/public/vendor/okjs/toolkit/elements/ok-table.ok.js +1 -1
- package/public/components/admin-route-host.ok.js +0 -1
- package/public/components/field.html +0 -158
- package/public/layouts/_default.ok.html +0 -3
- package/public/sections/api/index.ok.html +0 -1
- package/public/sections/auth/index.ok.html +0 -1
- package/public/sections/auth/modals/perm-info-popover.ok.js +0 -1
- package/public/sections/db/index.ok.html +0 -1
- package/public/sections/db/modals/add-item-modal.ok.js +0 -1
- package/public/sections/db/modals/create-fts-modal.ok.js +0 -1
- package/public/sections/db/modals/create-index-modal.ok.js +0 -1
- package/public/sections/db/modals/create-pipeline-modal.ok.js +0 -1
- package/public/sections/db/modals/schema-edit-modal.ok.js +0 -1
- package/public/sections/db/parts/db-overview.ok.js +0 -1
- package/public/sections/db/parts/edit-row.ok.js +0 -1
- package/public/sections/db/parts/type-changelog.ok.js +0 -1
- package/public/sections/db/parts/type-list.ok.js +0 -1
- package/public/sections/db/parts/type-pipelines-tab.ok.js +0 -1
- package/public/sections/db/parts/type-schema-tab.ok.js +0 -1
- package/public/sections/db/parts/type-viewer.ok.js +0 -1
- package/public/sections/db/parts/type-violations-tab.ok.js +0 -1
- package/public/sections/docs/index.ok.html +0 -1
- package/public/sections/embeddings/index.ok.html +0 -1
- package/public/sections/embeddings/modals/edit-pipeline-modal.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-create-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-embedder-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-engine-declaration-editor.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-engine-list.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-indexer-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-lifecycle-bar.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-overview.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-search-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embed-worker-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/embeddings-engine-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/engines-overview.ok.js +0 -1
- package/public/sections/embeddings/parts/pipeline-create-panel.ok.js +0 -1
- package/public/sections/embeddings/parts/pipeline-flow-strip.ok.js +0 -1
- package/public/sections/engines/engine-ui-utils.js +0 -1
- package/public/sections/engines/index.ok.html +0 -1
- package/public/sections/engines/modals/engine-modal.ok.js +0 -1
- package/public/sections/engines/parts/engine-declaration-editor.ok.js +0 -1
- package/public/sections/engines/parts/generic-engine-panel.ok.js +0 -1
- package/public/sections/files/index.ok.html +0 -1
- package/public/sections/files/parts/files-collection-list.ok.js +0 -1
- package/public/sections/files/parts/files-collection-panel.ok.js +0 -1
- package/public/sections/files/parts/files-file-list.ok.js +0 -1
- package/public/sections/files/parts/files-path-browser.ok.js +0 -1
- package/public/sections/files/parts/files-preview.ok.js +0 -1
- package/public/sections/files/parts/files-upload-panel.ok.js +0 -1
- package/public/sections/functions/index.ok.html +0 -1
- package/public/sections/functions/modals/function-modal.ok.js +0 -1
- package/public/sections/functions/parts/function-detail.ok.js +0 -1
- package/public/sections/functions/parts/function-logs.ok.js +0 -1
- package/public/sections/functions/parts/function-runner.ok.js +0 -1
- package/public/sections/license/index.ok.html +0 -1
- package/public/sections/license/parts/license-panel.ok.js +0 -1
- package/public/sections/queue/index.ok.html +0 -1
- package/public/sections/queue/modals/create-bucket-modal.ok.js +0 -1
- package/public/sections/queue/modals/edit-bucket-modal.ok.js +0 -1
- package/public/sections/queue/modals/edit-job-modal.ok.js +0 -1
- package/public/sections/queue/modals/enqueue-job-modal.ok.js +0 -1
- package/public/sections/queue/modals/job-type-modal.ok.js +0 -1
- package/public/sections/queue/parts/job-log-panel.ok.js +0 -1
- package/public/sections/queue/parts/ok-job-form.ok.js +0 -1
- package/public/sections/queue/parts/queue-buckets.ok.js +0 -1
- package/public/sections/queue/parts/queue-job-types.ok.js +0 -1
- package/public/sections/queue/parts/queue-jobs.ok.js +0 -1
- package/public/sections/queue/parts/queue-types.ok.js +0 -1
- package/public/sections/queue/parts/queue-workers.ok.js +0 -1
- package/public/sections/sync/index.ok.html +0 -5
- package/public/sections/sync/parts/sync-node-detail.ok.js +0 -1
- package/public/sections/system/index.ok.html +0 -1
- package/public/sections/system/parts/system-api-panel.ok.js +0 -1
- package/public/sections/system/parts/system-auth-panel.ok.js +0 -1
- package/public/sections/system/parts/system-log.ok.js +0 -1
- package/public/sections/system/parts/system-processing-panel.ok.js +0 -1
- package/public/sections/system/parts/system-status.ok.js +0 -1
- package/public/sections/system/parts/system-storage-panel.ok.js +0 -1
- package/public/sections/system/parts/system-sync-panel.ok.js +0 -1
- package/public/sections/views/index.ok.html +0 -1
- package/public/sections/views/modals/create-view-modal.ok.js +0 -1
- package/public/sections/views/parts/views-list.ok.js +0 -1
- package/public/sections/views/parts/views-overview.ok.js +0 -1
- package/public/stores/functions-store.js +0 -1
- /package/public/{sections → core}/db/parts/tm-timeline.ok.js +0 -0
- /package/public/{util → core/db}/sift-schema.js +0 -0
- /package/public/{view-models → core/db}/type-query-vm.js +0 -0
- /package/public/{sections → core}/system/modals/data-ops-modal.ok.js +0 -0
- /package/public/{sections → core}/system/parts/system-locks-panel.ok.js +0 -0
- /package/public/{sections → core}/system/parts/system-log-history.ok.js +0 -0
- /package/public/{sections → core}/system/parts/system-process-panel.ok.js +0 -0
- /package/public/{sections → core}/system/parts/system-runtime-overview.ok.js +0 -0
- /package/public/{sections → features}/api/parts/api-endpoint.ok.js +0 -0
- /package/public/{sections → features}/auth/modals/create-token-modal.ok.js +0 -0
- /package/public/{sections → features}/auth/modals/edit-token-modal.ok.js +0 -0
- /package/public/{sections → features}/auth/parts/token-detail.ok.js +0 -0
- /package/public/{sections → features}/auth/parts/token-list.ok.js +0 -0
- /package/public/{sections → features}/files/parts/files-blob-status.ok.js +0 -0
- /package/public/{sections → features}/files/parts/files-overview.ok.js +0 -0
- /package/public/{sections → features}/functions/parts/functions-list.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/engine-panel-shared-style.js +0 -0
- /package/public/{sections/embeddings → features/pipelines}/modals/register-model-modal.ok.js +0 -0
- /package/public/{sections/embeddings → features/pipelines}/modals/replace-embedder-modal.ok.js +0 -0
- /package/public/{sections/embeddings → features/pipelines}/parts/embed-model-catalog.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/parts/engine-lifecycle-actions.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/parts/engine-panel-shell.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/parts/engine-resource-card.ok.js +0 -0
- /package/public/{sections/engines → features/pipelines}/parts/engine-row-item.ok.js +0 -0
- /package/public/{sections/embeddings → features/pipelines}/parts/pipeline-try-search.ok.js +0 -0
- /package/public/{sections → features}/queue/parts/code-panel.ok.js +0 -0
- /package/public/{sections → features}/sync/modals/connect-peer-modal.ok.js +0 -0
- /package/public/{sections → features}/sync/parts/sync-retention.ok.js +0 -0
- /package/public/{sections → features}/sync/parts/sync-topology.ok.js +0 -0
- /package/public/{sections → features}/views/parts/view-detail.ok.js +0 -0
- /package/public/{sections/db → shell}/modals/create-env-modal.ok.js +0 -0
- /package/public/{sections/db → shell}/modals/demo-env-modal.ok.js +0 -0
- /package/public/{sections/db → shell}/modals/remove-env-modal.ok.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
let t=null;function
|
|
1
|
+
let t=null;function r(t){if(Array.isArray(t))return t.map(r);if(t&&"object"==typeof t){const a={};for(const e of Object.keys(t))a[e]=r(t[e]);return a}return t}function a(t){return!!t.$__unmount__$||!t.$el}function e(t){t.$cache.chart?.destroy(),t.$cache.chart=null}var o={tag:"ok-chart",attr:{type:{type:"string",default:"line"},data:{type:"object",default:()=>({labels:[],datasets:[]})},options:{type:"object",default:()=>({})},autoColor:{type:"boolean",default:!0}},context:e=>({loading:!0,error:null,getDefaultOptions:()=>({responsive:!0,maintainAspectRatio:!1,scales:{x:{type:"category",ticks:{color:"#aaa"},grid:{color:"rgba(255,255,255,0.05)"}},y:{type:"linear",ticks:{color:"#aaa"},grid:{color:"rgba(255,255,255,0.05)"}}},plugins:{legend:{labels:{color:"#ccc",boxWidth:12}},tooltip:{backgroundColor:"#1a1830",borderRadius:8,titleColor:"#fff",bodyColor:"#ccc"}},elements:{line:{borderWidth:2},point:{radius:3,hoverRadius:4}}}),applyAutoColors(t){if(!e.$attr.autoColor||!t.datasets)return t;const r=["#4dc0ff","#8f5","#f49","#ffcc00","#a0a0ff","#ffa07a"];return{...t,datasets:t.datasets.map((t,a)=>({...t,borderColor:t.borderColor||r[a%r.length],backgroundColor:t.backgroundColor||(t.borderColor||r[a%r.length])+"33",tension:t.tension??.3}))}},async initChart(){this.loading=!0,this.error=null;try{if(!t){const r=await import("https://cdn.jsdelivr.net/npm/chart.js@4.5.1/+esm"),{Chart:a,CategoryScale:e,LinearScale:o,BarController:i,LineController:n,PointElement:l,LineElement:c,BarElement:s,Title:d,Tooltip:h,Legend:p,Filler:u}=r;a.register(e,o,i,n,l,c,s,d,h,p,u),t=r}if(a(e))return;const{Chart:o}=t,i=e.$el.querySelector("canvas");if(!i)throw new Error("Canvas element not found");const n=i.getContext("2d"),l=this.applyAutoColors(r(e.$attr.data)),c={...this.getDefaultOptions(),...r(e.$attr.options||{})};e.$cache.chart&&e.$cache.chart.destroy(),e.$cache.chart=new o(n,{type:e.$attr.type,data:l,options:c}),this.loading=!1}catch(t){if(a(e))return;e.$log?.error?.(["Chart initialization failed"],{err:t}),this.error=t.message||"Failed to load chart",this.loading=!1}},updateChart(){const t=e.$cache.chart;if(t)try{const a=this.applyAutoColors(r(e.$attr.data)),o={...this.getDefaultOptions(),...r(e.$attr.options||{})};t.config.type=e.$attr.type,t.data=a,t.options=o,t.update()}catch(t){e.$log?.error?.(["Chart update failed"],{err:t})}}}),async mounted(t){await this.initChart(),a(t)?e(t):t.$watch(()=>[t.$attr.type,t.$attr.data,t.$attr.options],()=>{this.updateChart()},{deep:!0})},unmounted(t){e(t)},template:'<div class="chart-container"><if :="loading"><div class="chart-loader">Loading chart…</div></if><if :="error"><div class="chart-error">⚠️ {{ error }}</div></if><canvas/></div>',style:"[tag],canvas{width:100%;height:100%}[tag]{position:relative;display:flex}.chart-container{position:relative;width:100%;height:100%}canvas{border-radius:6px;display:block}.chart-error,.chart-loader{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;font-size:.9rem;border-radius:6px;background:rgba(0,0,0,.15);backdrop-filter:blur(3px);z-index:10}.chart-loader{color:#aaa}.chart-error{color:#f66}"};export{o as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"./ok-marked.ok.js";function t(e,t){const n=Array.isArray(t)?t.join("|"):t,o=new RegExp("```(?:"+n+")[^\\n]*\\n([\\s\\S]*?)```","i"),r=e.match(o);return r?r[1].trim():null}function n(e){const t=[];for(const o of e)o.file&&t.push(o),o.children?.length&&t.push(...n(o.children));return t}const o=[{name:["note","warning","tip"],render({name:e,content:t}){const n=t.trim().split("\n");let o=null,r=t.trim();const a=n[0]?.trim();a&&!a.startsWith("<")&&(o=a,r=n.slice(1).join("\n").trim());const i=document.createElement("div");i.className=`ok-callout ok-callout--${e}`;const l=document.createElement("div");l.className="ok-callout__icon",l.innerHTML=`<ok-icon name="${{note:"info",warning:"alert-triangle",tip:"lightbulb"}[e]}"></ok-icon>`;const c=document.createElement("div");if(c.className="ok-callout__content",o){const e=document.createElement("div");e.className="ok-callout__title",e.textContent=o,c.appendChild(e)}const s=document.createElement("div");return s.className="ok-callout__body",s.innerHTML=r,c.appendChild(s),i.appendChild(l),i.appendChild(c),i}},{name:"raw",render({content:e}){const t=document.createElement("div");return t.innerHTML=e.trim(),[...t.childNodes]}}],r={async render({lang:e,code:t,scope:n}){const o=document.createElement("div");o.className="ok-code-block";const r=document.createElement("div");r.className="ok-code-block__header";const a=document.createElement("span");a.className="lang",a.textContent=e.toUpperCase();const i=document.createElement("span");i.className="copy",i.textContent="Copy",i.addEventListener("click",()=>{navigator.clipboard.writeText(t.innerText?.trim()),i.textContent="Copied!",setTimeout(()=>i.textContent="Copy",1200)}),r.appendChild(a),r.appendChild(i);const l=document.createElement("pre");o.appendChild(r),o.appendChild(l);try{await n.$ok.componentRegistry.activate(n.$ok.componentRegistry.getRegistration("ok-monaco"),n);const o=await n.$ok.shared.monaco.load();t.setAttribute("data-lang","js"===e?"javascript":e);const r=getComputedStyle(n.$el).getPropertyValue("--ok-monaco-theme").trim()||"vs-dark";t.dataset.monacoSource=t.textContent,await o.editor.colorizeElement(t,{theme:r});const a=t.querySelectorAll("br");a[a.length-1]?.remove()}catch(e){}return l.append(t),o}};var a={tag:"ok-doc-viewer",dependencies:[e],attr:{anchor:{},file:{},root:{default:"/docs/"},prefix:{default:"#/docs/"},blocks:{default:()=>[]},codeBlock:{default:null},preprocess:{default:null},postprocess:{default:null},noDefaultBlocks:{default:!1,empty:!0},headingLevels:{default:()=>[1,2,3]},sidebarTitle:{default:"On this page"},scrollOffset:{default:80},iconSet:{default:"lucide"},manifest:{default:null}},context(e){const a=()=>new URL(e.$attr.root,document.baseURI).href;function i(){const t=e.$attr.headingLevels;return Array.isArray(t)?t.map(Number):"string"==typeof t?t.split(",").map(e=>Number(e.trim())):[1,2,3]}function l(n){const r={blocks:[],index:0};return n=function(e,n,o){for(const r of o){const o=Array.isArray(r.name)?r.name.join("|"):r.name,a=new RegExp(`:::[ \\t]*(${o})\\b([\\s\\S]*?):::`,"g");e=e.replace(a,(e,o,a)=>{const i=n.index++,l="params"in r?Object.fromEntries(Object.entries(r.params).map(([e,n])=>[e,t(a,n)])):void 0;return n.blocks.push({id:i,block:r,options:{name:o,content:a,fence:e=>t(a,e),params:l}}),`<span class="ok-docs-block" data-block="${i}"></span>`})}return e}(n,r,e.$attr.noDefaultBlocks?[...e.$attr.blocks]:[...o,...e.$attr.blocks]),n=function(e,t,n="lucide"){const o=[];return e.replace(/(```[\s\S]*?```|`[^`\n]+`)/g,e=>(o.push(e),`\0${o.length-1}\0`)).replace(/:([a-z0-9_-]+(?:\/[a-z0-9_-]+)?):/gi,(e,o)=>{const r=o.indexOf("/"),a=-1!==r?o.slice(0,r):n,i=-1!==r?o.slice(r+1):o,l=t.index++;return t.blocks.push({id:l,inline:!0,renderInline(){const e=document.createElement("ok-icon");return e.setAttribute("name",i),e.setAttribute("set",a),e}}),`<span class="ok-docs-block" data-block="${l}"></span>`}).replace(/\x00(\d+)\x00/g,(e,t)=>o[Number(t)])}(n,r,e.$attr.iconSet||"lucide"),{md:n,bag:r}}async function c(t,n){const o=a(),i=new URL(a()+e.$attr.file,document.baseURI).href;t.querySelectorAll("a[href]").forEach(t=>{const n=t.getAttribute("href");if(!n||/^(https?:)?\/\//.test(n)||n.startsWith("#"))return;const r=new URL(n,i);if(!r.href.startsWith(o))return;let a=r.href.replace(o,"").replace(/^\//,"");a.endsWith(".md")&&(a=a.slice(0,-3)),t.setAttribute("href",e.$attr.prefix+a+r.hash)});for(const o of n.blocks){const n=t.querySelector(`.ok-docs-block[data-block="${o.id}"]`);if(!n)continue;let r;if(o.inline)r=[o.renderInline()];else{const e=await o.block.render(o.options);r=Array.isArray(e)?e:[e]}n.replaceWith(...r);for(const t of r)await e.$ok.init(t)}const l=e.$attr.codeBlock||r;for(const n of[...t.querySelectorAll("pre code")]){if(!n.textContent.includes("\n"))continue;const t=n.closest("pre"),o=[...n.classList].find(e=>e.startsWith("language-"))?.replace("language-","")||"plaintext",r=await l.render({lang:o,code:n,scope:e}),a=Array.isArray(r)?r:[r];t.replaceWith(...a)}return[...t.childNodes]}let s=null,d=null,p=!1,m=!1,g=null,f=e.$attr.file;const u={markedEl:null,sidebarEl:null,headings:[],loading:!!e.$attr.file,error:null,get filteredHeadings(){const e=i();return this.headings.filter(t=>e.includes(t.level))},get prevDoc(){const t=e.$attr.manifest;if(!t?.length)return null;const o=n(t),r=(e.$attr.file||"").replace(/\.md$/,""),a=o.findIndex(e=>(e.file||"").replace(/\.md$/,"")===r);if(a<=0)return null;const i=o[a-1];return{...i,href:e.$attr.prefix+(i.file||"").replace(/\.md$/,"")}},get nextDoc(){const t=e.$attr.manifest;if(!t?.length)return null;const o=n(t),r=(e.$attr.file||"").replace(/\.md$/,""),a=o.findIndex(e=>(e.file||"").replace(/\.md$/,"")===r);if(a<0||a>=o.length-1)return null;const i=o[a+1];return{...i,href:e.$attr.prefix+(i.file||"").replace(/\.md$/,"")}},preprocessFn:t=>e.$attr.preprocess?e.$attr.preprocess(t,l):l(t),postprocessFn:async(t,n)=>e.$attr.postprocess?e.$attr.postprocess(t,n,c):c(t,n),get src(){return a()+e.$attr.file},resetHeadings(e){this.headings=[...e.querySelectorAll("h1,h2,h3,h4,h5,h6")].map(e=>(e.id||(e.id=e.textContent.trim().toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")),{level:Number(e.tagName[1]),text:e.textContent.trim(),id:e.id}))},resetAnchors(t){const n=i().map(e=>`h${e}`).join(","),o=[...t.querySelectorAll(n)];s?.stop(),g=function(e){for(;e&&e!==document.body;){if(/auto|scroll/.test(getComputedStyle(e).overflowY))return e;e=e.parentElement}return window}(t),s=e.$listen(g,"scroll",()=>{if(p)return clearTimeout(d),void(d=setTimeout(()=>p=!1,500));const t=function(t,n){const o=(n===window?0:n.getBoundingClientRect().top)+(Number(e.$attr.scrollOffset)||80);let r=null;for(const e of t){if(!(e.getBoundingClientRect().top<=o))break;r=e}return r}(o,g);if(!t)return;const n=t.id;e.$attr.anchor!==n&&(m=!0,e.$dispatch("anchor-change",n))})},anchorChanged(t=!1){p=!0;const n=e.$attr.anchor;if(n){const e=this.markedEl?.querySelector(`[id="${n}"]`);e&&e.scrollIntoView({behavior:t?"instant":"smooth",block:"start"})}else g&&g!==window?g.scrollTo({top:0,behavior:t?"instant":"smooth"}):window.scrollTo({top:0,behavior:t?"instant":"smooth"});clearTimeout(d),d=setTimeout(()=>p=!1,500)},loaded(t){p=!0,this.loading=!1,this.error=null,f=e.$attr.file,this.resetHeadings(t),this.resetAnchors(t),e.$dispatch("loaded",{container:t,headings:this.headings}),t.$scope.$ok.nextFrame(()=>{u.anchorChanged(!0),clearTimeout(d),d=setTimeout(()=>p=!1,500)})},onError(t){this.loading=!1,this.error=t?.error?.message||t?.message||"Failed to load document",e.$dispatch("error",t)},sidebarClick(t,n){n?.preventDefault(),e.$dispatch("heading-click",{id:t.id,text:t.text,level:t.level}),e.$dispatch("anchor-change",t.id)}};return e.$watch(()=>[e.$attr.file,e.$attr.anchor],()=>m?(m=!1,void requestAnimationFrame(()=>{u.sidebarEl?.querySelector(".sidebar__link.active")?.scrollIntoView({block:"nearest",behavior:"smooth"})})):e.$attr.file!==f?(u.loading=!0,void(u.error=null)):void u.anchorChanged()),u},mounted(e){e.$listen(e.$el,"transitionstart",t=>{if("--ok-monaco-theme"!==t.propertyName)return;const n=getComputedStyle(e.$el).getPropertyValue("--ok-monaco-theme").trim()||"vs-dark";for(const t of e.$el.querySelectorAll("[data-lang]"))t.dataset.monacoSource&&(t.textContent=t.dataset.monacoSource),window.monaco?.editor.colorizeElement(t,{theme:n})})},template:'<div class="doc-viewer__layout"><div class="doc-viewer__main"><if :="loading"><div class="doc-viewer__loading"><div class="doc-viewer__spinner"/></div></if><if :="error"><div class="doc-viewer__error"><div class="doc-viewer__error-icon">⚠</div><div class="doc-viewer__error-message">{{ error }}</div></div></if><ok-marked class="doc-viewer__content md" :class="{ \'doc-viewer__content--hidden\': loading || !!error }" @mount="markedEl = $el" @loaded="loaded($event.detail.container)" @error="onError($event.detail)" :src :preprocess="preprocessFn" :postprocess="postprocessFn"/><if :="prevDoc || nextDoc"><nav class="doc-viewer__nav"><if :="prevDoc"><a class="doc-viewer__nav-link doc-viewer__nav-prev" :href="prevDoc.href">← {{ prevDoc.label }}</a></if><if :="nextDoc"><a class="doc-viewer__nav-link doc-viewer__nav-next" :href="nextDoc.href">{{ nextDoc.label }} →</a></if></nav></if></div><if :="filteredHeadings.length > 0"><div class="doc-viewer__sidebar" :ref="sidebarEl = $el"><slot name="sidebar-top"/><div class="sidebar__title">{{ $props.sidebarTitle }}</div><each :of="filteredHeadings" let:item="h"><a class="sidebar__link" :class="{ active: $props.anchor === h.id }" :style="{ \'--level\': h.level }" :level="h.level" :href="\'#\' + h.id" @click="sidebarClick(h, $event)">{{ h.text }}</a></each><slot name="sidebar-bottom"/></div></if></div>',style:['\n@property --ok-monaco-theme {\n syntax: \'<custom-ident>\';\n inherits: true;\n initial-value: vs-dark;\n}\n[tag] { display: block; width: 100%; transition: --ok-monaco-theme 1ms allow-discrete; }\n\n[tag] .doc-viewer__layout {\n display: flex;\n align-items: flex-start;\n gap: 2rem;\n padding: 2rem;\n box-sizing: border-box;\n}\n\n[tag] .doc-viewer__main {\n flex: 1;\n min-width: 0;\n max-width: 760px;\n}\n\n[tag] .doc-viewer__sidebar {\n position: sticky;\n top: 100px;\n max-width: 240px;\n max-height: calc(100vh - 120px);\n padding-left: 1.2rem;\n padding-right: 0.4rem;\n display: flex;\n flex-direction: column;\n overflow-y: auto;\n border-left: 1px solid var(--ok_color-muted-border, #333);\n scrollbar-width: thin;\n align-self: flex-start;\n}\n\n[tag] .sidebar__title {\n font-size: 11px;\n letter-spacing: 1px;\n color: var(--ok_color-muted-fg, #888);\n margin-bottom: 8px;\n text-transform: uppercase;\n opacity: 0.8;\n flex-shrink: 0;\n}\n\n[tag] .sidebar__link {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 3px 0;\n cursor: pointer;\n font-size: 13px;\n color: var(--ok_color-fg, #eee);\n text-decoration: none;\n transition: color .15s ease;\n position: relative;\n margin-left: calc((var(--level, 1) - 1) * 12px);\n}\n\n[tag] .sidebar__link::before {\n content: "";\n position: absolute;\n left: -10px;\n width: 2px;\n height: 100%;\n background: transparent;\n transition: background .15s ease;\n border-radius: 1px;\n}\n\n[tag] .sidebar__link.active::before { background: var(--ok_color-accent, #4ea1ff); }\n[tag] .sidebar__link:hover { color: var(--ok_color-accent, #4ea1ff); }\n[tag] .sidebar__link[level="1"] { font-weight: 600; opacity: 0.9; margin-top: 4px; }\n\n/* ── Loading ─────────────────────────────────────────────────────────── */\n[tag] .doc-viewer__loading {\n display: flex;\n justify-content: center;\n padding: 4rem 0;\n}\n[tag] .doc-viewer__spinner {\n width: 28px;\n height: 28px;\n border: 3px solid rgba(255,255,255,0.08);\n border-top-color: var(--ok_color-accent, #4ea1ff);\n border-radius: 50%;\n animation: ok-dv-spin 0.7s linear infinite;\n}\n@keyframes ok-dv-spin { to { transform: rotate(360deg); } }\n\n/* ── Error ───────────────────────────────────────────────────────────── */\n[tag] .doc-viewer__error {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 0.75rem;\n padding: 4rem 0;\n color: var(--ok_color-fg, #eee);\n opacity: 0.65;\n text-align: center;\n}\n[tag] .doc-viewer__error-icon { font-size: 2rem; }\n[tag] .doc-viewer__error-message { font-size: 0.9rem; }\n[tag] .doc-viewer__content--hidden { display: none; }\n\n/* ── Prev / Next nav ─────────────────────────────────────────────────── */\n[tag] .doc-viewer__nav {\n display: flex;\n justify-content: space-between;\n align-items: flex-start;\n margin-top: 3rem;\n padding-top: 1.5rem;\n border-top: 1px solid var(--ok_color-muted-border, #333);\n gap: 1rem;\n}\n[tag] .doc-viewer__nav-link {\n color: var(--ok_color-accent, #4ea1ff);\n text-decoration: none;\n font-size: 0.9rem;\n opacity: 0.85;\n transition: opacity 0.15s;\n max-width: 45%;\n}\n[tag] .doc-viewer__nav-link:hover { opacity: 1; }\n[tag] .doc-viewer__nav-next { margin-left: auto; text-align: right; }\n\n/* ── Responsive ──────────────────────────────────────────────────────── */\n@media (max-width: 768px) {\n [tag] .doc-viewer__layout { flex-direction: column; padding: 1rem; gap: 1.5rem; }\n [tag] .doc-viewer__main { max-width: 100%; }\n [tag] .doc-viewer__sidebar {\n position: static;\n max-width: 100%;\n max-height: none;\n border-left: none;\n border-top: 1px solid var(--ok_color-muted-border, #333);\n padding: 0.8rem 0 0;\n overflow-y: visible;\n flex-direction: row;\n flex-wrap: wrap;\n gap: 2px 8px;\n }\n [tag] .sidebar__title { width: 100%; margin-bottom: 4px; }\n [tag] .sidebar__link { margin-left: 0 !important; font-size: 12px; }\n [tag] .sidebar__link::before { display: none; }\n}\n',"\n[tag] .md { line-height: 1.6; }\n\n[tag] .md h1, [tag] .md h2, [tag] .md h3 { font-weight: 600; line-height: 1.25; margin: 2rem 0 0.8rem; }\n[tag] .md h1 { font-size: 2rem; }\n[tag] .md h2 { font-size: 1.55rem; color: var(--ok_color-accent, #4ea1ff); }\n[tag] .md h3 { font-size: 1.25rem; }\n[tag] .md h4 { font-size: 1.1rem; margin: 1.2rem 0 0.6rem; font-weight: 600; }\n[tag] .md h5 { font-size: 1rem; margin: 1rem 0 0.6rem; font-weight: 600; opacity: 0.9; }\n[tag] .md h6 { font-size: 0.9rem; margin: 0.8rem 0 0.5rem; font-weight: 500; opacity: 0.85; }\n\n[tag] .md p { margin: 0.8rem 0; color: var(--ok_color-fg, #eee); }\n[tag] .md ul, [tag] .md ol { padding-left: 1.4rem; margin: 0.8rem 0; }\n[tag] .md li { margin: 0.3rem 0; }\n\n[tag] .md hr {\n border: 0; height: 1px; margin: 2rem 0;\n background: linear-gradient(to right, transparent, #444, transparent);\n opacity: 0.7;\n}\n\n[tag] .md pre {\n margin: 1.4rem 0;\n background: rgba(255,255,255,0.05);\n border-radius: 6px;\n box-shadow: 0 0 0 1px rgba(255,255,255,0.08);\n}\n[tag] .md pre, [tag] .md blockquote { margin: 1.4rem 0; }\n[tag] .md code { font-size: 0.95em; font-family: var(--font-mono, monospace); overflow-x: auto; }\n[tag] .md ok-icon { vertical-align: middle; }\n\n[tag] .ok-code-block {\n margin: 1.4rem 0;\n border-radius: 8px;\n overflow: hidden;\n background: var(--ok_color-code-bg, #1e1e1e);\n border: 1px solid var(--ok_color-code-border, rgba(255,255,255,0.06));\n}\n\n[tag] .ok-code-block__header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n background: var(--ok_color-code-header-bg, #252525);\n padding: 6px 10px;\n font-size: 11px;\n color: var(--ok_color-code-text, #cfcfcf);\n font-family: var(--font-mono, monospace);\n border-bottom: 1px solid var(--ok_color-code-header-border, rgba(255,255,255,0.07));\n}\n\n[tag] .ok-code-block .lang { opacity: 0.8; letter-spacing: 0.03em; }\n\n[tag] .ok-code-block .copy {\n cursor: pointer; color: var(--ok_color-code-copy, #aaa); font-size: 11px;\n padding: 2px 6px; border-radius: 4px; transition: 0.15s; user-select: none;\n}\n[tag] .ok-code-block .copy:hover { color: var(--ok_color-code-copy-hover, white); background: var(--ok_color-code-copy-hover-bg, rgba(255,255,255,0.08)); }\n[tag] .ok-code-block pre { margin: 0 !important; padding: 0.6rem 0.8rem !important; background: transparent !important; }\n\n[tag] .ok-callout {\n display: flex; gap: 0.75rem; padding: 1rem 1.2rem; margin: 1.4rem 0;\n border-radius: 8px; border: 1px solid rgba(255,255,255,0.06);\n background: rgba(255,255,255,0.035);\n}\n[tag] .ok-callout__icon ok-icon { width: 20px; height: 20px; opacity: 0.9; }\n[tag] .ok-callout__content { flex: 1; }\n[tag] .ok-callout__title { font-weight: 600; margin-bottom: 0.25rem; font-size: 0.95rem; }\n[tag] .ok-callout__body { line-height: 1.5; opacity: 0.9; }\n[tag] .ok-callout--note { border-left: 4px solid var(--ok_color-accent, #4ea1ff); }\n[tag] .ok-callout--warning { border-left: 4px solid #ffb24e; background: rgba(255,178,78,0.06); }\n[tag] .ok-callout--tip { border-left: 4px solid #44d07a; background: rgba(68,208,122,0.06); }\n"]};export{a as default};
|
|
1
|
+
import e from"./ok-marked.ok.js";function t(e,t){const n=Array.isArray(t)?t.join("|"):t,o=new RegExp("```(?:"+n+")[^\\n]*\\n([\\s\\S]*?)```","i"),r=e.match(o);return r?r[1].trim():null}function n(e){return!!e.$__unmount__$||!e.$el}function o(e){const t=[];for(const n of e)n.file&&t.push(n),n.children?.length&&t.push(...o(n.children));return t}const r=[{name:["note","warning","tip"],render({name:e,content:t}){const n=t.trim().split("\n");let o=null,r=t.trim();const a=n[0]?.trim();a&&!a.startsWith("<")&&(o=a,r=n.slice(1).join("\n").trim());const i=document.createElement("div");i.className=`ok-callout ok-callout--${e}`;const l=document.createElement("div");l.className="ok-callout__icon",l.innerHTML=`<ok-icon name="${{note:"info",warning:"alert-triangle",tip:"lightbulb"}[e]}"></ok-icon>`;const c=document.createElement("div");if(c.className="ok-callout__content",o){const e=document.createElement("div");e.className="ok-callout__title",e.textContent=o,c.appendChild(e)}const s=document.createElement("div");return s.className="ok-callout__body",s.innerHTML=r,c.appendChild(s),i.appendChild(l),i.appendChild(c),i}},{name:"raw",render({content:e}){const t=document.createElement("div");return t.innerHTML=e.trim(),[...t.childNodes]}}],a={async render({lang:e,code:t,scope:o}){const r=document.createElement("div");r.className="ok-code-block";const a=document.createElement("div");a.className="ok-code-block__header";const i=document.createElement("span");i.className="lang",i.textContent=e.toUpperCase();const l=document.createElement("span");l.className="copy",l.textContent="Copy",l.addEventListener("click",()=>{navigator.clipboard.writeText(t.innerText?.trim()),l.textContent="Copied!",setTimeout(()=>l.textContent="Copy",1200)}),a.appendChild(i),a.appendChild(l);const c=document.createElement("pre");r.appendChild(a),r.appendChild(c);try{if(await o.$ok.componentRegistry.activate(o.$ok.componentRegistry.getRegistration("ok-monaco"),o),n(o))return r;const a=await o.$ok.shared.monaco.load();if(n(o))return r;t.setAttribute("data-lang","js"===e?"javascript":e);const i=getComputedStyle(o.$el).getPropertyValue("--ok-monaco-theme").trim()||"vs-dark";t.dataset.monacoSource=t.textContent,await a.editor.colorizeElement(t,{theme:i});const l=t.querySelectorAll("br");l[l.length-1]?.remove()}catch(e){}return c.append(t),r}};var i={tag:"ok-doc-viewer",dependencies:[e],attr:{anchor:{},file:{},root:{default:"/docs/"},prefix:{default:"#/docs/"},blocks:{default:()=>[]},codeBlock:{default:null},preprocess:{default:null},postprocess:{default:null},noDefaultBlocks:{default:!1,empty:!0},headingLevels:{default:()=>[1,2,3]},sidebarTitle:{default:"On this page"},scrollOffset:{default:80},iconSet:{default:"lucide"},manifest:{default:null}},context(e){const i=()=>new URL(e.$attr.root,document.baseURI).href;function l(){const t=e.$attr.headingLevels;return Array.isArray(t)?t.map(Number):"string"==typeof t?t.split(",").map(e=>Number(e.trim())):[1,2,3]}function c(n){const o={blocks:[],index:0};return n=function(e,n,o){for(const r of o){const o=Array.isArray(r.name)?r.name.join("|"):r.name,a=new RegExp(`:::[ \\t]*(${o})\\b([\\s\\S]*?):::`,"g");e=e.replace(a,(e,o,a)=>{const i=n.index++,l="params"in r?Object.fromEntries(Object.entries(r.params).map(([e,n])=>[e,t(a,n)])):void 0;return n.blocks.push({id:i,block:r,options:{name:o,content:a,fence:e=>t(a,e),params:l}}),`<span class="ok-docs-block" data-block="${i}"></span>`})}return e}(n,o,e.$attr.noDefaultBlocks?[...e.$attr.blocks]:[...r,...e.$attr.blocks]),n=function(e,t,n="lucide"){const o=[];return e.replace(/(```[\s\S]*?```|`[^`\n]+`)/g,e=>(o.push(e),`\0${o.length-1}\0`)).replace(/:([a-z0-9_-]+(?:\/[a-z0-9_-]+)?):/gi,(e,o)=>{const r=o.indexOf("/"),a=-1!==r?o.slice(0,r):n,i=-1!==r?o.slice(r+1):o,l=t.index++;return t.blocks.push({id:l,inline:!0,renderInline(){const e=document.createElement("ok-icon");return e.setAttribute("name",i),e.setAttribute("set",a),e}}),`<span class="ok-docs-block" data-block="${l}"></span>`}).replace(/\x00(\d+)\x00/g,(e,t)=>o[Number(t)])}(n,o,e.$attr.iconSet||"lucide"),{md:n,bag:o}}async function s(t,o){const r=i(),l=new URL(i()+e.$attr.file,document.baseURI).href;t.querySelectorAll("a[href]").forEach(t=>{const n=t.getAttribute("href");if(!n||/^(https?:)?\/\//.test(n)||n.startsWith("#"))return;const o=new URL(n,l);if(!o.href.startsWith(r))return;let a=o.href.replace(r,"").replace(/^\//,"");a.endsWith(".md")&&(a=a.slice(0,-3)),t.setAttribute("href",e.$attr.prefix+a+o.hash)});const c=[],s=async()=>(await Promise.all(c.splice(0).map(t=>e.$ok.destroy(t))),[]);for(const r of o.blocks){const o=t.querySelector(`.ok-docs-block[data-block="${r.id}"]`);if(!o)continue;let a;if(r.inline)a=[r.renderInline()];else{const t=await r.block.render(r.options);if(n(e))return s();a=Array.isArray(t)?t:[t]}o.replaceWith(...a);for(const t of a)if(c.push(t),await e.$ok.init(t),n(e))return s()}const d=e.$attr.codeBlock||a;for(const o of[...t.querySelectorAll("pre code")]){if(!o.textContent.includes("\n"))continue;const t=o.closest("pre"),r=[...o.classList].find(e=>e.startsWith("language-"))?.replace("language-","")||"plaintext",a=await d.render({lang:r,code:o,scope:e});if(n(e))return s();const i=Array.isArray(a)?a:[a];t.replaceWith(...i)}return[...t.childNodes]}let d=null,p=null,m=!1,g=!1,f=null,u=e.$attr.file;const h={markedEl:null,sidebarEl:null,headings:[],loading:!!e.$attr.file,error:null,get filteredHeadings(){const e=l();return this.headings.filter(t=>e.includes(t.level))},get prevDoc(){const t=e.$attr.manifest;if(!t?.length)return null;const n=o(t),r=(e.$attr.file||"").replace(/\.md$/,""),a=n.findIndex(e=>(e.file||"").replace(/\.md$/,"")===r);if(a<=0)return null;const i=n[a-1];return{...i,href:e.$attr.prefix+(i.file||"").replace(/\.md$/,"")}},get nextDoc(){const t=e.$attr.manifest;if(!t?.length)return null;const n=o(t),r=(e.$attr.file||"").replace(/\.md$/,""),a=n.findIndex(e=>(e.file||"").replace(/\.md$/,"")===r);if(a<0||a>=n.length-1)return null;const i=n[a+1];return{...i,href:e.$attr.prefix+(i.file||"").replace(/\.md$/,"")}},preprocessFn:t=>e.$attr.preprocess?e.$attr.preprocess(t,c):c(t),postprocessFn:async(t,n)=>e.$attr.postprocess?e.$attr.postprocess(t,n,s):s(t,n),get src(){return i()+e.$attr.file},resetHeadings(e){this.headings=[...e.querySelectorAll("h1,h2,h3,h4,h5,h6")].map(e=>(e.id||(e.id=e.textContent.trim().toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"")),{level:Number(e.tagName[1]),text:e.textContent.trim(),id:e.id}))},resetAnchors(t){const n=l().map(e=>`h${e}`).join(","),o=[...t.querySelectorAll(n)];d?.stop(),f=function(e){for(;e&&e!==document.body;){if(/auto|scroll/.test(getComputedStyle(e).overflowY))return e;e=e.parentElement}return window}(t),d=e.$listen(f,"scroll",()=>{if(m)return clearTimeout(p),void(p=setTimeout(()=>m=!1,500));const t=function(t,n){const o=(n===window?0:n.getBoundingClientRect().top)+(Number(e.$attr.scrollOffset)||80);let r=null;for(const e of t){if(!(e.getBoundingClientRect().top<=o))break;r=e}return r}(o,f);if(!t)return;const n=t.id;e.$attr.anchor!==n&&(g=!0,e.$dispatch("anchor-change",n))})},anchorChanged(t=!1){m=!0;const n=e.$attr.anchor;if(n){const e=this.markedEl?.querySelector(`[id="${n}"]`);e&&e.scrollIntoView({behavior:t?"instant":"smooth",block:"start"})}else f&&f!==window?f.scrollTo({top:0,behavior:t?"instant":"smooth"}):window.scrollTo({top:0,behavior:t?"instant":"smooth"});clearTimeout(p),p=setTimeout(()=>m=!1,500)},loaded(t){m=!0,this.loading=!1,this.error=null,u=e.$attr.file,this.resetHeadings(t),this.resetAnchors(t),e.$dispatch("loaded",{container:t,headings:this.headings}),t.$scope.$ok.nextFrame(()=>{h.anchorChanged(!0),clearTimeout(p),p=setTimeout(()=>m=!1,500)})},onError(t){this.loading=!1,this.error=t?.error?.message||t?.message||"Failed to load document",e.$dispatch("error",t)},sidebarClick(t,n){n?.preventDefault(),e.$dispatch("heading-click",{id:t.id,text:t.text,level:t.level}),e.$dispatch("anchor-change",t.id)}};return e.$watch(()=>[e.$attr.file,e.$attr.anchor],()=>g?(g=!1,void requestAnimationFrame(()=>{h.sidebarEl?.querySelector(".sidebar__link.active")?.scrollIntoView({block:"nearest",behavior:"smooth"})})):e.$attr.file!==u?(h.loading=!0,void(h.error=null)):void h.anchorChanged()),h},mounted(e){e.$listen(e.$el,"transitionstart",t=>{if("--ok-monaco-theme"!==t.propertyName)return;const n=getComputedStyle(e.$el).getPropertyValue("--ok-monaco-theme").trim()||"vs-dark";for(const t of e.$el.querySelectorAll("[data-lang]"))t.dataset.monacoSource&&(t.textContent=t.dataset.monacoSource),window.monaco?.editor.colorizeElement(t,{theme:n})})},template:'<div class="doc-viewer__layout"><div class="doc-viewer__main"><if :="loading"><div class="doc-viewer__loading"><div class="doc-viewer__spinner"/></div></if><if :="error"><div class="doc-viewer__error"><div class="doc-viewer__error-icon">⚠</div><div class="doc-viewer__error-message">{{ error }}</div></div></if><ok-marked class="doc-viewer__content md" :class="{ \'doc-viewer__content--hidden\': loading || !!error }" @mount="markedEl = $el" @loaded="loaded($event.detail.container)" @error="onError($event.detail)" :src :preprocess="preprocessFn" :postprocess="postprocessFn"/><if :="prevDoc || nextDoc"><nav class="doc-viewer__nav"><if :="prevDoc"><a class="doc-viewer__nav-link doc-viewer__nav-prev" :href="prevDoc.href">← {{ prevDoc.label }}</a></if><if :="nextDoc"><a class="doc-viewer__nav-link doc-viewer__nav-next" :href="nextDoc.href">{{ nextDoc.label }} →</a></if></nav></if></div><if :="filteredHeadings.length > 0"><div class="doc-viewer__sidebar" :ref="sidebarEl = $el"><slot name="sidebar-top"/><div class="sidebar__title">{{ $props.sidebarTitle }}</div><each :of="filteredHeadings" let:item="h"><a class="sidebar__link" :class="{ active: $props.anchor === h.id }" :style="{ \'--level\': h.level }" :level="h.level" :href="\'#\' + h.id" @click="sidebarClick(h, $event)">{{ h.text }}</a></each><slot name="sidebar-bottom"/></div></if></div>',style:['\n@property --ok-monaco-theme {\n syntax: \'<custom-ident>\';\n inherits: true;\n initial-value: vs-dark;\n}\n[tag] { display: block; width: 100%; transition: --ok-monaco-theme 1ms allow-discrete; }\n\n[tag] .doc-viewer__layout {\n display: flex;\n align-items: flex-start;\n gap: 2rem;\n padding: 2rem;\n box-sizing: border-box;\n}\n\n[tag] .doc-viewer__main {\n flex: 1;\n min-width: 0;\n max-width: 760px;\n}\n\n[tag] .doc-viewer__sidebar {\n position: sticky;\n top: 100px;\n max-width: 240px;\n max-height: calc(100vh - 120px);\n padding-left: 1.2rem;\n padding-right: 0.4rem;\n display: flex;\n flex-direction: column;\n overflow-y: auto;\n border-left: 1px solid var(--ok_color-muted-border, #333);\n scrollbar-width: thin;\n align-self: flex-start;\n}\n\n[tag] .sidebar__title {\n font-size: 11px;\n letter-spacing: 1px;\n color: var(--ok_color-muted-fg, #888);\n margin-bottom: 8px;\n text-transform: uppercase;\n opacity: 0.8;\n flex-shrink: 0;\n}\n\n[tag] .sidebar__link {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 3px 0;\n cursor: pointer;\n font-size: 13px;\n color: var(--ok_color-fg, #eee);\n text-decoration: none;\n transition: color .15s ease;\n position: relative;\n margin-left: calc((var(--level, 1) - 1) * 12px);\n}\n\n[tag] .sidebar__link::before {\n content: "";\n position: absolute;\n left: -10px;\n width: 2px;\n height: 100%;\n background: transparent;\n transition: background .15s ease;\n border-radius: 1px;\n}\n\n[tag] .sidebar__link.active::before { background: var(--ok_color-accent, #4ea1ff); }\n[tag] .sidebar__link:hover { color: var(--ok_color-accent, #4ea1ff); }\n[tag] .sidebar__link[level="1"] { font-weight: 600; opacity: 0.9; margin-top: 4px; }\n\n/* ── Loading ─────────────────────────────────────────────────────────── */\n[tag] .doc-viewer__loading {\n display: flex;\n justify-content: center;\n padding: 4rem 0;\n}\n[tag] .doc-viewer__spinner {\n width: 28px;\n height: 28px;\n border: 3px solid rgba(255,255,255,0.08);\n border-top-color: var(--ok_color-accent, #4ea1ff);\n border-radius: 50%;\n animation: ok-dv-spin 0.7s linear infinite;\n}\n@keyframes ok-dv-spin { to { transform: rotate(360deg); } }\n\n/* ── Error ───────────────────────────────────────────────────────────── */\n[tag] .doc-viewer__error {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 0.75rem;\n padding: 4rem 0;\n color: var(--ok_color-fg, #eee);\n opacity: 0.65;\n text-align: center;\n}\n[tag] .doc-viewer__error-icon { font-size: 2rem; }\n[tag] .doc-viewer__error-message { font-size: 0.9rem; }\n[tag] .doc-viewer__content--hidden { display: none; }\n\n/* ── Prev / Next nav ─────────────────────────────────────────────────── */\n[tag] .doc-viewer__nav {\n display: flex;\n justify-content: space-between;\n align-items: flex-start;\n margin-top: 3rem;\n padding-top: 1.5rem;\n border-top: 1px solid var(--ok_color-muted-border, #333);\n gap: 1rem;\n}\n[tag] .doc-viewer__nav-link {\n color: var(--ok_color-accent, #4ea1ff);\n text-decoration: none;\n font-size: 0.9rem;\n opacity: 0.85;\n transition: opacity 0.15s;\n max-width: 45%;\n}\n[tag] .doc-viewer__nav-link:hover { opacity: 1; }\n[tag] .doc-viewer__nav-next { margin-left: auto; text-align: right; }\n\n/* ── Responsive ──────────────────────────────────────────────────────── */\n@media (max-width: 768px) {\n [tag] .doc-viewer__layout { flex-direction: column; padding: 1rem; gap: 1.5rem; }\n [tag] .doc-viewer__main { max-width: 100%; }\n [tag] .doc-viewer__sidebar {\n position: static;\n max-width: 100%;\n max-height: none;\n border-left: none;\n border-top: 1px solid var(--ok_color-muted-border, #333);\n padding: 0.8rem 0 0;\n overflow-y: visible;\n flex-direction: row;\n flex-wrap: wrap;\n gap: 2px 8px;\n }\n [tag] .sidebar__title { width: 100%; margin-bottom: 4px; }\n [tag] .sidebar__link { margin-left: 0 !important; font-size: 12px; }\n [tag] .sidebar__link::before { display: none; }\n}\n',"\n[tag] .md { line-height: 1.6; }\n\n[tag] .md h1, [tag] .md h2, [tag] .md h3 { font-weight: 600; line-height: 1.25; margin: 2rem 0 0.8rem; }\n[tag] .md h1 { font-size: 2rem; }\n[tag] .md h2 { font-size: 1.55rem; color: var(--ok_color-accent, #4ea1ff); }\n[tag] .md h3 { font-size: 1.25rem; }\n[tag] .md h4 { font-size: 1.1rem; margin: 1.2rem 0 0.6rem; font-weight: 600; }\n[tag] .md h5 { font-size: 1rem; margin: 1rem 0 0.6rem; font-weight: 600; opacity: 0.9; }\n[tag] .md h6 { font-size: 0.9rem; margin: 0.8rem 0 0.5rem; font-weight: 500; opacity: 0.85; }\n\n[tag] .md p { margin: 0.8rem 0; color: var(--ok_color-fg, #eee); }\n[tag] .md ul, [tag] .md ol { padding-left: 1.4rem; margin: 0.8rem 0; }\n[tag] .md li { margin: 0.3rem 0; }\n\n[tag] .md hr {\n border: 0; height: 1px; margin: 2rem 0;\n background: linear-gradient(to right, transparent, #444, transparent);\n opacity: 0.7;\n}\n\n[tag] .md pre {\n margin: 1.4rem 0;\n background: rgba(255,255,255,0.05);\n border-radius: 6px;\n box-shadow: 0 0 0 1px rgba(255,255,255,0.08);\n}\n[tag] .md pre, [tag] .md blockquote { margin: 1.4rem 0; }\n[tag] .md code { font-size: 0.95em; font-family: var(--font-mono, monospace); overflow-x: auto; }\n[tag] .md ok-icon { vertical-align: middle; }\n\n[tag] .ok-code-block {\n margin: 1.4rem 0;\n border-radius: 8px;\n overflow: hidden;\n background: var(--ok_color-code-bg, #1e1e1e);\n border: 1px solid var(--ok_color-code-border, rgba(255,255,255,0.06));\n}\n\n[tag] .ok-code-block__header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n background: var(--ok_color-code-header-bg, #252525);\n padding: 6px 10px;\n font-size: 11px;\n color: var(--ok_color-code-text, #cfcfcf);\n font-family: var(--font-mono, monospace);\n border-bottom: 1px solid var(--ok_color-code-header-border, rgba(255,255,255,0.07));\n}\n\n[tag] .ok-code-block .lang { opacity: 0.8; letter-spacing: 0.03em; }\n\n[tag] .ok-code-block .copy {\n cursor: pointer; color: var(--ok_color-code-copy, #aaa); font-size: 11px;\n padding: 2px 6px; border-radius: 4px; transition: 0.15s; user-select: none;\n}\n[tag] .ok-code-block .copy:hover { color: var(--ok_color-code-copy-hover, white); background: var(--ok_color-code-copy-hover-bg, rgba(255,255,255,0.08)); }\n[tag] .ok-code-block pre { margin: 0 !important; padding: 0.6rem 0.8rem !important; background: transparent !important; }\n\n[tag] .ok-callout {\n display: flex; gap: 0.75rem; padding: 1rem 1.2rem; margin: 1.4rem 0;\n border-radius: 8px; border: 1px solid rgba(255,255,255,0.06);\n background: rgba(255,255,255,0.035);\n}\n[tag] .ok-callout__icon ok-icon { width: 20px; height: 20px; opacity: 0.9; }\n[tag] .ok-callout__content { flex: 1; }\n[tag] .ok-callout__title { font-weight: 600; margin-bottom: 0.25rem; font-size: 0.95rem; }\n[tag] .ok-callout__body { line-height: 1.5; opacity: 0.9; }\n[tag] .ok-callout--note { border-left: 4px solid var(--ok_color-accent, #4ea1ff); }\n[tag] .ok-callout--warning { border-left: 4px solid #ffb24e; background: rgba(255,178,78,0.06); }\n[tag] .ok-callout--tip { border-left: 4px solid #44d07a; background: rgba(68,208,122,0.06); }\n"]};export{i as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let t=null,r=null;var
|
|
1
|
+
let t=null,r=null;function e(t,r){return!!t.$__unmount__$||!t.$el||!r.container}var a={tag:"ok-marked",attr:{src:{},text:{},map:{}},context:a=>({loading:!1,error:null,html:"",nodes:[],container:null,async load(){if(a.$attr.text||a.$attr.src){this.error=null,this.loading=!0;try{const n=await(r?Promise.resolve(r):t||(t=import("https://cdn.jsdelivr.net/npm/marked@17.0.0/+esm").then(t=>(r=t.marked||t.default||t,r.setOptions({gfm:!0,breaks:!0,headerIds:!1,mangle:!1}),r)).catch(t=>{throw t}),t));if(e(a,this))return;const i=a.$attr.text||await(await fetch(a.$attr.src)).text();if(e(a,this))return;const{md:s,bag:o}=a.$attr.preprocess?.(i)??{md:i,bag:null},c=n.parse(s),d=document.createElement("div");d.innerHTML=c;const l=await(a.$attr.postprocess?.(d,o));if(e(a,this))return;this.nodes=l||Array.from(d.childNodes),this.container.innerHTML="",this.container.append(...this.nodes),this.loading=!1,a.$dispatch("loaded",{md:s,container:this.container})}catch(t){if(e(a,this))return;this.loading=!1,this.error=t?.message||String(t),a.$dispatch("error",{error:t,src:a.$attr.src})}}}}),mounted(t){this.load(),t.$watch(()=>[t.$attr.text,t.$attr.src],()=>{this.load()})},template:'<if :="loading"/><div :ref="container = $el"/>'};export{a as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
let e=null;const t="https://cdn.jsdelivr.net/npm/monaco-editor@latest/min/vs/loader.js";function n(e){require.config({paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@latest/min/vs"}}),require(["vs/editor/editor.main"],()=>{for(const e of window.__monacoLoaderPending||[])e(window.monaco);delete window.__monacoLoaderPending,e(window.monaco)})}const o="https://cdn.jsdelivr.net/npm/prettier@3.3.3";let a=null;async function r(){return a??=(async()=>{const[e,t,n,a,r]=await Promise.all([import(`${o}/standalone.mjs`),import(`${o}/plugins/babel.mjs`),import(`${o}/plugins/estree.mjs`),import(`${o}/plugins/html.mjs`),import(`${o}/plugins/postcss.mjs`)]);return{prettier:e,plugins:[t.default,n.default,a.default,r.default]}})(),a}let i={};function s(e){if(i={...i,...e},window.monaco?.editor?.getEditors){const{formatOnSave:e,...t}=i;for(const e of monaco.editor.getEditors())e.updateOptions(t)}}function c(){const{formatOnSave:e,...t}=i;return t}function l(e){return null!=e.$attr.theme?e.$attr.theme:getComputedStyle(e.$el).getPropertyValue("--ok-monaco-theme").trim()||"vs-dark"}function d(){return window.monaco?window.monaco:e||(e=new Promise((e,o)=>{if(window.__monacoLoaderPending)return void window.__monacoLoaderPending.push(e);window.__monacoLoaderPending=[e];const a=document.querySelector(`script[src="${t}"]`);if(a)return window.require?.config?void n(e):(a.addEventListener("load",()=>{n(e)},{once:!0}),void a.addEventListener("error",o,{once:!0}));const r=document.createElement("script");r.src=t,r.onload=()=>{n(e)},r.onerror=o,document.head.appendChild(r)}),e)}var
|
|
1
|
+
let e=null;const t="https://cdn.jsdelivr.net/npm/monaco-editor@latest/min/vs/loader.js";function n(e){require.config({paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@latest/min/vs"}}),require(["vs/editor/editor.main"],()=>{for(const e of window.__monacoLoaderPending||[])e(window.monaco);delete window.__monacoLoaderPending,e(window.monaco)})}const o="https://cdn.jsdelivr.net/npm/prettier@3.3.3";let a=null;async function r(){return a??=(async()=>{const[e,t,n,a,r]=await Promise.all([import(`${o}/standalone.mjs`),import(`${o}/plugins/babel.mjs`),import(`${o}/plugins/estree.mjs`),import(`${o}/plugins/html.mjs`),import(`${o}/plugins/postcss.mjs`)]);return{prettier:e,plugins:[t.default,n.default,a.default,r.default]}})(),a}let i={};function s(e){if(i={...i,...e},window.monaco?.editor?.getEditors){const{formatOnSave:e,...t}=i;for(const e of monaco.editor.getEditors())e.updateOptions(t)}}function c(){const{formatOnSave:e,...t}=i;return t}function l(e){return null!=e.$attr.theme?e.$attr.theme:getComputedStyle(e.$el).getPropertyValue("--ok-monaco-theme").trim()||"vs-dark"}function d(e,t){return!!e.$__unmount__$||!e.$el||!t.container}function u(e){e.$cache.themeListener&&(e.$el?.removeEventListener("transitionstart",e.$cache.themeListener),e.$cache.themeListener=null),e.$cache.dropListeners?.(),e.$cache.dropListeners=null,e.$cache.completionDisposable?.dispose(),e.$cache.completionDisposable=null,e.$cache.editor?.dispose(),e.$cache.editor=null}function m(){return window.monaco?window.monaco:e||(e=new Promise((e,o)=>{if(window.__monacoLoaderPending)return void window.__monacoLoaderPending.push(e);window.__monacoLoaderPending=[e];const a=document.querySelector(`script[src="${t}"]`);if(a)return window.require?.config?void n(e):(a.addEventListener("load",()=>{n(e)},{once:!0}),void a.addEventListener("error",o,{once:!0}));const r=document.createElement("script");r.src=t,r.onload=()=>{n(e)},r.onerror=o,document.head.appendChild(r)}),e)}var g={tag:"ok-monaco",attr:{value:{default:""},language:{default:"javascript"},suggestions:{default:()=>[]},theme:{default:null},options:{},autogrow:{default:!1,empty:!0},markers:{default:()=>[]},reveal:{default:null}},register(e){e.shared.monaco={load:m,setDefaults:s}},context:e=>(Object.defineProperty(e.$el,"value",{get:()=>e.$innerContext.value,set(t){e.$innerContext.set(t)},enumerable:!0,configurable:!0}),e.$el.getEditor=()=>e.$cache.editor||null,e.$el.insertText=t=>{const n=e.$cache.editor;if(!n||!window.monaco)return null;const o=n.getPosition()||n.getModel().getFullModelRange().getEndPosition();return n.executeEdits("ok-insert",[{range:new monaco.Range(o.lineNumber,o.column,o.lineNumber,o.column),text:t}]),n.focus(),n.getValue()},e.$cache.completionDisposable=null,{get suggestions(){return e.$attr.suggestions||[]},get language(){return e.$attr.language},value:e.$attr.value||"",editor:null,container:null,ready:!1,set(t){this.value=t,e.$cache.editor&&e.$cache.editor.getValue()!==t&&e.$cache.editor.setValue(""+t)},get(){return this.value},applyReveal(){const t=e.$attr.reveal,n=e.$cache.editor,o=n?.getModel();if(!t||!t.line||!o)return;const a=Math.max(1,Math.min(Number(t.line)||1,o.getLineCount()));n.setPosition({lineNumber:a,column:Math.max(1,t.column||1)}),n.revealLineInCenter(a),n.focus()},applyMarkers(){const t=e.$cache.editor,n=t?.getModel();if(!window.monaco||!n)return;const o={error:monaco.MarkerSeverity.Error,warning:monaco.MarkerSeverity.Warning,info:monaco.MarkerSeverity.Info,hint:monaco.MarkerSeverity.Hint},a=n.getLineCount(),r=e=>Math.max(1,Math.min(Number(e)||1,a)),i=(e.$attr.markers||[]).map(e=>{const t=r(e.line),a=r(e.endLine||e.line);return{message:String(e.message||"Error"),severity:o[e.severity]??monaco.MarkerSeverity.Error,startLineNumber:t,startColumn:Math.max(1,e.column||1),endLineNumber:a,endColumn:e.endColumn||n.getLineMaxColumn(a)}});monaco.editor.setModelMarkers(n,"ok",i)},registerSuggestions(){window.monaco&&this.language&&this.suggestions.length&&(e.$cache.completionDisposable?.dispose(),e.$cache.completionDisposable=monaco.languages.registerCompletionItemProvider(this.language,{provideCompletionItems:t=>{if(t!==e.$cache.editor?.getModel())return{suggestions:[]};const n="html"===this.language,o="css"===this.language;return{suggestions:this.suggestions.map(e=>n?{label:`<${e}>`,kind:monaco.languages.CompletionItemKind.Snippet,insertText:`<${e}>\n\t$0\n</${e}>`,insertTextRules:monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,documentation:`Component: ${e}`}:o?{label:e,kind:monaco.languages.CompletionItemKind.Keyword,insertText:e,documentation:`Selector: ${e}`}:{label:e,kind:monaco.languages.CompletionItemKind.Text,insertText:e})}}}))},async initEditor(){try{await m()}catch(t){if(d(e,this))return;throw e.$error("MONACO_LOAD_FAILED",t)}if(d(e,this))return;if(this.registerSuggestions(),function(){if(!window.monaco||window.__okMonacoFormatters)return;window.__okMonacoFormatters=!0;const e={javascript:"babel",typescript:"babel-ts",html:"html",css:"css",json:"json"};for(const[t,n]of Object.entries(e))monaco.languages.registerDocumentFormattingEditProvider(t,{async provideDocumentFormattingEdits(e){try{const{prettier:t,plugins:o}=await r(),a=await t.format(e.getValue(),{parser:n,plugins:o});return[{range:e.getFullModelRange(),text:a}]}catch(e){return[]}}})}(),e.$cache.editor=monaco.editor.create(this.container,{value:this.value,language:this.language,theme:l(e),automaticLayout:!0,fontSize:14,scrollBeyondLastLine:!1,minimap:{enabled:!1},lineNumbersMinChars:2,...c(),...e.$attr.options||{}}),e.$attr.autogrow){const t=e.$cache.editor,n=()=>{const e=t.getContentHeight();this.container.style.height=e+"px",t.layout()};t.onDidContentSizeChange(n),e.$attr.readonly&&t.updateOptions({readOnly:!0,renderLineHighlight:"none",occurrencesHighlight:!1,selectionHighlight:!1}),n()}e.$cache.editor.onDidChangeModelContent(()=>{const t=e.$cache.editor.getValue();t!==this.value&&(this.value=t,e.$dispatch("editor-change",this.value))});const t=monaco.KeyMod.CtrlCmd|monaco.KeyCode.KeyS;e.$cache.editor.addCommand(t,async()=>{if(i.formatOnSave)try{await(e.$cache.editor.getAction("editor.action.formatDocument")?.run())}catch{}e.$dispatch("editor-save",{value:e.$cache.editor.getValue()})}),this.setupDropInsert(),this.applyMarkers(),this.applyReveal(),this.ready=!0},setupDropInsert(){const t=this.container,n=e=>Array.from(e.dataTransfer?.types||[]).includes("application/x-ok-insert"),o=t=>{if(!n(t))return;t.preventDefault(),t.dataTransfer.dropEffect="copy";const o=e.$cache.editor?.getTargetAtClientPoint(t.clientX,t.clientY);o?.position&&e.$cache.editor.setPosition(o.position)},a=t=>{if(!n(t))return;t.preventDefault(),t.stopPropagation();let o=null;try{o=JSON.parse(t.dataTransfer.getData("application/x-ok-insert"))}catch{}if(!o||!o.text&&!o.dep)return;const a=e.$cache.editor;if(o.text){const e=a.getTargetAtClientPoint(t.clientX,t.clientY),n=e?.position||a.getPosition()||{lineNumber:1,column:1};a.executeEdits("ok-insert",[{range:new monaco.Range(n.lineNumber,n.column,n.lineNumber,n.column),text:o.text}]),a.focus()}e.$dispatch("editor-drop",{...o,value:a.getValue()})};t.addEventListener("dragover",o),t.addEventListener("drop",a),e.$cache.dropListeners=()=>{t.removeEventListener("dragover",o),t.removeEventListener("drop",a)}}}),mounted(e){e.$watch(()=>e.$attr.value,t=>{if(e.$cache.editor){const t=e.$cache.editor,n=t.getValue(),o=e.$attr.value||"";if(n!==o){const e=t.getPosition(),n=t.getScrollTop(),a=t.getScrollLeft();t.setValue(""+o),e&&t.setPosition(e),t.setScrollTop(n),t.setScrollLeft(a)}}}),e.$watch(()=>e.$attr.suggestions,e=>{this.registerSuggestions()}),e.$watch(()=>e.$attr.markers,()=>{this.applyMarkers()}),e.$watch(()=>e.$attr.reveal,()=>{this.applyReveal()}),e.$watch(()=>e.$attr.value,()=>{this.applyMarkers()}),e.$watch(()=>e.$attr.language,t=>{e.$cache.editor&&e.$cache.editor.getModel()&&(monaco.editor.setModelLanguage(e.$cache.editor.getModel(),t[0].newValue),this.registerSuggestions())}),e.$watch(()=>e.$attr.theme,()=>{window.monaco&&e.$cache.editor&&monaco.editor.setTheme(l(e))})},async init(e){if(await this.initEditor(),d(e,this))return void u(e);const t=t=>{"--ok-monaco-theme"===t.propertyName&&null==e.$attr.theme&&window.monaco&&e.$cache.editor&&monaco.editor.setTheme(l(e))};e.$el.addEventListener("transitionstart",t),e.$cache.themeListener=t},unmounted(e){u(e)},template:'<div style="width:100%;height:100%" :ref="container = $el"/>',style:'@property --ok-monaco-theme{syntax:"<custom-ident>";inherits:true;initial-value:vs-dark}[tag]{display:flex;flex-direction:column;flex:1;min-height:0;min-width:0;transition:--ok-monaco-theme 1ms allow-discrete}'};export{g as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,e){let s=0,i=t.length-1;for(;s<=i;){const l=Math.floor((s+i)/2);t[l]<e?s=l+1:i=l-1}return s}var e={tag:"virtualized",attr:{items:{alias:[""],default:[]}},context(e){const s=[],i=[];let l=0,o=0,r=new Set,h=0,n=!1,a=!1,c=null,d=0,g=null,p=1/0,u=!1,m=null,f=!1,v=0,b=0;return{get firstLoad(){return e.$attr.firstLoad||10},get overscan(){return Math.max(e.$attr.overscan||2,1)},get defaultHeight(){return Number.parseInt(e.$attr.defaultHeight??50)},get averageHeight(){return null!=e.$attr.defaultHeight?this.defaultHeight:o>0?l/o:50},holeHeight(){return null!=e.$attr.defaultHeight?this.defaultHeight:c??(c=this.averageHeight)},get items(){return e.$attr.items||[]},get itemClass(){return e.$attr.itemClass||"virtualized-item"},get pinBottom(){return"bottom"===e.$attr.pin||"bottom"===e.$attr.start},get pinTop(){return"top"===e.$attr.pin},atTop:!0,atBottom:!1,following:!1,scrollTop:0,windowTop:0,gapBottom:0,contentHeight:0,start:0,startVisible:0,endVisible:0,end:0,view:[],scroller:null,rebuildAcc(){this.rebuildAccFrom(0)},rebuildAccFrom(t){const e=this.holeHeight();i.length=s.length;for(let l=t;l<s.length;l++)i[l]=(i[l-1]||0)+(s[l]??e);p=1/0},syncHeights(){s.length=this.items.length,this.rebuildAcc()},syncView(t){const e=this.view;if(0===e.length)return void(t.length&&e.push(...t));const s=e.length,i=new Map;for(let t=0;t<s;t++)i.has(e[t])||i.set(e[t],t);let l=0,o=0;for(let s=0;s<t.length;s++){const r=t[s],h=i.get(r);if(void 0===h||h<l)e.splice(o,0,r);else{const t=h-l;t>0&&e.splice(o,t),l=h+1}o++}const r=s-l;r>0&&e.splice(o,r)},handleUnshift(t){const e=t>0&&this.pinTop&&this.scroller;if(s.unshift(...Array(t)),this.rebuildAcc(),e){const e=t*this.holeHeight();this.update(!0),this.scroller.scrollTop+=e,m=v=this.scroller.scrollTop,b=this.endOffset(i[this.items.length-1]||0),this.onScroll({target:this.scroller})}},handlePush(t){const e=this.holeHeight();for(let l=0;l<t;l++){const t=i.length>0?i[i.length-1]:0;s.push(void 0),i.push(t+e)}},handlePop(){s.pop(),i.pop()},handleShift(){s.shift(),this.rebuildAcc()},handleSplice(t,e,i){s.splice(t,e,...Array(i)),this.rebuildAcc()},handleReplace(){s.length=0,s.length=this.items.length,this.rebuildAcc()},scheduleUpdate(t=!1){n||=t,a||(a=!0,setTimeout(()=>{a=!1,this.update(n),n=!1},100))},update(s){if(!(this.scroller&&e.$el instanceof Element&&e.$el.isConnected))return;if(Date.now()-d>200){let t=p;if(null==e.$attr.defaultHeight&&o>0){const e=this.averageHeight;(null==c||Math.abs(e-c)>.5)&&(c=e,t=0)}t!==1/0&&this.rebuildAccFrom(t)}const l=i[this.items.length-1]||0;!u&&"bottom"===e.$attr.start&&this.items.length>0&&(u=!0,this.following=!0);const r=this.pinBottom&&this.following;let n=null!=h?h:this.scrollTop;if((r||n>=l)&&(n=Math.max(0,l-this.scroller.clientHeight)),h=n,r&&this.snapToEnd(l),!s&&n===this.scrollTop&&this.view.length>0)return;const a=t(i,n),g=t(i,n+this.scroller.clientHeight),m=Math.max(a-this.overscan,0),f=Math.min(g+this.overscan,this.items.length-1);if(m===this.start&&f===this.end&&!s)return;this.scrollTop=n,this.start=m,this.end=f,this.startVisible=Math.max(m,a),this.endVisible=Math.min(f,g),this.windowTop=i[this.start-1]||0,this.gapBottom=l-(i[this.end]||0),this.syncView(this.items.slice(this.start,this.end+1)),this.contentHeight=l;const v=getComputedStyle(e.$el),b=parseFloat(v.minHeight)||0,x=parseFloat(v.maxHeight)||1/0,T=Math.max(b,Math.min(l,x));this.scroller.style.height=T+1+"px",this.atTop=this.scrollTop<=5,this.atBottom=this.isAtEnd(this.scrollTop,l)},get bottomSlack(){return Math.max(24,this.holeHeight())},distanceToEnd(t,e){return e-(t+this.scroller.clientHeight)},isAtEnd(t,e,s=this.bottomSlack){return this.distanceToEnd(t,e)<=s},endOffset(t){return Math.max(0,t-this.scroller.clientHeight)},snapToEnd(t){f||(f=!0,e.$ok.nextFrame(()=>{if(f=!1,!this.scroller||!e.$el.isConnected||!this.following)return;const s=Math.max(this.scroller.scrollHeight,t);this.scroller.scrollTop=s,m=this.scroller.scrollTop,v=m,b=this.endOffset(t),this.isAtEnd(m,t)||this.scheduleUpdate(!0)}))},updateItemSize(t){const e=t.$vars.index+this.start;if(e>=this.items.length)return;const i=t.$el.offsetHeight,r=s[e];r!==i?(l+=i-(r||0),r||o++,s[e]=i,p=Math.min(p,e),this.scheduleUpdate(!0)):this.scheduleUpdate()},itemMounted(t){r.add(t),e.$ok.nextFrame(()=>{r.delete(t),this.updateItemSize(t);const s=t.$el;e.$cache.virtualized.resizeMap.set(s,t),e.$cache.virtualized.resizeObserver.observe(s)})},itemUnmounted(t){const s=e.$cache.virtualized;t?.$el&&s.resizeObserver&&(s.resizeObserver.unobserve(t.$el),s.resizeMap.delete(t.$el))},onScroll(t){h=t.target.scrollTop;const e=null!==m&&Math.abs(h-m)<=.5;if(m=null,e||(d=Date.now()),this.pinBottom&&!e){const t=i[this.items.length-1]||0,e=this.endOffset(t),s=Math.max(0,b-e),l=v-h;this.following?l>s+.5&&(this.following=!1):h>v+.5&&this.isAtEnd(h,t)&&(this.following=!0),b=e,this.atBottom=this.isAtEnd(h,t)}v=h,this.update(!1),clearTimeout(g),g=setTimeout(()=>this.update(!0),250)},scrollTo(t,{smooth:e=!1}={}){if(!this.scroller)return;const s=Math.max(0,t);e&&"function"==typeof this.scroller.scrollTo?this.scroller.scrollTo({top:s,behavior:"smooth"}):(this.scroller.scrollTop=s,this.onScroll({target:this.scroller}))},scrollToTop(t){this.scrollTo(0,t)},scrollToEnd(t){this.scroller&&this.scrollTo(this.scroller.scrollHeight,t)},scrollToIndex(t,{align:e="start",smooth:s=!1}={}){if(!this.scroller||!this.items.length)return;const l=Math.max(0,Math.min(t,this.items.length-1)),o=i[l-1]||0,r=i[l]??o;let h=o;"center"===e?h=o-(this.scroller.clientHeight-(r-o))/2:"end"===e&&(h=r-this.scroller.clientHeight),this.scrollTo(h,{smooth:s})},scrollToItem(t,e){const s="function"==typeof t?this.items.findIndex(t):this.items.indexOf(t);-1!==s&&this.scrollToIndex(s,e)}}},mount(t){t.$el.scrollTo=(t,e)=>this.scrollTo(t,e),t.$el.scrollToTop=t=>this.scrollToTop(t),t.$el.scrollToEnd=t=>this.scrollToEnd(t),t.$el.scrollToIndex=(t,e)=>this.scrollToIndex(t,e),t.$el.scrollToItem=(t,e)=>this.scrollToItem(t,e);const e=t.$cache.virtualized={resizeMap:new WeakMap,resizeObserver:null};e.resizeObserver=new ResizeObserver(s=>{t.$ok.nextFrame(()=>{for(const t of s){const s=e.resizeMap.get(t.target);s&&this.updateItemSize(s)}})});const s=t=>{if(Array.isArray(t.target))if("length"===t.property){switch(t.mode){case"splice":const[e,s,...i]=t.args;this.handleSplice(e,s,i.length);break;case"push":this.handlePush(t.args.length);break;case"pop":this.handlePop();break;case"shift":this.handleShift();break;case"unshift":this.handleUnshift(t.args.length);break;default:this.handleReplace()}this.scheduleUpdate(!0)}else"set"===t.mode&&this.scheduleUpdate(!0)};t.$watch(()=>this.items,()=>{this.syncHeights(),this.scheduleUpdate(!0),t.$observe(this.items,null,s)}).run()},template:'<slot name="before"/><div :ref="scroller=$el" style="min-height:100%;overflow:auto;margin:0;position:relative;overflow-anchor:none" @scroll="onScroll"><div class="virtual-body" style="position:relative;overflow:hidden;width:100%" :style="{ \'height\': contentHeight + \'px\', \'--virt-avg\': averageHeight + \'px\', \'--virt-gap-top\': windowTop + \'px\', \'--virt-gap-bottom\': gapBottom + \'px\' }"><div class="virtual-window" style="position:absolute;left:0;right:0;z-index:1" :style="{ \'top\': windowTop + \'px\' }"><slot name="top"/><each :of="view" let:item let:index><div @mounted="itemMounted" @unmounted="itemUnmounted" :class="{[itemClass]: true, \'--visible\': index + start >= startVisible && index + start <= endVisible }"><slot :var:item="item" :var:index="index + start"/></div></each><slot name="bottom"/></div></div></div><slot name="after"/>',style:"[tag]{position:relative;overflow:hidden;flex-grow:1;max-height:100%}[tag] .virtual-body::after,[tag] .virtual-body::before{content:'';position:absolute;left:0;right:0;background:var(--ok_virtualized-skeleton, repeating-linear-gradient(\n to bottom,\n color-mix(in srgb, currentColor 7%, transparent) 0\n calc(max(var(--virt-avg, 50px) - 8px, 8px)),\n transparent calc(max(var(--virt-avg, 50px) - 8px, 8px))\n max(var(--virt-avg, 50px), 16px)\n ))}[tag] .virtual-body::before{top:0;height:var(--virt-gap-top, 0px)}[tag] .virtual-body::after{bottom:0;height:var(--virt-gap-bottom, 0px)}"};export{e as default};
|
|
1
|
+
function t(t,e){let s=0,i=t.length-1;for(;s<=i;){const l=Math.floor((s+i)/2);t[l]<e?s=l+1:i=l-1}return s}var e={tag:"virtualized",attr:{items:{alias:[""],default:()=>[]}},context(e){const s=[],i=[];let l=0,o=0,r=new Set,h=0,n=!1,a=!1,c=null,d=0,g=null,p=1/0,u=!1,m=null,f=!1,v=0,b=0;return{get firstLoad(){return e.$attr.firstLoad||10},get overscan(){return Math.max(e.$attr.overscan||2,1)},get defaultHeight(){return Number.parseInt(e.$attr.defaultHeight??50)},get averageHeight(){return null!=e.$attr.defaultHeight?this.defaultHeight:o>0?l/o:50},holeHeight(){return null!=e.$attr.defaultHeight?this.defaultHeight:c??(c=this.averageHeight)},get items(){return e.$attr.items||[]},get itemClass(){return e.$attr.itemClass||"virtualized-item"},get pinBottom(){return"bottom"===e.$attr.pin||"bottom"===e.$attr.start},get pinTop(){return"top"===e.$attr.pin},atTop:!0,atBottom:!1,following:!1,scrollTop:0,windowTop:0,gapBottom:0,contentHeight:0,start:0,startVisible:0,endVisible:0,end:0,view:[],scroller:null,rebuildAcc(){this.rebuildAccFrom(0)},rebuildAccFrom(t){const e=this.holeHeight();i.length=s.length;for(let l=t;l<s.length;l++)i[l]=(i[l-1]||0)+(s[l]??e);p=1/0},syncHeights(){s.length=this.items.length,this.rebuildAcc()},syncView(t){const e=this.view;if(0===e.length)return void(t.length&&e.push(...t));const s=e.length,i=new Map;for(let t=0;t<s;t++)i.has(e[t])||i.set(e[t],t);let l=0,o=0;for(let s=0;s<t.length;s++){const r=t[s],h=i.get(r);if(void 0===h||h<l)e.splice(o,0,r);else{const t=h-l;t>0&&e.splice(o,t),l=h+1}o++}const r=s-l;r>0&&e.splice(o,r)},handleUnshift(t){const e=t>0&&this.pinTop&&this.scroller;if(s.unshift(...Array(t)),this.rebuildAcc(),e){const e=t*this.holeHeight();this.update(!0),this.scroller.scrollTop+=e,m=v=this.scroller.scrollTop,b=this.endOffset(i[this.items.length-1]||0),this.onScroll({target:this.scroller})}},handlePush(t){const e=this.holeHeight();for(let l=0;l<t;l++){const t=i.length>0?i[i.length-1]:0;s.push(void 0),i.push(t+e)}},handlePop(){s.pop(),i.pop()},handleShift(){s.shift(),this.rebuildAcc()},handleSplice(t,e,i){s.splice(t,e,...Array(i)),this.rebuildAcc()},handleReplace(){s.length=0,s.length=this.items.length,this.rebuildAcc()},scheduleUpdate(t=!1){n||=t,a||(a=!0,setTimeout(()=>{a=!1,this.update(n),n=!1},100))},update(s){if(!(this.scroller&&e.$el instanceof Element&&e.$el.isConnected))return;if(Date.now()-d>200){let t=p;if(null==e.$attr.defaultHeight&&o>0){const e=this.averageHeight;(null==c||Math.abs(e-c)>.5)&&(c=e,t=0)}t!==1/0&&this.rebuildAccFrom(t)}const l=i[this.items.length-1]||0;!u&&"bottom"===e.$attr.start&&this.items.length>0&&(u=!0,this.following=!0);const r=this.pinBottom&&this.following;let n=null!=h?h:this.scrollTop;if((r||n>=l)&&(n=Math.max(0,l-this.scroller.clientHeight)),h=n,r&&this.snapToEnd(l),!s&&n===this.scrollTop&&this.view.length>0)return;const a=t(i,n),g=t(i,n+this.scroller.clientHeight),m=Math.max(a-this.overscan,0),f=Math.min(g+this.overscan,this.items.length-1);if(m===this.start&&f===this.end&&!s)return;this.scrollTop=n,this.start=m,this.end=f,this.startVisible=Math.max(m,a),this.endVisible=Math.min(f,g),this.windowTop=i[this.start-1]||0,this.gapBottom=l-(i[this.end]||0),this.syncView(this.items.slice(this.start,this.end+1)),this.contentHeight=l;const v=getComputedStyle(e.$el),b=parseFloat(v.minHeight)||0,x=parseFloat(v.maxHeight)||1/0,T=Math.max(b,Math.min(l,x));this.scroller.style.height=T+1+"px",this.atTop=this.scrollTop<=5,this.atBottom=this.isAtEnd(this.scrollTop,l)},get bottomSlack(){return Math.max(24,this.holeHeight())},distanceToEnd(t,e){return e-(t+this.scroller.clientHeight)},isAtEnd(t,e,s=this.bottomSlack){return this.distanceToEnd(t,e)<=s},endOffset(t){return Math.max(0,t-this.scroller.clientHeight)},snapToEnd(t){f||(f=!0,e.$ok.nextFrame(()=>{if(f=!1,!this.scroller||!e.$el.isConnected||!this.following)return;const s=Math.max(this.scroller.scrollHeight,t);this.scroller.scrollTop=s,m=this.scroller.scrollTop,v=m,b=this.endOffset(t),this.isAtEnd(m,t)||this.scheduleUpdate(!0)}))},updateItemSize(t){const e=t.$vars.index+this.start;if(e>=this.items.length)return;const i=t.$el.offsetHeight,r=s[e];r!==i?(l+=i-(r||0),r||o++,s[e]=i,p=Math.min(p,e),this.scheduleUpdate(!0)):this.scheduleUpdate()},itemMounted(t){r.add(t),e.$ok.nextFrame(()=>{r.delete(t),this.updateItemSize(t);const s=t.$el;e.$cache.virtualized.resizeMap.set(s,t),e.$cache.virtualized.resizeObserver.observe(s)})},itemUnmounted(t){const s=e.$cache.virtualized;t?.$el&&s.resizeObserver&&(s.resizeObserver.unobserve(t.$el),s.resizeMap.delete(t.$el))},onScroll(t){h=t.target.scrollTop;const e=null!==m&&Math.abs(h-m)<=.5;if(m=null,e||(d=Date.now()),this.pinBottom&&!e){const t=i[this.items.length-1]||0,e=this.endOffset(t),s=Math.max(0,b-e),l=v-h;this.following?l>s+.5&&(this.following=!1):h>v+.5&&this.isAtEnd(h,t)&&(this.following=!0),b=e,this.atBottom=this.isAtEnd(h,t)}v=h,this.update(!1),clearTimeout(g),g=setTimeout(()=>this.update(!0),250)},scrollTo(t,{smooth:e=!1}={}){if(!this.scroller)return;const s=Math.max(0,t);e&&"function"==typeof this.scroller.scrollTo?this.scroller.scrollTo({top:s,behavior:"smooth"}):(this.scroller.scrollTop=s,this.onScroll({target:this.scroller}))},scrollToTop(t){this.scrollTo(0,t)},scrollToEnd(t){this.scroller&&this.scrollTo(this.scroller.scrollHeight,t)},scrollToIndex(t,{align:e="start",smooth:s=!1}={}){if(!this.scroller||!this.items.length)return;const l=Math.max(0,Math.min(t,this.items.length-1)),o=i[l-1]||0,r=i[l]??o;let h=o;"center"===e?h=o-(this.scroller.clientHeight-(r-o))/2:"end"===e&&(h=r-this.scroller.clientHeight),this.scrollTo(h,{smooth:s})},scrollToItem(t,e){const s="function"==typeof t?this.items.findIndex(t):this.items.indexOf(t);-1!==s&&this.scrollToIndex(s,e)}}},mount(t){t.$el.scrollTo=(t,e)=>this.scrollTo(t,e),t.$el.scrollToTop=t=>this.scrollToTop(t),t.$el.scrollToEnd=t=>this.scrollToEnd(t),t.$el.scrollToIndex=(t,e)=>this.scrollToIndex(t,e),t.$el.scrollToItem=(t,e)=>this.scrollToItem(t,e);const e=t.$cache.virtualized={resizeMap:new WeakMap,resizeObserver:null};e.resizeObserver=new ResizeObserver(s=>{t.$ok.nextFrame(()=>{for(const t of s){const s=e.resizeMap.get(t.target);s&&this.updateItemSize(s)}})});const s=t=>{if(Array.isArray(t.target))if("length"===t.property){switch(t.mode){case"splice":const[e,s,...i]=t.args;this.handleSplice(e,s,i.length);break;case"push":this.handlePush(t.args.length);break;case"pop":this.handlePop();break;case"shift":this.handleShift();break;case"unshift":this.handleUnshift(t.args.length);break;default:this.handleReplace()}this.scheduleUpdate(!0)}else"set"===t.mode&&this.scheduleUpdate(!0)};t.$watch(()=>this.items,()=>{this.syncHeights(),this.scheduleUpdate(!0),t.$observe(this.items,null,s)}).run()},template:'<slot name="before"/><div :ref="scroller=$el" style="min-height:100%;overflow:auto;margin:0;position:relative;overflow-anchor:none" @scroll="onScroll"><div class="virtual-body" style="position:relative;overflow:hidden;width:100%" :style="{ \'height\': contentHeight + \'px\', \'--virt-avg\': averageHeight + \'px\', \'--virt-gap-top\': windowTop + \'px\', \'--virt-gap-bottom\': gapBottom + \'px\' }"><div class="virtual-window" style="position:absolute;left:0;right:0;z-index:1" :style="{ \'top\': windowTop + \'px\' }"><slot name="top"/><each :of="view" let:item let:index><div @mounted="itemMounted" @unmounted="itemUnmounted" :class="{[itemClass]: true, \'--visible\': index + start >= startVisible && index + start <= endVisible }"><slot :var:item="item" :var:index="index + start"/></div></each><slot name="bottom"/></div></div></div><slot name="after"/>',style:"[tag]{position:relative;overflow:hidden;flex-grow:1;max-height:100%}[tag] .virtual-body::after,[tag] .virtual-body::before{content:'';position:absolute;left:0;right:0;background:var(--ok_virtualized-skeleton, repeating-linear-gradient(\n to bottom,\n color-mix(in srgb, currentColor 7%, transparent) 0\n calc(max(var(--virt-avg, 50px) - 8px, 8px)),\n transparent calc(max(var(--virt-avg, 50px) - 8px, 8px))\n max(var(--virt-avg, 50px), 16px)\n ))}[tag] .virtual-body::before{top:0;height:var(--virt-gap-top, 0px)}[tag] .virtual-body::after{bottom:0;height:var(--virt-gap-bottom, 0px)}"};export{e as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e="server-render"===globalThis.__OK_SSG__?.phase,t=e?'\n<div class="main main--ssg">\n <div class="preview preview--ssg">\n <div class="ssg-placeholder">\n <div class="ssg-placeholder__title">Interactive example</div>\n <div class="ssg-placeholder__text">This live editor becomes interactive after hydration.</div>\n </div>\n </div>\n</div>':'\n<if :="window">\n <ok-overlay style="--ok-overlay_bg: rgba(0, 0, 0, 0.5)">\n <ok-window @close="window = false" style="--ok-window_padding: 0; --ok-window_overflow: none;">\n <ok-live-shell no-resize-height @update-content="updateContent($event.detail.tab, $event.detail.content, false)" :tabs="$props.tabs" :filename="$props.filename" :render="$props.render" />\n </ok-window>\n </ok-overlay>\n</if>\n<div class="main">\n <div class="editors" style="width: 70%">\n <div class="header">\n <div class="tabs">\n <each :="tabs" let:item="tab">\n <button class="tab-button" :class="{ active : tab === selectedTab }" @click="selectedTab = tab">\n {{ tab.label }}<if :="tab.error"><span> ⚠</span></if>\n </button>\n </each>\n </div>\n <div class="editor-controls">\n <label title="Auto Update">\n <input type="checkbox" !auto @change="auto && update()" />\n <span style="vertical-align: middle; font-size: 12px;">Auto</span>\n </label>\n <button @click="update()" title="Update"><ok-icon name="play-circle" /></button>\n <button @click="save" title="Save"><ok-icon name="save" /></button>\n <label title="Import">\n <button @click="$el.nextElementSibling.click()">\n <ok-icon name="folder-open" size="16" color="currentColor" />\n </button>\n <input type="file" accept=".json" @change="load" @click:allow="$el.value = null" style="display:none" />\n </label>\n <button @click="reset" title="Reset"><ok-icon name="rotate-ccw" /></button>\n <button @click="toggleWindow" :title="window ? \'Close Window\' : \'Pop Window\'">\n <ok-icon :name="window ? \'x\' : \'external-link\'" />\n </button>\n </div>\n </div>\n\n <ok-monaco\n :language="selectedTab.language"\n :value="getContent(selectedTab)"\n :options="$props.monaco"\n @editor-change="updateContent(selectedTab, $event.detail)"\n ></ok-monaco>\n\n <if :="compileError">\n <div class="error">⚠ {{ compileErrorText }}</div>\n </if>\n </div>\n \n <ok-resizer direction="horizontal" />\n <div :ref="previewEl = $el" class="preview"></div>\n</div>\n<if :="!$props.noResizeHeight">\n <ok-resizer direction="vertical" />\n</if>';var n={tag:"ok-live-shell",attr:{noResizeHeight:{default:!1,empty:!0},filename:{default:"live-shell.json"},monaco:{default:{minimap:{enabled:!1}}},tabs:{default:[{id:"html",label:"HTML",language:"html",error:null,default:""},{id:"context",label:"Context",language:"javascript",error:null,default:"{}"}]},render:{default:async(e,t,n)=>{const o=document.createElement("div");return o.innerHTML="ok-live-shell component loaded. Please provide a render function to display content.",o},description:"Function that receives the sandbox target, should return html to render"}},context(e){let t=null,n=null,o=null;return{previewEl:null,auto:!0,compileError:null,get compileErrorText(){if(!this.compileError)return"";let e=this.compileError;for(;e.cause?.scope;)e=e.cause;return e.message+(e.cause?` because ${e.cause.message}`:"")},get tabs(){return e.$attr.tabs||[]},selectedTab:e.$attr.tabs[0]||null,content:new Map,getContent(e){const t=this.content.get(e.id);return void 0!==t?t:e.default||""},async updateContent(t,n){const o=n??"";this.content.set(t.id,o),this.auto&&await this.update(),e.$dispatch("update-content",{tab:t,content:n})},save(){const t={};for(let e of this.tabs)t[e.id]=this.getContent(e);const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=e.$attr.filename,a.click(),URL.revokeObjectURL(o)},async load(e){const t=e.target.files?.[0];if(!t)return;const n=new FileReader;return new Promise((e,o)=>{n.onload=async()=>{try{const t=JSON.parse(n.result);for(let e of this.tabs)void 0===t[e.id]?this.content.delete(e.id):this.content.set(e.id,t[e.id]);await this.update(),e()}catch(t){this.compileError=t,e()}},n.readAsText(t)})},async update(){try{this.compileError=null;const t=await e.$attr.render(o,this.content,this.tabs);for(let e of[...o.dom.range(n)]){const t=e.$scope;t&&t.$destroy&&t.$destroy()}n.innerHTML="",o.dom.append(n,t)}catch(e){this.compileError=e}},async reset(){for(let e of this.tabs)this.content.set(e.id,e.default||"");await this.update()},async init(){t||(t=this.previewEl.attachShadow({mode:"open"}),n=document.createElement("body"),n.style.margin="0",n.style.padding="0",n.style.overflow="auto",n.style.position="relative",n.style.height="100%",t.append(n),o=e.$ok.OK({env:"sandbox",head:t,body:n}),await this.reset())},window:!1,toggleWindow(t=null){const n={tabs:[],render:e.$attr.render.toString()};for(let e of this.tabs)n.tabs.push({id:e.id,label:e.label,language:e.language,default:this.getContent(e)});e.$ok.shared.popout.pop('<ok-live-shell style="padding:0;height: 100vh;" :tabs :render="(new Function(`return (${render})`))()"></ok-live-shell>',{context:n})}}},mounted(){e||this.init()},template:t,style:'[tag]{flex-grow:1;padding:8px 8px 2px;font-family:"Segoe UI","Inter",sans-serif;background:#2a2a2e;color:#ddd;border-radius:8px;box-shadow:0 2px 10px #0005}[tag] .main{display:flex;flex-grow:1;align-items:stretch;min-height:200px}[tag],[tag] .editors{display:flex;flex-direction:column}[tag] .editors{overflow:hidden;gap:8px}[tag] .header{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap}[tag] .tabs{display:flex;gap:0;border-bottom:1px solid #444}[tag] .editor-controls button,[tag] .tab-button{background:0 0;border:0;color:#aaa;cursor:pointer}[tag] .tab-button{border-bottom:2px solid transparent;padding:6px 12px;font-size:13px;transition:all .2s}[tag] .tab-button.active{color:#fff;border-bottom-color:#66f;font-weight:500}[tag] .editor-controls{margin-inline-start:auto;display:flex;align-items:center;gap:8px}[tag] .editor-controls button{font-size:16px;padding:4px}[tag] .editor-controls button:hover{color:#fff}[tag] .editor-controls input[type=checkbox]{margin-right:4px}[tag] .preview,[tag] ok-monaco{border:1px solid #444;border-radius:4px}[tag] ok-monaco{overflow:hidden;height:200px}[tag] .preview{flex:1;background:#111;padding:10px;overflow:auto}[tag] .main--ssg{min-height:240px}[tag] .preview--ssg{display:flex;align-items:center;justify-content:center}[tag] .ssg-placeholder{max-width:28rem;text-align:center;padding:1.5rem;border:1px solid #334;border-radius:12px;background:rgba(255,255,255,.03)}[tag] .ssg-placeholder__title{color:#fff;font-size:1rem;font-weight:600;margin-bottom:.5rem}[tag] .ssg-placeholder__text{color:#aaa;line-height:1.5}[tag] .error{color:#f66;background:#330;border:1px solid #600;padding:6px 8px;margin-top:6px;border-radius:4px;font-size:13px}'};export{n as default};
|
|
1
|
+
const e="server-render"===globalThis.__OK_SSG__?.phase,t=e?'\n<div class="main main--ssg">\n <div class="preview preview--ssg">\n <div class="ssg-placeholder">\n <div class="ssg-placeholder__title">Interactive example</div>\n <div class="ssg-placeholder__text">This live editor becomes interactive after hydration.</div>\n </div>\n </div>\n</div>':'\n<if :="window">\n <ok-overlay style="--ok-overlay_bg: rgba(0, 0, 0, 0.5)">\n <ok-window @close="window = false" style="--ok-window_padding: 0; --ok-window_overflow: none;">\n <ok-live-shell no-resize-height @update-content="updateContent($event.detail.tab, $event.detail.content, false)" :tabs="$props.tabs" :filename="$props.filename" :render="$props.render" />\n </ok-window>\n </ok-overlay>\n</if>\n<div class="main">\n <div class="editors" style="width: 70%">\n <div class="header">\n <div class="tabs">\n <each :="tabs" let:item="tab">\n <button class="tab-button" :class="{ active : tab === selectedTab }" @click="selectedTab = tab">\n {{ tab.label }}<if :="tab.error"><span> ⚠</span></if>\n </button>\n </each>\n </div>\n <div class="editor-controls">\n <label title="Auto Update">\n <input type="checkbox" !auto @change="auto && update()" />\n <span style="vertical-align: middle; font-size: 12px;">Auto</span>\n </label>\n <button @click="update()" title="Update"><ok-icon name="play-circle" /></button>\n <button @click="save" title="Save"><ok-icon name="save" /></button>\n <label title="Import">\n <button @click="$el.nextElementSibling.click()">\n <ok-icon name="folder-open" size="16" color="currentColor" />\n </button>\n <input type="file" accept=".json" @change="load" @click:allow="$el.value = null" style="display:none" />\n </label>\n <button @click="reset" title="Reset"><ok-icon name="rotate-ccw" /></button>\n <button @click="toggleWindow" :title="window ? \'Close Window\' : \'Pop Window\'">\n <ok-icon :name="window ? \'x\' : \'external-link\'" />\n </button>\n </div>\n </div>\n\n <ok-monaco\n :language="selectedTab.language"\n :value="getContent(selectedTab)"\n :options="$props.monaco"\n @editor-change="updateContent(selectedTab, $event.detail)"\n ></ok-monaco>\n\n <if :="compileError">\n <div class="error">⚠ {{ compileErrorText }}</div>\n </if>\n </div>\n \n <ok-resizer direction="horizontal" />\n <div :ref="previewEl = $el" class="preview"></div>\n</div>\n<if :="!$props.noResizeHeight">\n <ok-resizer direction="vertical" />\n</if>';var n={tag:"ok-live-shell",attr:{noResizeHeight:{default:!1,empty:!0},filename:{default:"live-shell.json"},monaco:{default:()=>({minimap:{enabled:!1}})},tabs:{default:()=>[{id:"html",label:"HTML",language:"html",error:null,default:""},{id:"context",label:"Context",language:"javascript",error:null,default:"{}"}]},render:{default:()=>async(e,t,n)=>{const o=document.createElement("div");return o.innerHTML="ok-live-shell component loaded. Please provide a render function to display content.",o},description:"Function that receives the sandbox target, should return html to render"}},context(e){let t=null,n=null,o=null;return{previewEl:null,auto:!0,compileError:null,get compileErrorText(){if(!this.compileError)return"";let e=this.compileError;for(;e.cause?.scope;)e=e.cause;return e.message+(e.cause?` because ${e.cause.message}`:"")},get tabs(){return e.$attr.tabs||[]},selectedTab:e.$attr.tabs[0]||null,content:new Map,getContent(e){const t=this.content.get(e.id);return void 0!==t?t:e.default||""},async updateContent(t,n){const o=n??"";this.content.set(t.id,o),this.auto&&await this.update(),e.$dispatch("update-content",{tab:t,content:n})},save(){const t={};for(let e of this.tabs)t[e.id]=this.getContent(e);const n=new Blob([JSON.stringify(t,null,2)],{type:"application/json"}),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=e.$attr.filename,a.click(),URL.revokeObjectURL(o)},async load(e){const t=e.target.files?.[0];if(!t)return;const n=new FileReader;return new Promise((e,o)=>{n.onload=async()=>{try{const t=JSON.parse(n.result);for(let e of this.tabs)void 0===t[e.id]?this.content.delete(e.id):this.content.set(e.id,t[e.id]);await this.update(),e()}catch(t){this.compileError=t,e()}},n.readAsText(t)})},async update(){try{this.compileError=null;const t=await e.$attr.render(o,this.content,this.tabs);for(let e of[...o.dom.range(n)]){const t=e.$scope;t&&t.$destroy&&t.$destroy()}n.innerHTML="",o.dom.append(n,t)}catch(e){this.compileError=e}},async reset(){for(let e of this.tabs)this.content.set(e.id,e.default||"");await this.update()},async init(){t||(t=this.previewEl.attachShadow({mode:"open"}),n=document.createElement("body"),n.style.margin="0",n.style.padding="0",n.style.overflow="auto",n.style.position="relative",n.style.height="100%",t.append(n),o=e.$ok.OK({env:"sandbox",head:t,body:n}),await this.reset())},window:!1,toggleWindow(t=null){const n={tabs:[],render:e.$attr.render.toString()};for(let e of this.tabs)n.tabs.push({id:e.id,label:e.label,language:e.language,default:this.getContent(e)});e.$ok.shared.popout.pop('<ok-live-shell style="padding:0;height: 100vh;" :tabs :render="(new Function(`return (${render})`))()"></ok-live-shell>',{context:n})}}},mounted(){e||this.init()},template:t,style:'[tag]{flex-grow:1;padding:8px 8px 2px;font-family:"Segoe UI","Inter",sans-serif;background:#2a2a2e;color:#ddd;border-radius:8px;box-shadow:0 2px 10px #0005}[tag] .main{display:flex;flex-grow:1;align-items:stretch;min-height:200px}[tag],[tag] .editors{display:flex;flex-direction:column}[tag] .editors{overflow:hidden;gap:8px}[tag] .header{display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap}[tag] .tabs{display:flex;gap:0;border-bottom:1px solid #444}[tag] .editor-controls button,[tag] .tab-button{background:0 0;border:0;color:#aaa;cursor:pointer}[tag] .tab-button{border-bottom:2px solid transparent;padding:6px 12px;font-size:13px;transition:all .2s}[tag] .tab-button.active{color:#fff;border-bottom-color:#66f;font-weight:500}[tag] .editor-controls{margin-inline-start:auto;display:flex;align-items:center;gap:8px}[tag] .editor-controls button{font-size:16px;padding:4px}[tag] .editor-controls button:hover{color:#fff}[tag] .editor-controls input[type=checkbox]{margin-right:4px}[tag] .preview,[tag] ok-monaco{border:1px solid #444;border-radius:4px}[tag] ok-monaco{overflow:hidden;height:200px}[tag] .preview{flex:1;background:#111;padding:10px;overflow:auto}[tag] .main--ssg{min-height:240px}[tag] .preview--ssg{display:flex;align-items:center;justify-content:center}[tag] .ssg-placeholder{max-width:28rem;text-align:center;padding:1.5rem;border:1px solid #334;border-radius:12px;background:rgba(255,255,255,.03)}[tag] .ssg-placeholder__title{color:#fff;font-size:1rem;font-weight:600;margin-bottom:.5rem}[tag] .ssg-placeholder__text{color:#aaa;line-height:1.5}[tag] .error{color:#f66;background:#330;border:1px solid #600;padding:6px 8px;margin-top:6px;border-radius:4px;font-size:13px}'};export{n as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"./ok-dropdown.ok.js";var o={tag:"ok-select",dependencies:[e],attr:{value:{default:null},options:{default:[]},optionText:{default:null},optionValue:{default:null},placeholder:{default:""},noSearch:{default:!1,empty:!0},placement:{default:"auto"}},context(e){let o=null,t=null,r=null;const l=o=>{if(null==o)return"";const t=e.$attr.optionText;return String("function"==typeof t?t(o):"string"==typeof t?o?.[t]??o:o)},n=o=>{if(null==o)return null;const t=e.$attr.optionValue;return"function"==typeof t?t(o):"string"==typeof t?o?.[t]??o:o},s=(e,o)=>{const t=e.filteredOptions;if(!t.length)return;const r=t.findIndex(o=>o===e.hover);e.hover=1===o?t[(r+1)%t.length]:t[(t.length+r-1)%t.length]};return{isOpen:!1,search:"",hover:null,get displayValue(){const o=e.$attr.value;if(null==o)return"";const t=(e.$attr.options??[]).find(e=>n(e)===o);return void 0!==t?l(t):""},get filteredOptions(){const o=e.$attr.options??[],t=this.search?.toLowerCase();return t?o.filter(e=>l(e).toLowerCase().includes(t)):o},getLabel:l,getValue:n,isSelected:o=>n(o)===e.$attr.value,open(){o?.toggle(!0)},close(){o?.toggle(!1)},toggle(e){(void 0!==e?e:!this.isOpen)?this.open():this.close()},onToggle(o){const l=!!o.detail?.open;if(this.isOpen=l,l){const o=this.filteredOptions;this.hover=o.find(e=>this.isSelected(e))??o[0]??null,this.search="",e.$attr.noSearch||e.$ok.nextFrame(()=>{(r??e.$el.querySelector(".ok-select__search"))?.focus()})}else this.search="",t?.focus();e.$dispatch("toggle",o.detail)},select(o){e.$dispatch("change",n(o)),this.close()},onFaceKeydown(e){if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),!this.isOpen)return void this.open();s(this,"ArrowDown"===e.key?1:-1)}else if("Enter"===e.key||" "===e.key){if(e.preventDefault(),!this.isOpen)return void this.open();null!==this.hover&&this.select(this.hover)}else"Escape"===e.key&&(e.preventDefault(),this.close())},onSearchKeydown(e){"ArrowDown"===e.key||"ArrowUp"===e.key?(e.preventDefault(),s(this,"ArrowDown"===e.key?1:-1)):"Enter"===e.key?(e.preventDefault(),null!==this.hover&&this.select(this.hover)):"Escape"===e.key&&(e.preventDefault(),this.close())},setDropdownEl(e){o=e},setFaceEl(e){t=e},setSearchEl(e){r=e}}},mount(e){e.$el.toggle=o=>e.$context.toggle(o),e.$el.open=()=>e.$context.open(),e.$el.close=()=>e.$context.close()},template:'<ok-dropdown no-keyboard no-caret :placement="$props.placement" @mount="setDropdownEl($el)" @toggle="onToggle($event)"><template name="trigger"><div class="ok-select__face" @mount="setFaceEl($el)" role="combobox" tabindex="0" :aria-expanded="isOpen" aria-haspopup="listbox" @keydown:allow="onFaceKeydown($event)"><span class="ok-select__display" :class="{ \'ok-select__display--empty\': !displayValue }">{{ displayValue || $props.placeholder }} </span><span class="ok-select__caret" aria-hidden="true"><svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L5 5L9 1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span></div></template><div class="ok-select__panel"><if :="!$props.noSearch"><div class="ok-select__search-wrap"><input class="ok-select__search" @mount="setSearchEl($el)" @unmounted="setSearchEl(null)" type="text" !value="search" @keydown:allow="onSearchKeydown($event)" autocomplete="off" placeholder="Search…"></div></if><div class="ok-select__options"><each :of="filteredOptions" let:option><div class="ok-select__option" role="option" :class="{ \'ok-select__option--selected\': isSelected(option),\n \'ok-select__option--hover\': hover === option }" @click="select(option)" @mouseenter="hover = option"><slot name="option" :var:option="option">{{ getLabel(option) }}</slot></div></each><if :="!filteredOptions.length"><div class="ok-select__empty"><slot name="empty">No results</slot></div></if></div></div></ok-dropdown>',style:"[tag]{display:inline-block;--ok-dropdown-trigger-display:flex;--ok-dropdown-trigger-padding:0;--ok-dropdown-trigger-border:none;--ok-dropdown-trigger-bg:transparent;--ok-dropdown-trigger-hover-bg:transparent;--ok-dropdown-trigger-active-bg:transparent;--ok-dropdown-trigger-gap:0}.ok-select__face{display:inline-flex;align-items:center;gap:var(--ok-select-trigger-gap, 0.35em);cursor:pointer;user-select:none;width:100%;min-width:var(--ok-select-width, 160px);justify-content:space-between;padding:var(--ok-select-padding, 0.35rem 0.6rem);border-radius:var(--ok-select-radius, var(--ok_radius, 4px));border:var(--ok-select-border, 1px solid color-mix(in srgb, currentColor 20%, transparent));background:var(--ok-select-bg, var(--ok_bg, #fff));color:inherit;font-size:inherit;font-family:inherit;outline-offset:0;transition:border-color .15s;box-sizing:border-box}.ok-select__face:hover{border-color:var(--ok-select-hover-border, color-mix(in srgb, currentColor 35%, transparent))}.ok-select__face:focus,[tag] .ok-dropdown--open .ok-select__face{border-color:var(--ok-select-focus-border, var(--ok_focus-ring, currentColor));outline:1px solid var(--ok-select-focus-border, var(--ok_focus_ring, currentColor))}.ok-select__display{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:start}.ok-select__display--empty{color:var(--ok-select-placeholder-color, color-mix(in srgb, currentColor 40%, transparent))}.ok-select__caret{display:inline-flex;align-items:center;flex-shrink:0;line-height:0;color:color-mix(in srgb,currentColor 55%,transparent);transition:transform .2s ease}[tag] .ok-dropdown--open .ok-select__caret{transform:rotate(180deg)}.ok-select__panel{min-width:var(--ok-select-width, 160px)}.ok-select__search-wrap{padding:.35rem .4rem .3rem;border-bottom:1px solid color-mix(in srgb,currentColor 8%,transparent)}.ok-select__search{display:block;width:100%;box-sizing:border-box;border:1px solid color-mix(in srgb,currentColor 15%,transparent);border-radius:calc(var(--ok-select-radius, var(--ok_radius, 4px)) - 1px);padding:.25rem .45rem;font-size:inherit;font-family:inherit;background:var(--ok-select-search-bg, color-mix(in srgb, currentColor 4%, transparent));color:inherit;outline:0}.ok-select__search:focus{border-color:var(--ok-select-focus-border, var(--ok_focus_ring, currentColor));outline:1px solid var(--ok-select-focus-border, var(--ok_focus_ring, currentColor));outline-offset:0}.ok-select__options{max-height:var(--ok-select-panel-height, 220px);overflow-y:auto;padding:.2rem 0}.ok-select__option{padding:.4rem .75rem;cursor:pointer;font-size:inherit;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;transition:background .1s}.ok-select__option--hover,.ok-select__option--selected.ok-select__option--hover{background:var(--ok-select-option-hover-bg, color-mix(in srgb, currentColor 8%, transparent))}.ok-select__option--selected{background:var(--ok-select-option-selected-bg, color-mix(in srgb, currentColor 10%, transparent));font-weight:500}.ok-select__empty{padding:.5rem .75rem;color:color-mix(in srgb,currentColor 45%,transparent);font-style:italic;font-size:.875em}[tag].block{display:block}[tag].block .ok-select__face,[tag].block .ok-select__panel{width:100%;min-width:0}",plugins:{theme:{expose:{"--ok-select-width":{default:"160px",type:"length",description:"Minimum width of the select control",category:"ok-select"},"--ok-select-bg":{default:"var(--ok_bg, #fff)",type:"color",description:"Select trigger background",category:"ok-select"},"--ok-select-panel-height":{default:"220px",type:"length",description:"Maximum height of the scrollable options list",category:"ok-select"},"--ok-select-option-selected-bg":{default:"color-mix(in srgb, currentColor 10%, transparent)",type:"color",description:"Background of the selected option",category:"ok-select"}}}}};export{o as default};
|
|
1
|
+
import e from"./ok-dropdown.ok.js";var o={tag:"ok-select",dependencies:[e],attr:{value:{default:null},options:{default:()=>[]},optionText:{default:null},optionValue:{default:null},placeholder:{default:""},noSearch:{default:!1,empty:!0},placement:{default:"auto"}},context(e){let o=null,t=null,r=null;const l=o=>{if(null==o)return"";const t=e.$attr.optionText;return String("function"==typeof t?t(o):"string"==typeof t?o?.[t]??o:o)},n=o=>{if(null==o)return null;const t=e.$attr.optionValue;return"function"==typeof t?t(o):"string"==typeof t?o?.[t]??o:o},s=(e,o)=>{const t=e.filteredOptions;if(!t.length)return;const r=t.findIndex(o=>o===e.hover);e.hover=1===o?t[(r+1)%t.length]:t[(t.length+r-1)%t.length]};return{isOpen:!1,search:"",hover:null,get displayValue(){const o=e.$attr.value;if(null==o)return"";const t=(e.$attr.options??[]).find(e=>n(e)===o);return void 0!==t?l(t):""},get filteredOptions(){const o=e.$attr.options??[],t=this.search?.toLowerCase();return t?o.filter(e=>l(e).toLowerCase().includes(t)):o},getLabel:l,getValue:n,isSelected:o=>n(o)===e.$attr.value,open(){o?.toggle(!0)},close(){o?.toggle(!1)},toggle(e){(void 0!==e?e:!this.isOpen)?this.open():this.close()},onToggle(o){const l=!!o.detail?.open;if(this.isOpen=l,l){const o=this.filteredOptions;this.hover=o.find(e=>this.isSelected(e))??o[0]??null,this.search="",e.$attr.noSearch||e.$ok.nextFrame(()=>{(r??e.$el.querySelector(".ok-select__search"))?.focus()})}else this.search="",t?.focus();e.$dispatch("toggle",o.detail)},select(o){e.$dispatch("change",n(o)),this.close()},onFaceKeydown(e){if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),!this.isOpen)return void this.open();s(this,"ArrowDown"===e.key?1:-1)}else if("Enter"===e.key||" "===e.key){if(e.preventDefault(),!this.isOpen)return void this.open();null!==this.hover&&this.select(this.hover)}else"Escape"===e.key&&(e.preventDefault(),this.close())},onSearchKeydown(e){"ArrowDown"===e.key||"ArrowUp"===e.key?(e.preventDefault(),s(this,"ArrowDown"===e.key?1:-1)):"Enter"===e.key?(e.preventDefault(),null!==this.hover&&this.select(this.hover)):"Escape"===e.key&&(e.preventDefault(),this.close())},setDropdownEl(e){o=e},setFaceEl(e){t=e},setSearchEl(e){r=e}}},mount(e){e.$el.toggle=o=>e.$context.toggle(o),e.$el.open=()=>e.$context.open(),e.$el.close=()=>e.$context.close()},template:'<ok-dropdown no-keyboard no-caret :placement="$props.placement" @mount="setDropdownEl($el)" @toggle="onToggle($event)"><template name="trigger"><div class="ok-select__face" @mount="setFaceEl($el)" role="combobox" tabindex="0" :aria-expanded="isOpen" aria-haspopup="listbox" @keydown:allow="onFaceKeydown($event)"><span class="ok-select__display" :class="{ \'ok-select__display--empty\': !displayValue }">{{ displayValue || $props.placeholder }} </span><span class="ok-select__caret" aria-hidden="true"><svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L5 5L9 1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span></div></template><div class="ok-select__panel"><if :="!$props.noSearch"><div class="ok-select__search-wrap"><input class="ok-select__search" @mount="setSearchEl($el)" @unmounted="setSearchEl(null)" type="text" !value="search" @keydown:allow="onSearchKeydown($event)" autocomplete="off" placeholder="Search…"></div></if><div class="ok-select__options"><each :of="filteredOptions" let:option><div class="ok-select__option" role="option" :class="{ \'ok-select__option--selected\': isSelected(option),\n \'ok-select__option--hover\': hover === option }" @click="select(option)" @mouseenter="hover = option"><slot name="option" :var:option="option">{{ getLabel(option) }}</slot></div></each><if :="!filteredOptions.length"><div class="ok-select__empty"><slot name="empty">No results</slot></div></if></div></div></ok-dropdown>',style:"[tag]{display:inline-block;--ok-dropdown-trigger-display:flex;--ok-dropdown-trigger-padding:0;--ok-dropdown-trigger-border:none;--ok-dropdown-trigger-bg:transparent;--ok-dropdown-trigger-hover-bg:transparent;--ok-dropdown-trigger-active-bg:transparent;--ok-dropdown-trigger-gap:0}.ok-select__face{display:inline-flex;align-items:center;gap:var(--ok-select-trigger-gap, 0.35em);cursor:pointer;user-select:none;width:100%;min-width:var(--ok-select-width, 160px);justify-content:space-between;padding:var(--ok-select-padding, 0.35rem 0.6rem);border-radius:var(--ok-select-radius, var(--ok_radius, 4px));border:var(--ok-select-border, 1px solid color-mix(in srgb, currentColor 20%, transparent));background:var(--ok-select-bg, var(--ok_bg, #fff));color:inherit;font-size:inherit;font-family:inherit;outline-offset:0;transition:border-color .15s;box-sizing:border-box}.ok-select__face:hover{border-color:var(--ok-select-hover-border, color-mix(in srgb, currentColor 35%, transparent))}.ok-select__face:focus,[tag] .ok-dropdown--open .ok-select__face{border-color:var(--ok-select-focus-border, var(--ok_focus-ring, currentColor));outline:1px solid var(--ok-select-focus-border, var(--ok_focus_ring, currentColor))}.ok-select__display{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;text-align:start}.ok-select__display--empty{color:var(--ok-select-placeholder-color, color-mix(in srgb, currentColor 40%, transparent))}.ok-select__caret{display:inline-flex;align-items:center;flex-shrink:0;line-height:0;color:color-mix(in srgb,currentColor 55%,transparent);transition:transform .2s ease}[tag] .ok-dropdown--open .ok-select__caret{transform:rotate(180deg)}.ok-select__panel{min-width:var(--ok-select-width, 160px)}.ok-select__search-wrap{padding:.35rem .4rem .3rem;border-bottom:1px solid color-mix(in srgb,currentColor 8%,transparent)}.ok-select__search{display:block;width:100%;box-sizing:border-box;border:1px solid color-mix(in srgb,currentColor 15%,transparent);border-radius:calc(var(--ok-select-radius, var(--ok_radius, 4px)) - 1px);padding:.25rem .45rem;font-size:inherit;font-family:inherit;background:var(--ok-select-search-bg, color-mix(in srgb, currentColor 4%, transparent));color:inherit;outline:0}.ok-select__search:focus{border-color:var(--ok-select-focus-border, var(--ok_focus_ring, currentColor));outline:1px solid var(--ok-select-focus-border, var(--ok_focus_ring, currentColor));outline-offset:0}.ok-select__options{max-height:var(--ok-select-panel-height, 220px);overflow-y:auto;padding:.2rem 0}.ok-select__option{padding:.4rem .75rem;cursor:pointer;font-size:inherit;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;transition:background .1s}.ok-select__option--hover,.ok-select__option--selected.ok-select__option--hover{background:var(--ok-select-option-hover-bg, color-mix(in srgb, currentColor 8%, transparent))}.ok-select__option--selected{background:var(--ok-select-option-selected-bg, color-mix(in srgb, currentColor 10%, transparent));font-weight:500}.ok-select__empty{padding:.5rem .75rem;color:color-mix(in srgb,currentColor 45%,transparent);font-style:italic;font-size:.875em}[tag].block{display:block}[tag].block .ok-select__face,[tag].block .ok-select__panel{width:100%;min-width:0}",plugins:{theme:{expose:{"--ok-select-width":{default:"160px",type:"length",description:"Minimum width of the select control",category:"ok-select"},"--ok-select-bg":{default:"var(--ok_bg, #fff)",type:"color",description:"Select trigger background",category:"ok-select"},"--ok-select-panel-height":{default:"220px",type:"length",description:"Maximum height of the scrollable options list",category:"ok-select"},"--ok-select-option-selected-bg":{default:"color-mix(in srgb, currentColor 10%, transparent)",type:"color",description:"Background of the selected option",category:"ok-select"}}}}};export{o as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){return{prop:e.prop??null,value:e.value??null,title:e.title??null,width:e.width??null,lock:!!e.lock,noResize:e.noResize??!1,headerTemplate:e.headerTemplate??c(),cellTemplate:e.cellTemplate??s(),source:e.source??"user",computedWidth:null,setWidth:null,_n:e._n??null,_hidden:e._hidden??null,_title:e._title??null}}function t(t,l){const n=[];for(const r of t)if(r?.auto){const t=o(l.$attr.data,{...r,...r.auto});for(const l of t)if("more"===l.source){const t=e(l);t._configEntry=r,n.push(t)}else n.push(e({...l,...r}))}else n.push(e(r));const r=n[n.length-1];return r&&"more"!==r.source&&(r.width="1fr"),n}function l(e){const t=document.createElement("template");return t.innerHTML=e,t}function o(e,{width:t="min-content",headerTemplate:o,cellTemplate:n,filter:r,map:a,sort:c,max:s=null,showMoreContent:i=null,showMoreTitle:d=null,_expanded:u=!1}){const m=new Set;for(const t of e)if(t&&"object"==typeof t)for(const e of Object.keys(t))m.add(e);let h=[];for(const e of m)r&&!r(e)||h.push({prop:e,width:t,computedWidth:null,noResize:!1,headerTemplate:o,cellTemplate:n,source:"auto"});if(a&&(h=h.map(e=>({...e,...a(e)}))),c&&(h=h.sort(c)),s&&!u&&h.length>s){const e=h.slice(s),t=e.length,o="function"==typeof i?String(i(t,e)):i??`+${t}`,n="function"==typeof d?String(d(t,e)):d;h=h.slice(0,s),h.push({prop:null,value:null,title:null,width:"min-content",computedWidth:null,noResize:!0,headerTemplate:l(o),cellTemplate:null,source:"more",_n:t,_hidden:e,_title:n})}return h}function n(e){if(!e)return null;const t=document.createElement("template");t.content.append(...e.childNodes);for(const l of e.attributes)l.name.startsWith("let:")&&t.setAttribute(l.name,l.value);return t}function r(e,t){const l=e.getAttribute("width")||"min-content",o=e.hasAttribute("max")?parseInt(e.getAttribute("max"),10):null,r=Array.from(e.children).find(e=>"HEADER"===e.tagName),a=Array.from(e.children).find(e=>"CELL"===e.tagName);let c=null;e.getAttribute(":filter")&&(c=t.$fn(e.getAttribute(":filter"))(t));let s=null;e.getAttribute(":sort")&&(s=t.$fn(e.getAttribute(":sort"))(t));let i=null;e.getAttribute(":map")&&(i=t.$fn(e.getAttribute(":map"))(t));let d=e.getAttribute("show-more-content");e.getAttribute(":show-more-content")&&(d=t.$fn(e.getAttribute(":show-more-content"))(t));let u=e.getAttribute("show-more-title");return e.getAttribute(":show-more-title")&&(u=t.$fn(e.getAttribute(":show-more-title"))(t)),{auto:{filter:c,sort:s,map:i},cellTemplate:n(a),headerTemplate:n(r),width:l,max:o,showMoreContent:d,showMoreTitle:u,columnEl:e}}function a(e,t){const l=e.getAttribute("prop")||null,o=Array.from(e.children).find(e=>"HEADER"===e.tagName),r=Array.from(e.children).find(e=>"CELL"===e.tagName);return{width:e.getAttribute("width")||"1fr",noResize:e.hasAttribute("no-resize"),prop:l,headerTemplate:n(o),cellTemplate:n(r),columnEl:e}}function c(e){const t=document.createElement("template");return t.setAttribute("let:column","column"),t.innerHTML="{{ column.title || column.prop || '' }}",t}function s(e){const t=document.createElement("template");return t.setAttribute("let:row","row"),t.setAttribute("let:column","column"),t.setAttribute("let:value","value"),t.innerHTML="{{ value || '' }}",t}var i={tag:"ok-table",attr:{data:{default:[]},columns:{default:null},expand:{default:"multi"},select:{default:"none"},selected:{default:null},expanded:{default:null}},plugins:{theme:{expose:{"--ok-table_bg":{type:"color",description:"Table background",category:"Colors"},"--ok-table_header-bg":{type:"color",description:"Header background",category:"Colors"},"--ok-table_color":{type:"color",description:"Text color",category:"Colors"},"--ok-table_hover-bg":{default:"color-mix(in srgb, var(--ok_color-accent-fg) 20%, transparent)",type:"color",description:"Row hover background",category:"Colors"},"--ok-table_selected-bg":{default:"color-mix(in srgb, var(--ok_color-accent-fg, #007bff) 25%, transparent)",type:"color",description:"Selected row background",category:"Colors"},"--ok-table_border":{type:"border",description:"Cell border",category:"Layout"},"--ok-table_padding":{type:"length",description:"Cell padding",category:"Layout"},"--ok-table_font":{type:"string",description:"Table font",category:"Typography"}}}},context(e){const l=e.$cache.cmp.templates.default;var n;e.$attr.columns&&(n=l,Array.from(n?.content?.children||[]).find(e=>"COLUMNS"===e.tagName||"AUTO"===e.tagName||"COLUMN"===e.tagName));const c=e.$attr.columns||function(e,t){const l=Array.from(e?.content?.children||[]).find(e=>"COLUMNS"===e.tagName),n=[];if(!l)return o(t.$attr.data,{});for(const e of l.children)"AUTO"===e.tagName?n.push(r(e,t)):"COLUMN"===e.tagName&&n.push(a(e));return n}(l,e);c.length||c.push({auto:!0});const s=t(c,e),i=Array.from(l?.content.children??[]).find(e=>"EXPANDED"===e.tagName);if(i){const t=document.createElement("template");t.content.append(...i.childNodes);for(const e of i.attributes)e.name.startsWith("let:")&&t.setAttribute(e.name,e.value);e.$cache.cmp.templates.expanded=t}return{get expand(){return e.$attr.expand||"multi"},get select(){return e.$attr.select||"none"},get canSelect(){return"none"!==this.select},_expandedRows:new Set,_selectedRows:new Set,get expandedRows(){return e.$attr.expanded??this._expandedRows},get selectedRows(){return e.$attr.selected??this._selectedRows},columnsConfig:c,columns:s,valueOf:(e,t)=>t.value?t.value(e):t.prop?e[t.prop]:void 0,showMore(l){l._configEntry._expanded=!0,this.columns=t(this.columnsConfig,e)},get columnStyle(){if(!this.columns.length)return"1fr";const e=this.columns.map(e=>`minmax(0, ${e.setWidth||e.computedWidth||e.width||"1fr"})`),t=e.length-1;return e[t]=`minmax(${this.columns[t].setWidth||0}, auto)`,e.join(" ")},get rows(){return e.$attr.data},resizeColumn:null,expandedRow:null,hoverRow:null,get canExpand(){return e.$cache.cmp.templates.expanded},wasExpanded(e){return this.expandedRows.has(e)},toggleExpand(t,l=null){if(!this.canExpand)return;const o=this.expandedRows.has(t),n=null===l?!o:!!l;"single"===this.expand&&this.expandedRows.clear(),n?this.expandedRows.add(t):this.expandedRows.delete(t),e.$dispatch("expand-change",{expanded:this.expandedRows,row:t,action:n?"expand":"collapse"})},isSelected(e){return this.selectedRows.has(e)},toggleSelect(t,l=null){if(!this.canSelect)return;const o=this.selectedRows.has(t),n=null===l?!o:!!l;"single"===this.select&&this.selectedRows.clear(),n?this.selectedRows.add(t):this.selectedRows.delete(t),e.$dispatch("select-change",{selected:this.selectedRows,row:t,action:n?"select":"deselect"})},handleRowClick(e){this.toggleExpand(e),this.canSelect&&this.toggleSelect(e)},resize(t,l){l.preventDefault(),this.resizeColumn=t,e.$el.getBoundingClientRect();const o=e.$el.querySelectorAll(".ok-table__cell--header")[this.columns.indexOf(t)],n=l.clientX,r=o.offsetWidth;if(!t.computedWidth){const t=e.$el.querySelectorAll(".ok-table__cell--header");this.columns.forEach((e,l)=>{if(!e.computedWidth){const o=t[l];o&&(e.computedWidth=`${o.offsetWidth}px`)}})}const a=e=>{const l=e.clientX-n,o=r+l;t.setWidth=`${o}px`},c=()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",c),this.resizeColumn=null};document.addEventListener("mousemove",a),document.addEventListener("mouseup",c)}}},mounted(e){e.$watch(()=>e.$attr.data?.length,()=>{this.columns=t(this.columnsConfig,e)}),e.$el.select=(e,t)=>this.toggleSelect(e,t??!0),e.$el.deselect=e=>this.toggleSelect(e,!1),e.$el.toggleSelect=(e,t)=>this.toggleSelect(e,t??null),e.$el.clearSelection=()=>this.selectedRows.clear(),e.$el.getSelected=()=>this.selectedRows,e.$el.expand=(e,t)=>this.toggleExpand(e,t??!0),e.$el.collapse=e=>this.toggleExpand(e,!1),e.$el.toggleExpand=(e,t)=>this.toggleExpand(e,t??null),e.$el.clearExpanded=()=>this.expandedRows.clear(),e.$el.getExpanded=()=>this.expandedRows},mount(e){e.$cache.start=performance.now()},init(e){},template:'<div class="ok-table__container" :style="{ gridTemplateColumns: columnStyle }"><each :of="columns" let:item="column" let:index="columnIndex"><div class="ok-table__column ok-table__column--header"><if :="column.source === \'more\'"><div class="ok-table__cell ok-table__cell--header ok-table__cell--show-more" :title="column._title" @click="showMore(column)"><div class="ok-table__cell__inner"><slot :template="column.headerTemplate" :var:column="column"/></div></div><else><div class="ok-table__cell ok-table__cell--header"><div class="ok-table__cell__inner"><slot :template="column.headerTemplate" :var:column="column"/></div></div><if :="!column.noResize"><div class="ok-table__resizer ok-table__resizer--header" :class="{\'ok-table__resizer--resizing\': resizeColumn === column}" @mousedown="resize(column, $event)"/></if></else></if></div></each><each :of="rows" let:item="row" let:index="rowIndex"><each :of="columns" let:item="column" let:index="columnIndex"><if :="column.source === \'more\'"><div class="ok-table__cell ok-table__cell--data ok-table__cell--show-more"/><else><div class="ok-table__cell ok-table__cell--data" :class="{\n \'ok-table__cell--hover-row\': hoverRow === row,\n \'ok-table__cell--expanded\': expandedRows.has(row),\n \'ok-table__cell--selected\': selectedRows.has(row),\n \'ok-table__cell--start\': columnIndex === 0,\n \'ok-table__cell--end\': columnIndex === columns.length - 1\n }" @click="handleRowClick(row)" @mouseenter="hoverRow = row" @mouseleave="hoverRow = hoverRow === row ? null : hoverRow"><div class="ok-table__cell__inner"><slot :template="column.cellTemplate" :var:row="row" :var:column="column" :var:index="rowIndex" :var:value="valueOf(row, column)"/></div><if :="!column.noResize"><div class="ok-table__resizer ok-table__resizer--cell" :class="{ \'ok-table__resizer--resizing\': resizeColumn === column}" @mousedown="resize(column, $event)"/></if></div></else></if></each><if :="canExpand && wasExpanded(row)"><div class="ok-table__expanded_row"><slot name="expanded" :var:row="row" :var:index="rowIndex"/></div></if></each></div>',style:"[tag]{display:block;overflow:auto;max-width:100%}.ok-table__container{display:grid;grid-template-rows:auto;grid-auto-rows:auto;font-family:var(--ok-table-font);width:max-content;min-width:-webkit-fill-available}.ok-table__column--header{position:sticky;top:0;z-index:1}.ok-table__cell{color:var(--ok-table_color);border-bottom:var(--ok-table_border);white-space:nowrap;align-items:center;position:relative;background:var(--ok-table_bg);overflow:hidden;height:100%;box-sizing:border-box}.ok-table__cell__inner{padding:var(--ok-table_padding, 0.1rem 1rem);text-overflow:ellipsis;overflow:hidden}.ok-table__cell--header{font-weight:700;background:var(--ok-table_header-bg, var(--ok_bg-accent, rgba(0, 123, 255, 0.05)));border-bottom:var(--ok-table_border)}.ok-table__cell--hover-row{background:var(--ok-table_hover-bg, rgba(0, 123, 255, 0.1))}.ok-table__cell--selected{background:var(--ok-table_selected-bg, color-mix(in srgb, var(--ok_color-accent-fg, #007bff) 25%, transparent))}.ok-table__cell--expanded,.ok-table__cell--header.ok-table__cell--show-more:hover{background:var(--ok-table_hover-bg, rgba(0, 123, 255, 0.1))}.ok-table__cell--start{border-left:var(--ok-table_border)}.ok-table__cell--end{border-right:var(--ok-table_border)}.ok-table__resizer{position:absolute;right:0;top:0;bottom:0;width:6px;cursor:col-resize;z-index:10}.ok-table__resizer--resizing,.ok-table__resizer:hover{background:var(--ok_bg-accent-hover, rgba(0, 123, 255, 0.3))}.ok-table__expanded_row{grid-column:1/-1;contain:inline-size}.ok-table__cell--header.ok-table__cell--show-more{cursor:pointer;user-select:none;opacity:.7}.ok-table__cell--header.ok-table__cell--show-more:hover{opacity:1}.ok-table__cell--data.ok-table__cell--show-more{pointer-events:none}"};export{i as default};
|
|
1
|
+
function e(e){return{prop:e.prop??null,value:e.value??null,title:e.title??null,width:e.width??null,lock:!!e.lock,noResize:e.noResize??!1,headerTemplate:e.headerTemplate??c(),cellTemplate:e.cellTemplate??s(),source:e.source??"user",computedWidth:null,setWidth:null,_n:e._n??null,_hidden:e._hidden??null,_title:e._title??null}}function t(t,l){const n=[];for(const r of t)if(r?.auto){const t=o(l.$attr.data,{...r,...r.auto});for(const l of t)if("more"===l.source){const t=e(l);t._configEntry=r,n.push(t)}else n.push(e({...l,...r}))}else n.push(e(r));const r=n[n.length-1];return r&&"more"!==r.source&&(r.width="1fr"),n}function l(e){const t=document.createElement("template");return t.innerHTML=e,t}function o(e,{width:t="min-content",headerTemplate:o,cellTemplate:n,filter:r,map:a,sort:c,max:s=null,showMoreContent:i=null,showMoreTitle:d=null,_expanded:u=!1}){const m=new Set;for(const t of e)if(t&&"object"==typeof t)for(const e of Object.keys(t))m.add(e);let h=[];for(const e of m)r&&!r(e)||h.push({prop:e,width:t,computedWidth:null,noResize:!1,headerTemplate:o,cellTemplate:n,source:"auto"});if(a&&(h=h.map(e=>({...e,...a(e)}))),c&&(h=h.sort(c)),s&&!u&&h.length>s){const e=h.slice(s),t=e.length,o="function"==typeof i?String(i(t,e)):i??`+${t}`,n="function"==typeof d?String(d(t,e)):d;h=h.slice(0,s),h.push({prop:null,value:null,title:null,width:"min-content",computedWidth:null,noResize:!0,headerTemplate:l(o),cellTemplate:null,source:"more",_n:t,_hidden:e,_title:n})}return h}function n(e){if(!e)return null;const t=document.createElement("template");t.content.append(...e.childNodes);for(const l of e.attributes)l.name.startsWith("let:")&&t.setAttribute(l.name,l.value);return t}function r(e,t){const l=e.getAttribute("width")||"min-content",o=e.hasAttribute("max")?parseInt(e.getAttribute("max"),10):null,r=Array.from(e.children).find(e=>"HEADER"===e.tagName),a=Array.from(e.children).find(e=>"CELL"===e.tagName);let c=null;e.getAttribute(":filter")&&(c=t.$fn(e.getAttribute(":filter"))(t));let s=null;e.getAttribute(":sort")&&(s=t.$fn(e.getAttribute(":sort"))(t));let i=null;e.getAttribute(":map")&&(i=t.$fn(e.getAttribute(":map"))(t));let d=e.getAttribute("show-more-content");e.getAttribute(":show-more-content")&&(d=t.$fn(e.getAttribute(":show-more-content"))(t));let u=e.getAttribute("show-more-title");return e.getAttribute(":show-more-title")&&(u=t.$fn(e.getAttribute(":show-more-title"))(t)),{auto:{filter:c,sort:s,map:i},cellTemplate:n(a),headerTemplate:n(r),width:l,max:o,showMoreContent:d,showMoreTitle:u,columnEl:e}}function a(e,t){const l=e.getAttribute("prop")||null,o=Array.from(e.children).find(e=>"HEADER"===e.tagName),r=Array.from(e.children).find(e=>"CELL"===e.tagName);return{width:e.getAttribute("width")||"1fr",noResize:e.hasAttribute("no-resize"),prop:l,headerTemplate:n(o),cellTemplate:n(r),columnEl:e}}function c(e){const t=document.createElement("template");return t.setAttribute("let:column","column"),t.innerHTML="{{ column.title || column.prop || '' }}",t}function s(e){const t=document.createElement("template");return t.setAttribute("let:row","row"),t.setAttribute("let:column","column"),t.setAttribute("let:value","value"),t.innerHTML="{{ value || '' }}",t}var i={tag:"ok-table",attr:{data:{default:()=>[]},columns:{default:null},expand:{default:"multi"},select:{default:"none"},selected:{default:null},expanded:{default:null}},plugins:{theme:{expose:{"--ok-table_bg":{type:"color",description:"Table background",category:"Colors"},"--ok-table_header-bg":{type:"color",description:"Header background",category:"Colors"},"--ok-table_color":{type:"color",description:"Text color",category:"Colors"},"--ok-table_hover-bg":{default:"color-mix(in srgb, var(--ok_color-accent-fg) 20%, transparent)",type:"color",description:"Row hover background",category:"Colors"},"--ok-table_selected-bg":{default:"color-mix(in srgb, var(--ok_color-accent-fg, #007bff) 25%, transparent)",type:"color",description:"Selected row background",category:"Colors"},"--ok-table_border":{type:"border",description:"Cell border",category:"Layout"},"--ok-table_padding":{type:"length",description:"Cell padding",category:"Layout"},"--ok-table_font":{type:"string",description:"Table font",category:"Typography"}}}},context(e){const l=e.$cache.cmp.templates.default;var n;e.$attr.columns&&(n=l,Array.from(n?.content?.children||[]).find(e=>"COLUMNS"===e.tagName||"AUTO"===e.tagName||"COLUMN"===e.tagName));const c=e.$attr.columns||function(e,t){const l=Array.from(e?.content?.children||[]).find(e=>"COLUMNS"===e.tagName),n=[];if(!l)return o(t.$attr.data,{});for(const e of l.children)"AUTO"===e.tagName?n.push(r(e,t)):"COLUMN"===e.tagName&&n.push(a(e));return n}(l,e);c.length||c.push({auto:!0});const s=t(c,e),i=Array.from(l?.content.children??[]).find(e=>"EXPANDED"===e.tagName);if(i){const t=document.createElement("template");t.content.append(...i.childNodes);for(const e of i.attributes)e.name.startsWith("let:")&&t.setAttribute(e.name,e.value);e.$cache.cmp.templates.expanded=t}return{get expand(){return e.$attr.expand||"multi"},get select(){return e.$attr.select||"none"},get canSelect(){return"none"!==this.select},_expandedRows:new Set,_selectedRows:new Set,get expandedRows(){return e.$attr.expanded??this._expandedRows},get selectedRows(){return e.$attr.selected??this._selectedRows},columnsConfig:c,columns:s,valueOf:(e,t)=>t.value?t.value(e):t.prop?e[t.prop]:void 0,showMore(l){l._configEntry._expanded=!0,this.columns=t(this.columnsConfig,e)},get columnStyle(){if(!this.columns.length)return"1fr";const e=this.columns.map(e=>`minmax(0, ${e.setWidth||e.computedWidth||e.width||"1fr"})`),t=e.length-1;return e[t]=`minmax(${this.columns[t].setWidth||0}, auto)`,e.join(" ")},get rows(){return e.$attr.data},resizeColumn:null,expandedRow:null,hoverRow:null,get canExpand(){return e.$cache.cmp.templates.expanded},wasExpanded(e){return this.expandedRows.has(e)},toggleExpand(t,l=null){if(!this.canExpand)return;const o=this.expandedRows.has(t),n=null===l?!o:!!l;"single"===this.expand&&this.expandedRows.clear(),n?this.expandedRows.add(t):this.expandedRows.delete(t),e.$dispatch("expand-change",{expanded:this.expandedRows,row:t,action:n?"expand":"collapse"})},isSelected(e){return this.selectedRows.has(e)},toggleSelect(t,l=null){if(!this.canSelect)return;const o=this.selectedRows.has(t),n=null===l?!o:!!l;"single"===this.select&&this.selectedRows.clear(),n?this.selectedRows.add(t):this.selectedRows.delete(t),e.$dispatch("select-change",{selected:this.selectedRows,row:t,action:n?"select":"deselect"})},handleRowClick(e){this.toggleExpand(e),this.canSelect&&this.toggleSelect(e)},resize(t,l){l.preventDefault(),this.resizeColumn=t,e.$el.getBoundingClientRect();const o=e.$el.querySelectorAll(".ok-table__cell--header")[this.columns.indexOf(t)],n=l.clientX,r=o.offsetWidth;if(!t.computedWidth){const t=e.$el.querySelectorAll(".ok-table__cell--header");this.columns.forEach((e,l)=>{if(!e.computedWidth){const o=t[l];o&&(e.computedWidth=`${o.offsetWidth}px`)}})}const a=e=>{const l=e.clientX-n,o=r+l;t.setWidth=`${o}px`},c=()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",c),this.resizeColumn=null};document.addEventListener("mousemove",a),document.addEventListener("mouseup",c)}}},mounted(e){e.$watch(()=>e.$attr.data?.length,()=>{this.columns=t(this.columnsConfig,e)}),e.$el.select=(e,t)=>this.toggleSelect(e,t??!0),e.$el.deselect=e=>this.toggleSelect(e,!1),e.$el.toggleSelect=(e,t)=>this.toggleSelect(e,t??null),e.$el.clearSelection=()=>this.selectedRows.clear(),e.$el.getSelected=()=>this.selectedRows,e.$el.expand=(e,t)=>this.toggleExpand(e,t??!0),e.$el.collapse=e=>this.toggleExpand(e,!1),e.$el.toggleExpand=(e,t)=>this.toggleExpand(e,t??null),e.$el.clearExpanded=()=>this.expandedRows.clear(),e.$el.getExpanded=()=>this.expandedRows},mount(e){e.$cache.start=performance.now()},init(e){},template:'<div class="ok-table__container" :style="{ gridTemplateColumns: columnStyle }"><each :of="columns" let:item="column" let:index="columnIndex"><div class="ok-table__column ok-table__column--header"><if :="column.source === \'more\'"><div class="ok-table__cell ok-table__cell--header ok-table__cell--show-more" :title="column._title" @click="showMore(column)"><div class="ok-table__cell__inner"><slot :template="column.headerTemplate" :var:column="column"/></div></div><else><div class="ok-table__cell ok-table__cell--header"><div class="ok-table__cell__inner"><slot :template="column.headerTemplate" :var:column="column"/></div></div><if :="!column.noResize"><div class="ok-table__resizer ok-table__resizer--header" :class="{\'ok-table__resizer--resizing\': resizeColumn === column}" @mousedown="resize(column, $event)"/></if></else></if></div></each><each :of="rows" let:item="row" let:index="rowIndex"><each :of="columns" let:item="column" let:index="columnIndex"><if :="column.source === \'more\'"><div class="ok-table__cell ok-table__cell--data ok-table__cell--show-more"/><else><div class="ok-table__cell ok-table__cell--data" :class="{\n \'ok-table__cell--hover-row\': hoverRow === row,\n \'ok-table__cell--expanded\': expandedRows.has(row),\n \'ok-table__cell--selected\': selectedRows.has(row),\n \'ok-table__cell--start\': columnIndex === 0,\n \'ok-table__cell--end\': columnIndex === columns.length - 1\n }" @click="handleRowClick(row)" @mouseenter="hoverRow = row" @mouseleave="hoverRow = hoverRow === row ? null : hoverRow"><div class="ok-table__cell__inner"><slot :template="column.cellTemplate" :var:row="row" :var:column="column" :var:index="rowIndex" :var:value="valueOf(row, column)"/></div><if :="!column.noResize"><div class="ok-table__resizer ok-table__resizer--cell" :class="{ \'ok-table__resizer--resizing\': resizeColumn === column}" @mousedown="resize(column, $event)"/></if></div></else></if></each><if :="canExpand && wasExpanded(row)"><div class="ok-table__expanded_row"><slot name="expanded" :var:row="row" :var:index="rowIndex"/></div></if></each></div>',style:"[tag]{display:block;overflow:auto;max-width:100%}.ok-table__container{display:grid;grid-template-rows:auto;grid-auto-rows:auto;font-family:var(--ok-table-font);width:max-content;min-width:-webkit-fill-available}.ok-table__column--header{position:sticky;top:0;z-index:1}.ok-table__cell{color:var(--ok-table_color);border-bottom:var(--ok-table_border);white-space:nowrap;align-items:center;position:relative;background:var(--ok-table_bg);overflow:hidden;height:100%;box-sizing:border-box}.ok-table__cell__inner{padding:var(--ok-table_padding, 0.1rem 1rem);text-overflow:ellipsis;overflow:hidden}.ok-table__cell--header{font-weight:700;background:var(--ok-table_header-bg, var(--ok_bg-accent, rgba(0, 123, 255, 0.05)));border-bottom:var(--ok-table_border)}.ok-table__cell--hover-row{background:var(--ok-table_hover-bg, rgba(0, 123, 255, 0.1))}.ok-table__cell--selected{background:var(--ok-table_selected-bg, color-mix(in srgb, var(--ok_color-accent-fg, #007bff) 25%, transparent))}.ok-table__cell--expanded,.ok-table__cell--header.ok-table__cell--show-more:hover{background:var(--ok-table_hover-bg, rgba(0, 123, 255, 0.1))}.ok-table__cell--start{border-left:var(--ok-table_border)}.ok-table__cell--end{border-right:var(--ok-table_border)}.ok-table__resizer{position:absolute;right:0;top:0;bottom:0;width:6px;cursor:col-resize;z-index:10}.ok-table__resizer--resizing,.ok-table__resizer:hover{background:var(--ok_bg-accent-hover, rgba(0, 123, 255, 0.3))}.ok-table__expanded_row{grid-column:1/-1;contain:inline-size}.ok-table__cell--header.ok-table__cell--show-more{cursor:pointer;user-select:none;opacity:.7}.ok-table__cell--header.ok-table__cell--show-more:hover{opacity:1}.ok-table__cell--data.ok-table__cell--show-more{pointer-events:none}"};export{i as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e){return new Promise(t=>setTimeout(t,e))}export default{tag:"admin-route-host",attr:{section:{}},context:t=>({loading:!1,error:null,importHref:null,requestToken:0,get sectionName(){return t.$attr.section||"db"},get targetHref(){return`./sections/${this.sectionName}/index.ok.html`},async load(){const t=++this.requestToken;this.loading=!0,this.error=null,this.importHref=null;const i=[0,200,500,1e3];let o=null;for(const r of i){if(r&&await e(r),t!==this.requestToken)return;try{const e=await fetch(this.targetHref,{credentials:"same-origin",cache:"no-store"});if(!e.ok)throw new Error(`HTTP ${e.status} loading ${this.targetHref}`);if(t!==this.requestToken)return;return this.importHref=this.targetHref,void(this.loading=!1)}catch(e){o=e}}t===this.requestToken&&(this.loading=!1,this.error=o?.message||String(o||"Failed to load section"))},retry(){this.load()},reloadPage(){window.location.reload()}}),init(e){e.$watch(()=>e.$attr.section,()=>this.load()),this.load()},template:'\n <if :="importHref">\n <component :import="importHref"></component>\n </if>\n <if :="loading && !importHref">\n <div style="min-height:100vh;display:flex;align-items:center;justify-content:center;padding:32px;color:var(--okdb-app-fg-muted);">\n <div style="display:flex;flex-direction:column;gap:10px;align-items:center;max-width:420px;text-align:center;">\n <div style="font-size:15px;font-weight:600;color:var(--okdb-app-fg-strong);">Loading {{ sectionName }}…</div>\n <div style="font-size:12px;line-height:1.6;opacity:.8;">Retrying section fetch automatically in case the local admin server is still starting.</div>\n </div>\n </div>\n </if>\n <if :="error && !loading && !importHref">\n <div style="min-height:100vh;display:flex;align-items:center;justify-content:center;padding:32px;color:var(--okdb-app-fg-muted);">\n <div style="display:flex;flex-direction:column;gap:12px;max-width:560px;padding:18px;border:1px solid var(--okdb-app-border);border-radius:14px;background:var(--okdb-app-bg);box-shadow:0 0 8px #00000022;">\n <div style="font-size:16px;font-weight:700;color:var(--okdb-app-fg-strong);">Could not load the {{ sectionName }} section</div>\n <div style="font-size:12px;line-height:1.7;">The admin UI hit a temporary fetch failure while loading <code>{{ targetHref }}</code>. This usually resolves once the local server is ready again.</div>\n <div style="padding:10px 12px;border:1px solid color-mix(in srgb, var(--okdb-danger) 33%, transparent);border-radius:10px;background:var(--okdb-danger-soft-bg);color:var(--okdb-danger);font-size:12px;line-height:1.6;word-break:break-word;">{{ error }}</div>\n <div style="display:flex;gap:10px;flex-wrap:wrap;">\n <button @click="retry()" style="font-size:12px;padding:6px 14px;color:var(--okdb-accent);border-color:var(--okdb-accent-soft-border);">Retry section load</button>\n <button @click="reloadPage()" style="font-size:12px;padding:6px 14px;opacity:.8;">Reload admin UI</button>\n </div>\n </div>\n </div>\n </if>\n',style:"[tag]{display:flex;flex-grow:1}"};
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<title>field-path-input — test</title>
|
|
6
|
-
<script type="importmap">
|
|
7
|
-
{
|
|
8
|
-
"imports": {
|
|
9
|
-
"@toolkit/": "../vendor/okjs/toolkit/",
|
|
10
|
-
"@okjs": "../vendor/okjs/ok.esm.min.js"
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
</script>
|
|
14
|
-
<style>
|
|
15
|
-
body { background:#0d1117; color:#c9d1d9; font-family:system-ui,sans-serif; padding:32px; }
|
|
16
|
-
h2 { font-size:13px; text-transform:uppercase; letter-spacing:.08em; opacity:.45; margin:32px 0 10px; }
|
|
17
|
-
.row { display:flex; align-items:flex-start; gap:16px; margin-bottom:24px; }
|
|
18
|
-
.col { flex:1; display:flex; flex-direction:column; gap:8px; }
|
|
19
|
-
.label { font-size:11px; opacity:.5; }
|
|
20
|
-
.out { font-size:12px; font-family:monospace; padding:6px 8px; background:#1e2326; border-radius:6px; min-height:28px; color:#4FC1FF; }
|
|
21
|
-
.chip { display:inline-flex; align-items:center; gap:4px; background:#2a3035; padding:3px 8px; border-radius:4px; font-size:12px; margin:2px; font-family:monospace; }
|
|
22
|
-
.chip button { background:none; border:none; color:#aaa; cursor:pointer; padding:0 2px; font-size:13px; }
|
|
23
|
-
.chips { display:flex; flex-wrap:wrap; min-height:28px; align-items:center; gap:2px; }
|
|
24
|
-
.add-row { display:flex; gap:8px; align-items:center; }
|
|
25
|
-
.add-row button { white-space:nowrap; }
|
|
26
|
-
hr { border:none; border-top:1px solid #2a3035; margin:32px 0; }
|
|
27
|
-
</style>
|
|
28
|
-
</head>
|
|
29
|
-
<body>
|
|
30
|
-
|
|
31
|
-
<!-- ─── Test 1: basic, no :value, all types ─────────────────────────────── -->
|
|
32
|
-
<h2>1 · Basic — no initial value, all field types</h2>
|
|
33
|
-
<div class="row">
|
|
34
|
-
<div class="col">
|
|
35
|
-
<div class="label">field-path-input (strict mode)</div>
|
|
36
|
-
<field-path-input
|
|
37
|
-
:items="fields"
|
|
38
|
-
placeholder="Type to filter…"
|
|
39
|
-
@change="pick1 = $event.detail"
|
|
40
|
-
></field-path-input>
|
|
41
|
-
<div class="label">Selected value</div>
|
|
42
|
-
<div class="out">{{ pick1 || '—' }}</div>
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
|
|
46
|
-
<!-- ─── Test 2: controlled :value + allow-custom ────────────────────────── -->
|
|
47
|
-
<h2>2 · Controlled + allow-custom</h2>
|
|
48
|
-
<div class="row">
|
|
49
|
-
<div class="col">
|
|
50
|
-
<div class="label">field-path-input (allow-custom="true")</div>
|
|
51
|
-
<field-path-input
|
|
52
|
-
:value="pick2"
|
|
53
|
-
:items="fields"
|
|
54
|
-
allow-custom="true"
|
|
55
|
-
placeholder="Known or free-text path"
|
|
56
|
-
@change="pick2 = $event.detail"
|
|
57
|
-
></field-path-input>
|
|
58
|
-
<div class="label">Value (round-trips via :value)</div>
|
|
59
|
-
<div class="out">{{ pick2 || '—' }}</div>
|
|
60
|
-
<button @click="pick2 = ''">Clear</button>
|
|
61
|
-
</div>
|
|
62
|
-
</div>
|
|
63
|
-
|
|
64
|
-
<!-- ─── Test 3: multi-select (the chips pattern used in the real modals) ── -->
|
|
65
|
-
<h2>3 · Multi-select chips (Index / FTS modal pattern)</h2>
|
|
66
|
-
<div class="col">
|
|
67
|
-
<div class="add-row">
|
|
68
|
-
<field-path-input
|
|
69
|
-
:value="pick3"
|
|
70
|
-
:items="fields"
|
|
71
|
-
placeholder="Add a field…"
|
|
72
|
-
@change="pick3 = $event.detail"
|
|
73
|
-
style="flex:1"
|
|
74
|
-
></field-path-input>
|
|
75
|
-
<button @click="addChip()" :disabled="!pick3 || chips.includes(pick3)">+ Add</button>
|
|
76
|
-
</div>
|
|
77
|
-
<div class="chips">
|
|
78
|
-
<each :of="chips" let:item="c">
|
|
79
|
-
<span class="chip">{{ c }} <button @click="removeChip(c)">×</button></span>
|
|
80
|
-
</each>
|
|
81
|
-
<span style="font-size:12px; opacity:.3;" :style="chips.length ? 'display:none' : ''">no fields added</span>
|
|
82
|
-
</div>
|
|
83
|
-
<div class="label">Chips array</div>
|
|
84
|
-
<div class="out">{{ JSON.stringify(chips) }}</div>
|
|
85
|
-
</div>
|
|
86
|
-
|
|
87
|
-
<hr>
|
|
88
|
-
|
|
89
|
-
<!-- ─── Scoring proof ─────────────────────────────────────────────────────── -->
|
|
90
|
-
<h2>4 · Scoring proof — type "body" → content.body ranks highest</h2>
|
|
91
|
-
<div class="row">
|
|
92
|
-
<div class="col">
|
|
93
|
-
<div class="label">Try typing: body, cre, lat, co bo</div>
|
|
94
|
-
<field-path-input
|
|
95
|
-
:items="deepFields"
|
|
96
|
-
placeholder="Test scoring…"
|
|
97
|
-
@change="pick4 = $event.detail"
|
|
98
|
-
></field-path-input>
|
|
99
|
-
<div class="out">{{ pick4 || '—' }}</div>
|
|
100
|
-
</div>
|
|
101
|
-
</div>
|
|
102
|
-
|
|
103
|
-
<script type="module">
|
|
104
|
-
import fieldPathInput from './field-path-input.ok.js';
|
|
105
|
-
import { ok } from '../modules/ok.js';
|
|
106
|
-
ok.register(fieldPathInput);
|
|
107
|
-
|
|
108
|
-
ok.init(document.body, {
|
|
109
|
-
// ── shared items ──────────────────────────────────────────────────────
|
|
110
|
-
fields: [
|
|
111
|
-
{ path: 'name', types: ['string'] },
|
|
112
|
-
{ path: 'email', types: ['string'] },
|
|
113
|
-
{ path: 'city', types: ['string'] },
|
|
114
|
-
{ path: 'country', types: ['string'] },
|
|
115
|
-
{ path: 'home', types: ['geo'], hint: 'geo' },
|
|
116
|
-
{ path: 'bio', types: ['string'] },
|
|
117
|
-
{ path: 'interests', types: ['array'] },
|
|
118
|
-
{ path: 'memberSince', types: ['string'] },
|
|
119
|
-
{ path: 'checkinsCount', types: ['number'] },
|
|
120
|
-
{ path: 'active', types: ['boolean'] },
|
|
121
|
-
{ path: 'meta', types: ['object'] },
|
|
122
|
-
],
|
|
123
|
-
|
|
124
|
-
// deeper paths for scoring test
|
|
125
|
-
deepFields: [
|
|
126
|
-
{ path: 'content', types: ['object'] },
|
|
127
|
-
{ path: 'content.title', types: ['string'] },
|
|
128
|
-
{ path: 'content.body', types: ['string'] },
|
|
129
|
-
{ path: 'content.summary', types: ['string'] },
|
|
130
|
-
{ path: 'meta', types: ['object'] },
|
|
131
|
-
{ path: 'meta.created', types: ['number'] },
|
|
132
|
-
{ path: 'meta.author', types: ['string'] },
|
|
133
|
-
{ path: 'location', types: ['geo'], hint: 'geo' },
|
|
134
|
-
],
|
|
135
|
-
|
|
136
|
-
// ── state ─────────────────────────────────────────────────────────────
|
|
137
|
-
pick1: '',
|
|
138
|
-
pick2: '',
|
|
139
|
-
pick3: '',
|
|
140
|
-
pick4: '',
|
|
141
|
-
chips: [],
|
|
142
|
-
|
|
143
|
-
addChip() {
|
|
144
|
-
const v = this.pick3.trim();
|
|
145
|
-
if (v && !this.chips.includes(v)) {
|
|
146
|
-
this.chips.push(v);
|
|
147
|
-
this.pick3 = '';
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
removeChip(c) {
|
|
151
|
-
const i = this.chips.indexOf(c);
|
|
152
|
-
if (i >= 0) this.chips.splice(i, 1);
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
</script>
|
|
156
|
-
</body>
|
|
157
|
-
</html>
|
|
158
|
-
|