UNPKG

@wordpress/interactivity

Version:

Package that provides a standard and simple way to handle the frontend interactivity of Gutenberg blocks.

8 lines (7 loc) 3.86 kB
{ "version": 3, "sources": ["../src/index.ts"], "sourcesContent": ["if ( globalThis.SCRIPT_DEBUG ) {\n\tawait import( 'preact/debug' );\n}\n\n/**\n * External dependencies\n */\nimport { h, cloneElement, render } from 'preact';\nimport { batch, effect } from '@preact/signals';\n\n/**\n * Internal dependencies\n */\nimport registerDirectives, { routerRegions } from './directives';\nimport {\n\tinitialVdom,\n\thydrateRegions,\n\tgetRegionRootFragment,\n} from './hydration';\nimport { toVdom } from './vdom';\nimport { directive } from './hooks';\nimport { getNamespace } from './namespaces';\nimport { parseServerData, populateServerData } from './store';\nimport { proxifyState } from './proxies';\nimport { deepReadOnly, navigationSignal, onDOMReady, warn } from './utils';\n\nexport {\n\tstore,\n\tgetConfig,\n\tgetServerState,\n\ttype AsyncAction,\n\ttype TypeYield,\n} from './store';\nexport { getContext, getServerContext, getElement } from './scopes';\nexport {\n\twithScope,\n\tuseWatch,\n\tuseInit,\n\tuseEffect,\n\tuseLayoutEffect,\n\tuseCallback,\n\tuseMemo,\n\tsplitTask,\n\twithSyncEvent,\n} from './utils';\n\nexport { useState, useRef } from 'preact/hooks';\n\n/**\n * Subscribes to changes in any signal accessed inside the callback, re-running\n * the callback whenever those signals change. Returns a cleanup function to\n * stop watching.\n *\n * @example\n * ```js\n * const unwatch = watch( () => {\n * console.log( state.counter );\n * } );\n *\n * // Later, to stop watching:\n * unwatch();\n * ```\n */\nexport const watch = effect;\n\nconst requiredConsent =\n\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.';\n\nexport const privateApis = (\n\tlock: 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n): any => {\n\tif ( lock === requiredConsent ) {\n\t\treturn {\n\t\t\tgetRegionRootFragment,\n\t\t\tinitialVdom,\n\t\t\ttoVdom,\n\t\t\tdirective,\n\t\t\tgetNamespace,\n\t\t\th,\n\t\t\tcloneElement,\n\t\t\trender,\n\t\t\tproxifyState,\n\t\t\tparseServerData,\n\t\t\tpopulateServerData,\n\t\t\tbatch,\n\t\t\trouterRegions,\n\t\t\tdeepReadOnly,\n\t\t\tnavigationSignal,\n\t\t\twarn,\n\t\t};\n\t}\n\n\tthrow new Error( 'Forbidden access.' );\n};\n\n// Parses and populates the initial state and config. All the core directives\n// are registered at this point as well.\npopulateServerData( parseServerData() );\nregisterDirectives();\n\n// Hydrates all interactive regions when `DOMContentLoaded` is dispatched, or as\n// soon as the `@wordpress/interactivity` module is evaluated in the case that\n// the event was already dispatched. This ensures synchronous modules had the\n// opportunity to register their stores before hydration takes place. For\n// asynchronous modules, or modules importing this module asynchronously, this\n// cannot be guaranteed.\nonDOMReady( hydrateRegions );\n"], "mappings": ";AAOA,SAAS,GAAG,cAAc,cAAc;AACxC,SAAS,OAAO,cAAc;AAK9B,OAAO,sBAAsB,qBAAqB;AAClD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB,0BAA0B;AACpD,SAAS,oBAAoB;AAC7B,SAAS,cAAc,kBAAkB,YAAY,YAAY;AAEjE;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AACP,SAAS,YAAY,kBAAkB,kBAAkB;AACzD;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,SAAS,UAAU,cAAc;AA9CjC,IAAK,WAAW,cAAe;AAC9B,QAAM,OAAQ,cAAe;AAC9B;AA6DO,IAAM,QAAQ;AAErB,IAAM,kBACL;AAEM,IAAM,cAAc,CAC1B,SACS;AACT,MAAK,SAAS,iBAAkB;AAC/B,WAAO;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,QAAM,IAAI,MAAO,mBAAoB;AACtC;AAIA,mBAAoB,gBAAgB,CAAE;AACtC,mBAAmB;AAQnB,WAAY,cAAe;", "names": [] }